TheDan64 / inkwell

It's a New Kind of Wrapper for Exposing LLVM (Safely)
https://thedan64.github.io/inkwell/
Apache License 2.0
2.22k stars 217 forks source link

Mystery compilation errors with x86_64-unknown-linux-musl compilation target #499

Closed wareya closed 1 month ago

wareya commented 1 month ago

Describe the Bug

I'm trying to make a fully static build of a project that depends on inkwell using a github actions runner, a nix shell, and the x86_64-unknown-linux-musl rust target. But libinkwell_internals triggers a linking failure because it's somehow linking a version of libm that links glibc instead of musl's libc.

I can't tell if this is an issue with my own environment or not. inkwell_internals seems relatively simple and doesn't have a build.rs, so maybe it's a problem with one of the libraries inkwell_internals is pulling in...? Or maybe it's an issue with how procedural macros don't use the --target specified by Cargo, and I need to install more dependencies into my runner environment?

2024-05-20T13:01:23.0475071Z error: /home/runner/work/konoran/konoran/target/release/deps/libinkwell_internals-af28c4e2695b6f55.so: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.38' not found (required by /home/runner/work/konoran/konoran/target/release/deps/libinkwell_internals-af28c4e2695b6f55.so)
2024-05-20T13:01:23.0479036Z   --> /home/runner/.cargo/git/checkouts/inkwell-946411d814d2c9f8/5d5a531/src/lib.rs:15:1
2024-05-20T13:01:23.0741352Z    |
2024-05-20T13:01:23.0741869Z 15 | extern crate inkwell_internals;
2024-05-20T13:01:23.0742668Z    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

inkwell_internals is previously compiled as:

2024-05-20T13:01:17.6468896Z    Compiling inkwell_internals v0.9.0 (https://github.com/TheDan64/inkwell.git?rev=5d5a531c765a6ad37aa6591c0287d0f9109fff62#5d5a531c)
2024-05-20T13:01:17.6593627Z      Running `/home/runner/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/rustc --crate-name inkwell_internals --edition=2021 /home/runner/.cargo/git/checkouts/inkwell-946411d814d2c9f8/5d5a531/internal_macros/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type proc-macro --emit=dep-info,link -C prefer-dynamic -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=off -C metadata=af28c4e2695b6f55 -C extra-filename=-af28c4e2695b6f55 --out-dir /home/runner/work/konoran/konoran/target/release/deps -L dependency=/home/runner/work/konoran/konoran/target/release/deps --extern proc_macro2=/home/runner/work/konoran/konoran/target/release/deps/libproc_macro2-58938079c3742c1c.rlib --extern quote=/home/runner/work/konoran/konoran/target/release/deps/libquote-18c75a27a0cec5a8.rlib --extern syn=/home/runner/work/konoran/konoran/target/release/deps/libsyn-6f21f67ef447e8b4.rlib --extern proc_macro --cap-lints allow`

For reproducibility reasons I'm targeting a specific inkwell git revision in Cargo.toml:

inkwell = { git = "https://github.com/TheDan64/inkwell.git", rev = "5d5a531c765a6ad37aa6591c0287d0f9109fff62", features = ["llvm18-0"] }
llvm-sys = { version = "180", features = ["force-static"] }

To Reproduce

Haven't reproduced locally, only in the cloud: https://github.com/wareya/konoran/actions/runs/9159087795/job/25178738603

The length of weird rust errors are because of the compiler failing to link inkwell_internals during compilation; open up the raw logs and ctrl+f extern crate inkwell_internals.

Expected Behavior

I should be getting weird symbol resolution errors at the low-level linking stage at the end of compilation, rather than an error about glibc.

LLVM Version (please complete the following information):

llvm 18, inkwell revision 5d5a531c765a6ad37aa6591c0287d0f9109fff62

Desktop (please complete the following information):

Ubuntu-based github actions runner

wareya commented 1 month ago

I changed the runner from ubuntu-latest (ubuntu 22) to ubuntu-24.04 and this error went away. I assume that rustc was somehow finding a version of libm from the ubuntu environment and then finding a version of glibc from the nix shell environment, which were incompatible.