cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.8k stars 379 forks source link

Crates calling rustc from build.rs broken (e.g. autocfg) #1527

Open larsch opened 4 months ago

larsch commented 4 months ago

Checklist

Describe your issue

Crates with a build.rs that try to execute rustc fail (libLLVM.so not in linker search path).

What target(s) are you cross-compiling for?

x86_64-pc-windows-gnu

Which operating system is the host (e.g computer cross is on) running?

What architecture is the host?

What container engine is cross using?

cross version

cross 0.2.5

Example

Run cargo init and add this build.rs:

fn main() {
    assert!(
        std::process::Command::new("rustc")
            .arg("--version")
            .status()
            .unwrap()
            .success(),
        "Failed to run rustc"
    );
}

Running cross run --target x86_64-pc-windows-gnu fails with the error Failed to run rust.

Caused by:
  process didn't exit successfully: `/target/debug/build/minimal-5e6e7e96bd90ecd5/build-script-build` (exit status: 101)
  --- stderr
  rustc: error while loading shared libraries: libLLVM.so.18.1-rust-1.81.0-nightly: cannot open shared object file: No such file or directory
  thread 'main' panicked at build.rs:2:5:
  Failed to run rustc
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Additional information / notes

Issue appears to be that the rust compiler is installed in /rust/lib which is not in the dynamic linker search path.

The autocfg crate tries to execute rustc to detect compiler version/features.

Workaround: Setting LD_LIBRARY_PATH=/rust/lib:

Cargo.toml:

[build.env]
passthrough = ["LD_LIBRARY_PATH=/rust/lib"]