I’m trying to test ex_typst with a new application but I’m receiving an error when compilling the application. I already have Rust installed (rustc 1.73.0 (cc66ad468 2023-10-03)). I have MacBook Pro M1 Pro, last Sonoma system version (13.6 (22G120)).
I tested with Erlang 26, 25 and 24.
Compiling extypst_nif v0.1.0 (/Users/lucas.pedreiro/Dev/learn/elixir/docx/deps/ex_typst/native/extypst_nif)
error: linking with `cc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="/Users/lucas.pedreiro/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin ...
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile `extypst_nif` (lib) due to previous error
== Compilation error in file lib/ex_typst_nif.ex ==
** (RuntimeError) Rust NIF compile error (rustc exit code 101)
(rustler 0.28.0) lib/rustler/compiler.ex:41: Rustler.Compiler.compile_crate/2
lib/ex_typst_nif.ex:4: (module)
I would be super grateful if somebody would bump the Typst version used by this lib. It’s using 0.4.0 and the current one is 0.13.1. I tried it myself locally, but of course there is some Rust involved and that’s where I ended. Even Claude 3.7 didn’t help.
I successfully integrated typst into an elixir app a while ago by just putting the correct binary in the priv directory in releases and running it through System.cmd. Of course installing it into the PATH is also possible. Getting data into typst is also quite easy by passing JSON through stdin, which also has the benefit of not being prone to code injection. So that’s what I’d recommend doing, especially since the library doesn’t look maintained at the moment.
That’s pretty much what we do (command line typst), with a couple of differences:
We embed images in our output (based on user input rather than static images) so have to create a temp folder with the images and run typst within that folder (typst constrains where you can access images from). We resize and pre-compress the images before they get there to avoid having to run the generated PDF through a compressor post-generation.
As a result of #1, we just write the JSON with the data into the same temp folder rather than using stdin.
We have a typst build step in our deployment docker pipeline so we don’t have to worry about target platform too much - this is cached so the overhead isn’t too bad.
You’re using the wrong package. This one created four months ago supports Typst 0.12. It has not yet been updated to Typst 0.13, but that might be easy to achieve in a fork.
JSON handling is one of the big improvements in Typst 0.13. In Typst 0.12, it is recommended to use the command line version if you want to create unique documents from JSON payloads. Typst 0.13 can decode JSON sent as a parameter to a function.