-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
rustc: be extremely principled about cross builds #356769
Draft
rhelmot
wants to merge
1
commit into
NixOS:staging
Choose a base branch
from
rhelmot:rustc-cross
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,7 +52,9 @@ let | |
concatStringsSep | ||
; | ||
inherit (darwin.apple_sdk.frameworks) Security; | ||
useLLVM = stdenv.targetPlatform.useLLVM or false; | ||
useLLVMTarget = stdenv.targetPlatform.useLLVM or false; | ||
useLLVMHost = stdenv.hostPlatform.useLLVM or false; | ||
useLLVMBuild = llvmSharedForBuild.stdenv.cc.libcxx.isLLVM or false; | ||
in | ||
stdenv.mkDerivation (finalAttrs: { | ||
pname = "${targetPackages.stdenv.cc.targetPrefix}rustc"; | ||
|
@@ -93,19 +95,8 @@ stdenv.mkDerivation (finalAttrs: { | |
"${pkgsBuildHost.stdenv.cc.targetPrefix}pkg-config"; | ||
|
||
NIX_LDFLAGS = toString ( | ||
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch' | ||
# This doesn't apply to cross-building for FreeBSD because the host | ||
# uses libstdc++, but the target (used for building std) uses libc++ | ||
optional ( | ||
stdenv.hostPlatform.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && !useLLVM | ||
) "--push-state --as-needed -lstdc++ --pop-state" | ||
++ | ||
optional | ||
(stdenv.hostPlatform.isLinux && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD && useLLVM) | ||
"--push-state --as-needed -L${llvmPackages.libcxx}/lib -lc++ -lc++abi -lLLVM-${lib.versions.major llvmPackages.llvm.version} --pop-state" | ||
++ optional (stdenv.hostPlatform.isDarwin && !withBundledLLVM) "-lc++ -lc++abi" | ||
++ optional stdenv.hostPlatform.isFreeBSD "-rpath ${llvmPackages.libunwind}/lib" | ||
++ optional stdenv.hostPlatform.isDarwin "-rpath ${llvmSharedForHost.lib}/lib" | ||
optional (stdenv.buildPlatform.isDarwin && !withBundledLLVM) "-lc++ -lc++abi" | ||
++ optional stdenv.buildPlatform.isDarwin "-rpath ${llvmSharedForHost.lib}/lib" | ||
); | ||
|
||
# Increase codegen units to introduce parallelism within the compiler. | ||
|
@@ -199,15 +190,23 @@ stdenv.mkDerivation (finalAttrs: { | |
++ optionals (!withBundledLLVM) [ | ||
"--enable-llvm-link-shared" | ||
"${setBuild}.llvm-config=${llvmSharedForBuild.dev}/bin/llvm-config" | ||
"${setHost}.llvm-config=${llvmSharedForHost.dev}/bin/llvm-config" | ||
"${setTarget}.llvm-config=${llvmSharedForTarget.dev}/bin/llvm-config" | ||
] | ||
++ ( | ||
if (llvmShared.stdenv.hostPlatform == llvmShared.stdenv.buildPlatform) then | ||
[ | ||
"${setHost}.llvm-config=${llvmShared.dev}/bin/llvm-config" | ||
] | ||
else | ||
[ | ||
"${setHost}.llvm-config=${llvmShared.dev}/bin/llvm-config-native" | ||
] | ||
) | ||
++ optionals fastCross [ | ||
# Since fastCross only builds std, it doesn't make sense (and | ||
# doesn't work) to build a linker. | ||
"--disable-llvm-bitcode-linker" | ||
] | ||
++ optionals (stdenv.targetPlatform.isLinux && !(stdenv.targetPlatform.useLLVM or false)) [ | ||
++ optionals (stdenv.targetPlatform.isLinux && !useLLVMTarget) [ | ||
"--enable-profiler" # build libprofiler_builtins | ||
] | ||
++ optionals stdenv.buildPlatform.isMusl [ | ||
|
@@ -226,9 +225,34 @@ stdenv.mkDerivation (finalAttrs: { | |
# https://github.com/rust-lang/rust/issues/92173 | ||
"--set rust.jemalloc" | ||
] | ||
++ optionals (useLLVM && !stdenv.targetPlatform.isFreeBSD) [ | ||
++ [ | ||
# https://github.com/NixOS/nixpkgs/issues/311930 | ||
"--llvm-libunwind=${if withBundledLLVM then "in-tree" else "system"}" | ||
"${setBuild}.llvm-libunwind=${ | ||
if (!useLLVMBuild || stdenv.buildPlatform.isFreeBSD) then | ||
"no" | ||
else if withBundledLLVM then | ||
"in-tree" | ||
else | ||
"system" | ||
}" | ||
"${setHost}.llvm-libunwind=${ | ||
if (!useLLVMHost || stdenv.hostPlatform.isFreeBSD) then | ||
"no" | ||
else if withBundledLLVM then | ||
"in-tree" | ||
else | ||
"system" | ||
}" | ||
"${setTarget}.llvm-libunwind=${ | ||
if (!useLLVMTarget || stdenv.targetPlatform.isFreeBSD) then | ||
"no" | ||
else if withBundledLLVM then | ||
"in-tree" | ||
else | ||
"system" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is repeated three times — maybe a function? |
||
}" | ||
] | ||
++ optionals (withBundledLLVM && useLLVMHost) [ | ||
"--enable-use-libcxx" | ||
]; | ||
|
||
|
@@ -311,7 +335,7 @@ stdenv.mkDerivation (finalAttrs: { | |
directory = "vendor" | ||
EOF | ||
'' | ||
+ lib.optionalString (stdenv.hostPlatform.isFreeBSD) '' | ||
+ lib.optionalString (stdenv.buildPlatform.isFreeBSD) '' | ||
# lzma-sys bundles an old version of xz that doesn't build | ||
# on modern FreeBSD, use the system one instead | ||
substituteInPlace src/bootstrap/src/core/build_steps/tool.rs \ | ||
|
@@ -340,6 +364,13 @@ stdenv.mkDerivation (finalAttrs: { | |
pkg-config | ||
xz | ||
] | ||
# splicing isn't working here - saying llvmPackages.libcxx here does not give you libcxx for the build platform. | ||
# e.g. if you're doing linux -> freebsd -> freebsd cross, the libcxx here would be linked against freebsd libc.so.7 | ||
++ optionals (!withBundledLLVM && useLLVMBuild) [ | ||
llvmSharedForBuild.stdenv.cc.libcxx | ||
pkgsBuildBuild.llvmPackages.libunwind | ||
] | ||
++ optional (!withBundledLLVM) llvmSharedForBuild.lib | ||
++ optionals fastCross [ | ||
lndir | ||
makeWrapper | ||
|
@@ -353,7 +384,8 @@ stdenv.mkDerivation (finalAttrs: { | |
zlib | ||
] | ||
++ optional (!withBundledLLVM) llvmShared.lib | ||
++ optional (useLLVM && !withBundledLLVM && !stdenv.targetPlatform.isFreeBSD) [ | ||
++ optional (!withBundledLLVM && (useLLVMHost || useLLVMTarget)) llvmPackages.libcxx | ||
++ optionals (useLLVMHost && !withBundledLLVM && !stdenv.hostPlatform.isFreeBSD) [ | ||
llvmPackages.libunwind | ||
# Hack which is used upstream https://github.com/gentoo/gentoo/blob/master/dev-lang/rust/rust-1.78.0.ebuild#L284 | ||
(runCommandLocal "libunwind-libgcc" { } '' | ||
|
@@ -402,7 +434,12 @@ stdenv.mkDerivation (finalAttrs: { | |
|
||
passthru = { | ||
llvm = llvmShared; | ||
inherit llvmPackages; | ||
inherit | ||
llvmPackages | ||
llvmSharedForBuild | ||
llvmSharedForHost | ||
llvmSharedForTarget | ||
; | ||
inherit (rustc) tier1TargetPlatforms targetPlatforms badTargetPlatforms; | ||
tests = { | ||
inherit fd ripgrep wezterm; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should always create llvm-config-native, even in non-cross builds… This is fine for now though!