diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix index d336924570771..652b074c30206 100644 --- a/pkgs/build-support/rust/hooks/default.nix +++ b/pkgs/build-support/rust/hooks/default.nix @@ -75,11 +75,8 @@ in { ${lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) '' [target."${shortTarget}"] "linker" = "${ccForHost}" - ${# https://github.com/rust-lang/rust/issues/46651#issuecomment-433611633 - lib.optionalString (stdenv.hostPlatform.isMusl && stdenv.hostPlatform.isAarch64) '' - "rustflags" = [ "-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc" ] - ''} ''} + "rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ] ''; }; } ./cargo-setup-hook.sh) {}; diff --git a/pkgs/development/compilers/rust/binary.nix b/pkgs/development/compilers/rust/binary.nix index 1145f4da8f663..6c3751cbb5757 100644 --- a/pkgs/development/compilers/rust/binary.nix +++ b/pkgs/development/compilers/rust/binary.nix @@ -1,4 +1,5 @@ { lib, stdenv, makeWrapper, bash, curl, darwin, zlib +, autoPatchelfHook, gcc , version , src , platform @@ -31,7 +32,9 @@ rec { license = [ licenses.mit licenses.asl20 ]; }; + nativeBuildInputs = lib.optional (!stdenv.isDarwin) autoPatchelfHook; buildInputs = [ bash ] + ++ lib.optionals (!stdenv.isDarwin) [ gcc.cc.lib zlib ] ++ lib.optional stdenv.isDarwin Security; postPatch = '' @@ -42,24 +45,6 @@ rec { ./install.sh --prefix=$out \ --components=${installComponents} - ${optionalString (stdenv.isLinux && bootstrapping) ('' - patchelf \ - --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ - "$out/bin/rustc" - '' + optionalString (lib.versionAtLeast version "1.46") - # rustc bootstrap needs libz starting from 1.46 - '' - ln -s ${zlib}/lib/libz.so.1 $out/lib/libz.so.1 - ln -s ${zlib}/lib/libz.so $out/lib/libz.so - '' + '' - patchelf \ - --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ - "$out/bin/rustdoc" - patchelf \ - --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ - "$out/bin/cargo" - '')} - # Do NOT, I repeat, DO NOT use `wrapProgram` on $out/bin/rustc # (or similar) here. It causes strange effects where rustc loads # the wrong libraries in a bootstrap-build causing failures that @@ -83,8 +68,11 @@ rec { license = [ licenses.mit licenses.asl20 ]; }; - nativeBuildInputs = [ makeWrapper ]; - buildInputs = [ bash ] ++ lib.optional stdenv.isDarwin Security; + nativeBuildInputs = [ makeWrapper ] + ++ lib.optional (!stdenv.isDarwin) autoPatchelfHook; + buildInputs = [ bash ] + ++ lib.optional (!stdenv.isDarwin) gcc.cc.lib + ++ lib.optional stdenv.isDarwin Security; postPatch = '' patchShebangs . @@ -95,12 +83,6 @@ rec { ./install.sh --prefix=$out \ --components=cargo - ${optionalString (stdenv.isLinux && bootstrapping) '' - patchelf \ - --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ - "$out/bin/cargo" - ''} - wrapProgram "$out/bin/cargo" \ --suffix PATH : "${rustc}/bin" ''; diff --git a/pkgs/development/compilers/rust/cargo.nix b/pkgs/development/compilers/rust/cargo.nix index b50f36f0d9b64..2d8361eb2a4e1 100644 --- a/pkgs/development/compilers/rust/cargo.nix +++ b/pkgs/development/compilers/rust/cargo.nix @@ -72,5 +72,7 @@ rustPlatform.buildRustPackage { maintainers = with maintainers; [ retrry ]; license = [ licenses.mit licenses.asl20 ]; platforms = platforms.unix; + # weird segfault in a build script + broken = stdenv.targetPlatform.isMusl && !stdenv.targetPlatform.isStatic; }; } diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index a996f987bed66..cfed71f0e80bd 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -87,6 +87,10 @@ in stdenv.mkDerivation rec { "${setBuild}.cxx=${cxxForBuild}" "${setHost}.cxx=${cxxForHost}" "${setTarget}.cxx=${cxxForTarget}" + + "${setBuild}.crt-static=${lib.boolToString stdenv.buildPlatform.isStatic}" + "${setHost}.crt-static=${lib.boolToString stdenv.hostPlatform.isStatic}" + "${setTarget}.crt-static=${lib.boolToString stdenv.targetPlatform.isStatic}" ] ++ optionals (!withBundledLLVM) [ "--enable-llvm-link-shared" "${setBuild}.llvm-config=${llvmSharedForBuild.dev}/bin/llvm-config" @@ -188,8 +192,5 @@ in stdenv.mkDerivation rec { maintainers = with maintainers; [ madjar cstrahan globin havvy ]; license = [ licenses.mit licenses.asl20 ]; platforms = platforms.linux ++ platforms.darwin; - # rustc can't generate binaries for dynamically linked Musl. - # https://github.com/NixOS/nixpkgs/issues/179242 - broken = stdenv.targetPlatform.isMusl && !stdenv.targetPlatform.isStatic; }; } diff --git a/pkgs/development/python-modules/pyelftools/default.nix b/pkgs/development/python-modules/pyelftools/default.nix index cec999bf999a5..1f0bcc15b3ea1 100644 --- a/pkgs/development/python-modules/pyelftools/default.nix +++ b/pkgs/development/python-modules/pyelftools/default.nix @@ -20,7 +20,7 @@ buildPythonPackage rec { hash = "sha256-+T5C0ah2oj5E8fWaQbuzYRVgD5bSiUbaArrlxNLojvw="; }; - doCheck = stdenv.hostPlatform.system == "x86_64-linux"; + doCheck = stdenv.hostPlatform.system == "x86_64-linux" && stdenv.hostPlatform.isGnu; checkPhase = '' patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" test/external_tools/readelf