jrsonnet icon indicating copy to clipboard operation
jrsonnet copied to clipboard

Build statically linked binary

Open morgangalpin opened this issue 3 years ago • 3 comments

When I run the following command, as suggested in README.md:

cargo build --release

it results in a dynamically linked binary, which runs great locally, but I'm unable to run it on other machines, for example, in a docker image.

The releases page includes statically linked binaries. What is the command or config used to create these? If possible, could these commands be included in the README.md file for future reference?

Thanks for your help!

morgangalpin avatar Mar 01 '22 00:03 morgangalpin

Static linked instructions is not included in README.md, as this is platform-dependent thing in Rust

For x86 linux - this is just cargo build --release --target=x86_64-unknown-linux-musl, for windows this is RUSTFLAGS=-Ctarget-feature=+crt-static, etc. There is no universal command, and i think for most users this is enough to use precompiled binaries or build for native platform toolchain (and most platforms don't use static linking by default)

CertainLach avatar Apr 09 '22 16:04 CertainLach

Thanks for getting back to me.

I tried this on Linux, on the v0.4.2 branch:

cargo build --release --target=x86_64-unknown-linux-musl

with this result:

error: cannot produce cdylib for `jsonnet v0.4.2 (/home/.../jrsonnet/bindings/jsonnet)` as the target `x86_64-unknown-linux-musl` does not support these crate types

I have these versions of rust and cargo:

rustc 1.58.1 (db9d1b20b 2022-01-20)
cargo 1.58.0 (f01b232bc 2022-01-19)

Is there something else that I need to have installed for this to work?

morgangalpin avatar May 05 '22 21:05 morgangalpin

Running cargo build inside of workspace will build all projects in workspace, and there is bindings/jsonnet subproject, which is implementation of libjsonnet.so Dynamic libraries (.so) can't be build statically with musl

You only need to build jrsonnet executable - go to cmds/jrsonnet subdirectory, and execute build here

(Also, i recommend you to use gcmodule branch, as there is several performance regressions in v0.4.2, and there is more supported features on gcmodule branch)

CertainLach avatar May 05 '22 21:05 CertainLach