Orange-OpenSource / hurl

Hurl, run and test HTTP requests with plain text.
https://hurl.dev
Apache License 2.0
13.14k stars 491 forks source link

Trying to build for x86_64-unknown-linux-musl #3400

Open pepa65 opened 1 week ago

pepa65 commented 1 week ago

I added openssl-sys = { version = "0.9.104", features = ["vendored"] } in packages/hurl/Cargo.toml as a dependency. And I did export LIBXML2=/usr/lib/x86_64-linux-gnu/libxml2.so (this is on Linux Mint 22). But I get stuck at:

   Compiling hurl v6.0.0-SNAPSHOT (/data/git/hurl/packages/hurl)
error: linking with `cc` failed: exit status: 1
  |                                                                                                                            
  = note: LC_ALL="C" PATH="/home/pp/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/pp/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/pp/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/pp/bin:/home/pp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/home/pp/go/bin:/usr/local/go/bin:/home/pp/.cargo/bin:/home/pp/.cabal/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcHx7tcL/symbols.o" "/data/git/hurl/target/86_64-unknown-linux-musl/release/deps/hurl-bb607de7ad2daf85.hurl.4fbb805e2c22e3cc-cgu.0.rcgu.o" "-Wl,--as-needed" "-Wl,-Bstatic" "/tmp/rustcHx7tcL/libhurl-5f15dc918a4a4ebf.rlib" "/tmp/rustcHx7tcL/libcurl_sys-b58220081a0d211d.rlib" "/tmp/rustcHx7tcL/libopenssl_sys-e6c08e3509ed612e.rlib" "/tmp/rustcHx7tcL/liblibz_sys-6ac898a6ab2fc417.rlib" "/home/pp/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/ru
stlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-dbe01828b841a238.rlib" "-Wl,-Bdynamic" "-lxml2" "-lgcc_s" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/data/git/hurl/target/x86_64-unknown-linux-musl/release/build/hurl-71c8407c36c4afe7/out" "-L" "/data/git/hurl/target/x86_64-unknown-linux-musl/release/build/curl-sys-912f1fd6ee92d867/out/build" "-L" "/data/git/hurl/target/x86_64-unknown-linux-musl/release/build/libz-sys-9499a14ece8a9a84/out/lib" "-L" "/data/git/hurl/target/x86_64-unknown-linux-musl/release/build/libz-sys-9499a14ece8a9a84/out/lib" "-L" "/data/git/hurl/target/x86_64-unknown-linux-musl/release/build/openssl-sys-836a3adec2003491/out/openssl-build/install/lib" "-L" "/usr/lib/x86_64-linux-gnu" "-L" "/home/pp/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-o" "/data/git/hurl/target/x86_64-unknown-linux-musl/release/deps/hurl-bb607de7ad2daf85" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-all" "-nodefaultlibs"
  = note: /usr/bin/ld: /data/git/hurl/target/x86_64-unknown-linux-musl/release/deps/hurl-bb607de7ad2daf85.hurl.4fbb805e2c22e3cc
-cgu.0.rcgu.o: undefined reference to symbol 'round@@GLIBC_2.2.5'
          /usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specifie
d
  = note: use the `-l` flag to specify native libraries to link 
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lan
g.org/cargo/reference/build-scripts.html#rustc-link-lib)

error: could not compile `hurl` (bin "hurl") due to 1 previous error
jcamiel commented 1 week ago

Hi @pepa65

I don't know Linux Mint distribution but I've the impression that the packet manager is apt. Have you trying installing Debian based prerquisites ?

From https://hurl.dev/docs/installation.html#debian-based-distributions

$ apt install -y build-essential pkg-config libssl-dev libcurl4-openssl-dev libxml2-dev

With pkg-config, you should not need tp export LIBXML2, pkg-config should be sufficient to configure the build.

Also, could you explain why you're modifying the Cargo.toml ? (openssl-sys = { version = "0.9.104", features = ["vendored"] }). It's a bit unclear for me...

Thanks

pepa65 commented 1 week ago

Yes, I have installed all the packages you mention (otherwise I wouldn't have gotten this far...). If I don't have LIBXML2 set, the build ends at error: failed to run custom build command for 'libxml v0.3.3'.

If I don't add openssl-sys as a dependency, it won't build (since the GNU version links dynamically to openssl). I have some experience building with musl, but I am very new to Rust.

If you're really interested to see if hurl could be a standalone static binary, you could do rustup target add x86_64-unknown-linux-musl and then try building with cargo build --target x86_64-unknown-linux-musl yourself.

jcamiel commented 1 week ago

I'm sorry I've zero experience with musl so consider me as a complete rookie here. Is your goal to build a static binary of Hurl, using musl? What about libcurl and libxml which are dynamically linked in the libc version? Do you need also they to be statically linked to the final library?

I try to distinguish the problem and I would like to know if Linux Mint is part of it. From what I understand, we can try to build for x86_64-unknown-linux-musl on a Debian distrib and see if we can build. Also would you be able to tell me if Hurl compiles on Linux Mint with the default libc target?

Thanks a lot!

pepa65 commented 1 week ago

I like to have static binaries that I can easily distribute to my different (Linux) systems with different versions of glibc etc. I guess the challenge would be that you link to libraries outside of Rust, so maybe it's just too hard at this point.

Nothing to do with Linux Mint, it's just what I was using right now. You can do the same on Debian or Fedora, with the same results (depending how you set up the tool chain, like install musl-dev or musl-tools, whatever is required).

Yes, hurl compiles fine with the default target, and even with the openssl-sys dependency added to Cargo.toml.