From 4e3c11c73d2728b060330366fb0c831310aeb9cf Mon Sep 17 00:00:00 2001 From: Winter Date: Wed, 4 Jan 2023 18:15:20 -0500 Subject: [PATCH] rust: fix on aarch64-linux by using GCC 11 and passing `-lgcc` This change switches to using GCC 11 by default on aarch64-linux, as well as passing `-lgcc` to the linker, per #201485. See #201254 and #208412 for wider context on the issue. (cherry picked from commit 8442601c6445894b350e8b2b10717c1f609bedaf) --- pkgs/build-support/rust/hooks/cargo-setup-hook.sh | 2 ++ pkgs/build-support/rust/hooks/default.nix | 3 +++ pkgs/development/compilers/rust/rustc.nix | 4 +++- pkgs/top-level/all-packages.nix | 2 ++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/rust/hooks/cargo-setup-hook.sh b/pkgs/build-support/rust/hooks/cargo-setup-hook.sh index aeddeef29d928..8146573e79dba 100644 --- a/pkgs/build-support/rust/hooks/cargo-setup-hook.sh +++ b/pkgs/build-support/rust/hooks/cargo-setup-hook.sh @@ -1,6 +1,8 @@ cargoSetupPostUnpackHook() { echo "Executing cargoSetupPostUnpackHook" + export NIX_LDFLAGS+=" @aarch64LinuxGccWorkaround@" + # Some cargo builds include build hooks that modify their own vendor # dependencies. This copies the vendor directory into the build tree and makes # it writable. If we're using a tarball, the unpackFile hook already handles diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix index 6ee122adb52a1..f521de161e7f3 100644 --- a/pkgs/build-support/rust/hooks/default.nix +++ b/pkgs/build-support/rust/hooks/default.nix @@ -98,6 +98,9 @@ in { host-config = true target-applies-to-host = true ''; + + # https://github.com/NixOS/nixpkgs/issues/201254 + aarch64LinuxGccWorkaround = lib.optionalString (stdenv.isLinux && stdenv.isAarch64 && stdenv.cc.isGNU) "-lgcc"; }; } ./cargo-setup-hook.sh) {}; diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index 8288cd5c61e3e..7abe1b6158a46 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -52,7 +52,9 @@ in stdenv.mkDerivation rec { # when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch' optional (stdenv.isLinux && !withBundledLLVM) "--push-state --as-needed -lstdc++ --pop-state" ++ optional (stdenv.isDarwin && !withBundledLLVM) "-lc++" - ++ optional stdenv.isDarwin "-rpath ${llvmSharedForHost}/lib"); + ++ optional stdenv.isDarwin "-rpath ${llvmSharedForHost}/lib" + # https://github.com/NixOS/nixpkgs/issues/201254 + ++ optional (stdenv.isLinux && stdenv.isAarch64 && stdenv.cc.isGNU) "-lgcc"); # Increase codegen units to introduce parallelism within the compiler. RUSTFLAGS = "-Ccodegen-units=10"; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 6f334554674d3..1b0908628da5b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15012,6 +15012,8 @@ with pkgs; rust_1_66 = callPackage ../development/compilers/rust/1_66.nix { inherit (darwin.apple_sdk.frameworks) CoreFoundation Security SystemConfiguration; llvm_14 = llvmPackages_14.libllvm; + # https://github.com/NixOS/nixpkgs/issues/201254 + stdenv = if stdenv.isLinux && stdenv.isAarch64 && stdenv.cc.isGNU then gcc11Stdenv else stdenv; }; rust = rust_1_66;