google / jsonnet

Jsonnet - The data templating language
http://jsonnet.org
Apache License 2.0
6.97k stars 440 forks source link

Build jsonnet with musl static binary #908

Open vincent-herlemont opened 3 years ago

vincent-herlemont commented 3 years ago

Is there a way to build jsonnet with musl?

I am a novice in C++ development and I try to build jsonnet with musl 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"

...
RUN cd jsonnet && \
    CC="musl-gcc -static" && make
...

The build pass :heavy_check_mark: .

Is it enough to guarantee that jsonnet build with musl?

sbarzowski commented 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.

vincent-herlemont commented 3 years ago

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)
Here the Dockerfile than I use ```Dockerfile FROM alpine:latest AS builder RUN apk -U add build-base WORKDIR /opt COPY . /opt/jsonnet RUN cd jsonnet && \ CC="musl-gcc -static" && make FROM alpine:latest RUN apk add --no-cache libstdc++ COPY --from=builder /opt/jsonnet/jsonnet /usr/local/bin COPY --from=builder /opt/jsonnet/jsonnetfmt /usr/local/bin CMD ["/bin/sh"] ```

How I can build jsonnet as a static binary?

sbarzowski commented 3 years ago

I think you should set the CXX environment variable in addition to CC. (Not sure if that is enough.)

vincent-herlemont commented 3 years ago

Yes, the behaviour is different.

Try with x86_64-alpine-linux-musl-g++ present alpine /usr/bin/.

Here others available musl packages ``` x86_64-alpine-linux-musl-c++ x86_64-alpine-linux-musl-g++ x86_64-alpine-linux-musl-gcc x86_64-alpine-linux-musl-gcc-10.2.1 x86_64-alpine-linux-musl-gcc-ar x86_64-alpine-linux-musl-gcc-nm x86_64-alpine-linux-musl-gcc-ranlib ```

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
The full-stack strace ```bash Sending build context to Docker daemon 111.3MB Step 1/11 : FROM alpine:latest AS builder ---> 6dbb9cc54074 Step 2/11 : RUN apk -U add build-base ---> Using cache ---> 5fb78d8ee979 Step 3/11 : WORKDIR /opt ---> Using cache ---> bcd5fcab4ab0 Step 4/11 : CMD ["/bin/sh"] ---> Using cache ---> bdb58cee5de2 Step 5/11 : COPY . /opt/jsonnet ---> 69db2ebae23c Step 6/11 : RUN cd jsonnet && export CXX="x86_64-alpine-linux-musl-g++ -static" export CC="x86_64-alpine-linux-musl-g++ -static" && make ---> Running in 45db5682a1c5 ((od -v -Anone -t u1 stdlib/std.jsonnet \ | tr " " "\n" \ | grep -v "^$" \ | tr "\n" "," ) && echo "0") > core/std.jsonnet.h echo >> core/std.jsonnet.h x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/desugarer.cpp -o core/desugarer.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/formatter.cpp -o core/formatter.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/lexer.cpp -o core/lexer.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/libjsonnet.cpp -o core/libjsonnet.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/parser.cpp -o core/parser.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/pass.cpp -o core/pass.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/static_analysis.cpp -o core/static_analysis.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/string_utils.cpp -o core/string_utils.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/vm.cpp -o core/vm.o x86_64-alpine-linux-musl-g++ -static -c -g -O3 -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++0x -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json third_party/md5/md5.cpp -o third_party/md5/md5.o x86_64-alpine-linux-musl-g++ -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 /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 The command '/bin/sh -c cd jsonnet && export CXX="x86_64-alpine-linux-musl-g++ -static" export CC="x86_64-alpine-linux-musl-g++ -static" && make' returned a non-zero code: 2 ```
The Dockerfile for reproduce the error The docker command: ```bash docker build -t test . && docker run -it --rm test ``` The Dockerfile: ```Dockerfile FROM alpine:latest AS builder RUN apk -U add build-base WORKDIR /opt CMD ["/bin/sh"] COPY . /opt/jsonnet RUN cd jsonnet && \ export CXX="x86_64-alpine-linux-musl-g++ -static" \ export CC="x86_64-alpine-linux-musl-g++ -static" && \ make FROM alpine:latest RUN apk add --no-cache libstdc++ COPY --from=builder /opt/jsonnet/jsonnet /usr/local/bin COPY --from=builder /opt/jsonnet/jsonnetfmt /usr/local/bin CMD ["/bin/sh"] ```
vincent-herlemont commented 3 years ago

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.

The full-stack strace ```bash Sending build context to Docker daemon 111.3MB Step 1/11 : FROM alpine:latest AS builder ---> 6dbb9cc54074 Step 2/11 : RUN apk -U add build-base ---> Using cache ---> 5fb78d8ee979 Step 3/11 : WORKDIR /opt ---> Using cache ---> bcd5fcab4ab0 Step 4/11 : CMD ["/bin/sh"] ---> Using cache ---> bdb58cee5de2 Step 5/11 : COPY . /opt/jsonnet ---> ab190a0e177b Step 6/11 : RUN cd jsonnet && export CXX="x86_64-alpine-linux-musl-g++ -static" export CC="x86_64-alpine-linux-musl-g++ -static" export CXXFLAGS="$CXXFLAGS -fPIC" && make ---> Running in 6c74791cca5f ((od -v -Anone -t u1 stdlib/std.jsonnet \ | tr " " "\n" \ | grep -v "^$" \ | tr "\n" "," ) && echo "0") > core/std.jsonnet.h echo >> core/std.jsonnet.h x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/desugarer.cpp -o core/desugarer.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/formatter.cpp -o core/formatter.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/lexer.cpp -o core/lexer.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/libjsonnet.cpp -o core/libjsonnet.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/parser.cpp -o core/parser.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/pass.cpp -o core/pass.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/static_analysis.cpp -o core/static_analysis.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/string_utils.cpp -o core/string_utils.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/vm.cpp -o core/vm.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json third_party/md5/md5.cpp -o third_party/md5/md5.o x86_64-alpine-linux-musl-g++ -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 /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 The command '/bin/sh -c cd jsonnet && export CXX="x86_64-alpine-linux-musl-g++ -static" export CC="x86_64-alpine-linux-musl-g++ -static" export CXXFLAGS="$CXXFLAGS -fPIC" && make' returned a non-zero code: 2 ```
The Dockerfile for reproduce the error The docker command: ```bash docker build -t test . && docker run -it --rm test ``` The Dockerfile: ```Dockerfile FROM alpine:latest AS builder RUN apk -U add build-base WORKDIR /opt CMD ["/bin/sh"] COPY . /opt/jsonnet RUN cd jsonnet && \ export CXX="x86_64-alpine-linux-musl-g++ -static" \ export CC="x86_64-alpine-linux-musl-g++ -static" \ export CXXFLAGS="$CXXFLAGS -fPIC" && \ make FROM alpine:latest RUN apk add --no-cache libstdc++ COPY --from=builder /opt/jsonnet/jsonnet /usr/local/bin COPY --from=builder /opt/jsonnet/jsonnetfmt /usr/local/bin CMD ["/bin/sh"] ```
sbarzowski commented 3 years ago

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.

vincent-herlemont commented 3 years ago

Test with LDFLAGS=-static. The same error is thrown.

The full-stack strace ```bash Sending build context to Docker daemon 111.3MB Step 1/11 : FROM alpine:latest AS builder ---> 6dbb9cc54074 Step 2/11 : RUN apk -U add build-base ---> Using cache ---> 5fb78d8ee979 Step 3/11 : WORKDIR /opt ---> Using cache ---> bcd5fcab4ab0 Step 4/11 : CMD ["/bin/sh"] ---> Using cache ---> bdb58cee5de2 Step 5/11 : COPY . /opt/jsonnet ---> ea04a99854d6 Step 6/11 : RUN cd jsonnet && export CXX="x86_64-alpine-linux-musl-g++ -static" export CC="x86_64-alpine-linux-musl-g++ -static" export CXXFLAGS="$CXXFLAGS -fPIC" && export LDFLAGS=-static && make ---> Running in 9eb13c67bf29 ((od -v -Anone -t u1 stdlib/std.jsonnet \ | tr " " "\n" \ | grep -v "^$" \ | tr "\n" "," ) && echo "0") > core/std.jsonnet.h echo >> core/std.jsonnet.h x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/desugarer.cpp -o core/desugarer.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/formatter.cpp -o core/formatter.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/lexer.cpp -o core/lexer.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/libjsonnet.cpp -o core/libjsonnet.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/parser.cpp -o core/parser.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/pass.cpp -o core/pass.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/static_analysis.cpp -o core/static_analysis.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/string_utils.cpp -o core/string_utils.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json core/vm.cpp -o core/vm.o x86_64-alpine-linux-musl-g++ -static -c -fPIC -Iinclude -Ithird_party/md5 -Ithird_party/json third_party/md5/md5.cpp -o third_party/md5/md5.o 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 /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 The command '/bin/sh -c cd jsonnet && export CXX="x86_64-alpine-linux-musl-g++ -static" export CC="x86_64-alpine-linux-musl-g++ -static" export CXXFLAGS="$CXXFLAGS -fPIC" && export LDFLAGS=-static && make' returned a non-zero code: 2 ```
The Dockerfile for reproduce the error The docker command: ```bash docker build -t test . && docker run -it --rm test ``` The Dockerfile: ```Dockerfile FROM alpine:latest AS builder RUN apk -U add build-base WORKDIR /opt CMD ["/bin/sh"] COPY . /opt/jsonnet RUN cd jsonnet && \ export CXX="x86_64-alpine-linux-musl-g++ -static" \ export CC="x86_64-alpine-linux-musl-g++ -static" \ export CXXFLAGS="$CXXFLAGS -fPIC" && \ export LDFLAGS=-static && \ make FROM alpine:latest RUN apk add --no-cache libstdc++ COPY --from=builder /opt/jsonnet/jsonnet /usr/local/bin COPY --from=builder /opt/jsonnet/jsonnetfmt /usr/local/bin CMD ["/bin/sh"] ```

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.

sbarzowski commented 3 years ago

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.