Skip to content

Commit

Permalink
Merge pull request #186443 from yu-re-ka/feature/rustc-musl2
Browse files Browse the repository at this point in the history
fix pkgsMusl.rustc
  • Loading branch information
Mic92 authored Aug 13, 2022
2 parents e971e42 + a67c5f8 commit f08b424
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 34 deletions.
5 changes: 1 addition & 4 deletions pkgs/build-support/rust/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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) {};
Expand Down
34 changes: 8 additions & 26 deletions pkgs/development/compilers/rust/binary.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{ lib, stdenv, makeWrapper, bash, curl, darwin, zlib
, autoPatchelfHook, gcc
, version
, src
, platform
Expand Down Expand Up @@ -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 = ''
Expand All @@ -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
Expand All @@ -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 .
Expand All @@ -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"
'';
Expand Down
2 changes: 2 additions & 0 deletions pkgs/development/compilers/rust/cargo.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
7 changes: 4 additions & 3 deletions pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
};
}
2 changes: 1 addition & 1 deletion pkgs/development/python-modules/pyelftools/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f08b424

Please sign in to comment.