cross-rs / cross

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

Nightly builds fail on many platforms now that nightly sets `-fuse-ld=lld` #1496

Closed autarch closed 1 month ago

autarch commented 1 month ago

Checklist

Describe your issue

Compilation fails on many platforms (maybe all?) because of this change in nightly:

cross -v +nightly build --locked --release --target x86_64-unknown-freebsd

...

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/rust/lib/rustlib/x86_64-unknown-linux-gnu/bin:/rust/lib/rustlib/x86_64-unknown-linux-gnu/bin/self-contained:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/rust/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcVrgDOH/symbols.o" "/target/release/build/libc-ac0b713d0dd5a2f4/build_script_build-ac0b713d0dd5a2f4.build_script_build.26c1efd651742760-cgu.0.rcgu.o" "/target/release/build/libc-ac0b713d0dd5a2f4/build_script_build-ac0b713d0dd5a2f4.build_script_build.26c1efd651742760-cgu.1.rcgu.o" "/target/release/build/libc-ac0b713d0dd5a2f4/build_script_build-ac0b713d0dd5a2f4.build_script_build.26c1efd651742760-cgu.2.rcgu.o" "/target/release/build/libc-ac0b713d0dd5a2f4/build_script_build-ac0b713d0dd5a2f4.build_script_build.26c1efd651742760-cgu.3.rcgu.o" "/target/release/build/libc-ac0b713d0dd5a2f4/build_script_build-ac0b713d0dd5a2f4.0p8wefs2ijwvpbvkr3biqh6z0.rcgu.o" "-Wl,--as-needed" "-L" "/target/release/deps" "-L" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-de48b8168d6cf4fa.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-9f3477fb95a0bba7.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-210d920812faea91.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libmemchr-f3d3451767410a17.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-1a79dd36d08251de.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-886230e7120831b2.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-2caea079085a58a2.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-a9d7d97cdc65a449.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-5727477b0a78105a.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-7e555563aa211118.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-c8f13465f1a795b2.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-ee5b5774583426df.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-14df174c91007922.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-e8bfe52be756260a.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-6275035a459b3ada.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-b6892f3c52c68f01.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-f72b956e24d1de70.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-632ae0f28c5e55ff.rlib" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-e8b7e96e438f08f6.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-B/rust/lib/rustlib/x86_64-unknown-linux-gnu/bin/gcc-ld" "-fuse-ld=lld" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/rust/lib/rustlib/x86_64-unknown-linux-gnu/lib/self-contained" "-o" "/target/release/build/libc-ac0b713d0dd5a2f4/build_script_build-ac0b713d0dd5a2f4" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,--strip-debug" "-nodefaultlibs"
  = note: cc: error: unrecognized command line option '-fuse-ld=lld'

I've tried lots of different methods of passing in the flag to tell it not to use lld, including:

Setting RUSTFLAGS when I invoke cross.

Various changes to my Cargo.toml:

[package.metadata.cross.target.x86_64-unknown-freebsd]
pre-build = [
    'set -x',
    'mkdir -p ~/.cargo',
    'echo "rustflags = [\"-Z linker-features=-lld\"]" >> ~/.cargo/config.toml',
    'cat ~/.cargo/config.toml',
]

And also:

[package.metadata.cross.target.x86_64-unknown-freebsd]
rustflags = ["-Z linker-features=-lld"]

None of these worked.

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

aarch64-unknown-freebsd

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

cross -v +nightly build --target x86_64-unknown-freebsd

I think this will fail on any project.

Additional information / notes

No response

autarch commented 1 month ago

This doesn't seem to be an issue with the latest repo version of cross for some reason. I don't see -fuse-ld=lld in the rustc commands that are run. This didn't require any changes to my crate's config.

Emilgardis commented 1 month ago

fuse-ld=lld requires GCC 9. The new feature enabled in nightly-2024-05-18 for toolchain x86_64-unknown-linux-gnu doesn't use the system LLVM, instead it uses a self-contained lld called rust-lld inside the toolchain bin folder (which is also put in path).

I'll have to investigate why it doesn't work on 0.2.5

The pre-build you shared should not work, ~ refers to the home of root. The rustflags setting you shared should have worked though.

upstream changes: https://github.com/rust-lang/rust/pull/124129 announcement: https://blog.rust-lang.org/2024/05/17/enabling-rust-lld-on-linux.html

VorpalBlade commented 1 month ago

Running into this too when cross compiling nightly from x86-64 to Aarch64. Seems like a regression in Rust to me.

Emilgardis commented 1 month ago

This should now be fixed with new nightly builds, thanks @VorpalBlade for reporting it upstream!