Open vincent-herlemont opened 3 years ago
Not 100% sure. Generally there should be no problem using Jsonnet with musl (we try not to depend on any glibc-specific stuff).
Try running ldd ./jsonnet
to see if the result is a static binary.
jsonnet
seems no build as a static binary.
In the docker container, I ran ldd /usr/local/bin/jsonnet
. See the output below.
/lib/ld-musl-x86_64.so.1 (0x7f13ff919000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f13ff6a0000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f13ff686000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f13ff919000)
How I can build jsonnet as a static binary?
I think you should set the CXX
environment variable in addition to CC
. (Not sure if that is enough.)
Yes, the behaviour is different.
Try with x86_64-alpine-linux-musl-g++
present alpine /usr/bin/
.
The compilation fail with this error relocation R_X86_64_32 against hidden symbol
:
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/crtbeginT.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a shared object
/usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/gcc/x86_64-alpine-linux-musl/10.2.1/crtend.o: relocation R_X86_64_32 against `.ctors' can not be used when making a shared object; recompile with -fPIC
collect2: error: ld returned 1 exit status
make: *** [Makefile:173: libjsonnet.so.0.17.0] Error 1
I tried to set -fPIC
.
export CXX="x86_64-alpine-linux-musl-g++ -static" \
export CC="x86_64-alpine-linux-musl-g++ -static" \
export CXXFLAGS="$CXXFLAGS -fPIC" && \
make
But the same error as this https://github.com/google/jsonnet/issues/908#issuecomment-832564094 happens.
One more thing to try: LDFLAGS=-static
.
BTW if you want a static executable anyway, why not try https://github.com/google/go-jsonnet. It's static by default, faster and the version we're focusing our development efforts on.
Test with LDFLAGS=-static
. The same error is thrown.
BTW if you want a static executable anyway, why not try https://github.com/google/go-jsonnet. It's static by default, faster and the version we're focusing our development efforts on.
I use jsonnet (c++) because I use rust-jsonnet and I want make my rust binary as static binary with musl
. So I am stuck with this issue https://github.com/anguslees/rust-jsonnet/issues/40. The following error happens when I try to build my rust binary with a musl target cargo build --target=x86_64-unknown-linux-musl
.
Compiling rust-jsonnet v0.1.0 (/home/rust/src)
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-Wl,--eh-frame-hdr" "-nostartfiles" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crt1.o" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crti.o" "-L" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-L" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.161wm2g1wzcwjgvj.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.17g76nh6zyv5tade.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.1987eq46n067ujzn.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.1abbep6d3mn1dgy9.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.1un33j1csb5877gg.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.1vljilws0ah901yu.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.1vm9g2b4blurtxqm.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.1xm8vfqv31jxksj8.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.27j7l36m4w6rmgp8.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.2c8nvn35g9sapb18.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.2jhs5rkzvd1jo36n.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.2kad6j71rqxbf0u9.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.2ozhh54lqq9e5gtq.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.2w3a53db7zkes2or.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.2wruq8kkmv5d5zmb.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.2xcmtkf3k4mzjj0u.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3alxf2o5rlsz7i6k.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3brkz0i0ta8x5zfj.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3d52dgmcmvpvc7d2.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3diz8n6fr3dd9apv.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3ilbig2mz3wn2rqy.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3ju3wbgel4wxv79s.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3l9dam6qy77ek27s.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3lconvqngedo2wzp.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3w4uhou73epgr6o7.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.3z9hhie2bj9la88f.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.41ycxlqudm3xpcvm.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.4c3y1mhq3n7ey0gv.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.4mglmqcgb9qcea5q.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.4nzqziykll36gv0.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.4q5siug0ctdigsoh.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.4tdvux387vbk3e0k.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.4v9jfn7jgidqkqra.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.50fpmyf1y03f02d2.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.570vp5wlegduooxi.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.59zsicpr9ird2d05.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.5c582dex2atv09sd.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.6zerhfd5dlig97r.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.aboc0uze851xo83.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.bnfu4a6o4fo3s13.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.cqs69h4nu2u3jun.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.iiscs9k9nd7v13b.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.pzypk02yxxhwn6t.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.q0ee0vehfpybip4.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.qhf48m00vwgtumh.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.vz9p7qxi5x1o14n.rcgu.o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.y43jij24lm9p779.rcgu.o" "-o" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91.geb96741bqnvbkg.rcgu.o" "-Wl,--gc-sections" "-static" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps" "-L" "/home/rust/src/target/debug/deps" "-L" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/build/jsonnet-sys-ec1ecc5ea86284b5/out" "-L" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libjsonnet-d4e2953816f2eb9d.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libjsonnet_sys-f23132dca1dd9b88.rlib" "/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/liblibc-77bb581c43605ad5.rlib" "-Wl,--start-group" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-d2918ad39560ef70.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-f4ca16729b67f4dd.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-400395ea2841002a.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-b0533ea0af675dc9.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-e9d03d8a1cf7a110.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-fe8cb29709d122d4.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-09ef970e0d183722.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-1a8801c99e79f10f.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-886c89b28e5e0865.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-dcf93364faa2ceaa.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-75081e895819d734.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-6c4598f129413e8a.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-d3a472b733fbfd21.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-2f23acd805819d02.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-d2b457edb67a2174.rlib" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-fc65d219541fe932.rlib" "-Wl,--end-group" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-f4df6b79d8e73f02.rlib" "-Wl,-Bdynamic" "-lstdc++" "/opt/rust/rustup/toolchains/1.50.0-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
= note: /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libjsonnet_sys-f23132dca1dd9b88.rlib(libjsonnet.o): In function `__static_initialization_and_destruction_0(int, int)':
/usr/include/c++/7/iostream:74: undefined reference to `__dso_handle'
/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libjsonnet_sys-f23132dca1dd9b88.rlib(libjsonnet.o): In function `__static_initialization_and_destruction_0(int, int)':
/home/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonnet-sys-0.17.0/jsonnet/core/ast.h:1078: undefined reference to `__dso_handle'
/home/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonnet-sys-0.17.0/jsonnet/core/ast.h:1079: undefined reference to `__dso_handle'
/home/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonnet-sys-0.17.0/jsonnet/core/ast.h:1080: undefined reference to `__dso_handle'
/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libjsonnet_sys-f23132dca1dd9b88.rlib(parser.o): In function `__static_initialization_and_destruction_0(int, int)':
/usr/include/c++/7/iostream:74: undefined reference to `__dso_handle'
/home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/libjsonnet_sys-f23132dca1dd9b88.rlib(parser.o):/home/rust/.cargo/registry/src/github.com-1ecc6299db9ec823/jsonnet-sys-0.17.0/jsonnet/core/ast.h:1078: more undefined references to `__dso_handle' follow
/usr/bin/ld: /home/rust/src/target/x86_64-unknown-linux-musl/debug/deps/rust_jsonnet-0414d9e071c87c91: hidden symbol `__dso_handle' isn't defined
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
It seems some symbole are missing hidden symbol '__dso_handle' isn't defined /usr/bin/ld: final link failed: Bad value
. So I try to build jsonnet (c++) with musl
to make sure that is possible before to dig in the rust binding.
So thank you for the information to https://github.com/google/go-jsonnet but I don't know if the binding go
to rust
will be easy :s.
Hmmmm...
x86_64-alpine-linux-musl-g++ -static -static core/desugarer.o core/formatter.o core/lexer.o core/libjsonnet.o core/parser.o core/pass.o core/static_analysis.o core/string_utils.o core/vm.o third_party/md5/md5.o -shared -Wl,-soname,libjsonnet.so.0 -o libjsonnet.so.0.17.0
This is about building the shared library. You probably don't need that if you want to have static binary in the end anyway.
Also, if you're using rust, perhaps https://github.com/CertainLach/jrsonnet will be interesting to you (that's a third-party unofficial implementation, though).
Re go-rust bindings: we offer a compatible C interface. It's a drop-in replacement when using a shared library. Not sure how to create a single shared binary with Go and Rust. Also it means your binary will include the Go runtime with GC, threads etc.
Is there a way to build jsonnet with
musl
?I am a novice in C++ development and I try to build
jsonnet
withmusl
in order to create a static binary (here the root issue https://github.com/anguslees/rust-jsonnet/issues/40).I updated the Dockerfile:L10 with adding
CC="musl-gcc -static"
The build pass :heavy_check_mark: .
Is it enough to guarantee that
jsonnet
build withmusl
?