Skip to content

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

Open
@larsch

Description

@larsch

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?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

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"]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions