Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix pkgsMusl.rustc #186443

Merged
merged 7 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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