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

rustc: enable bpfe library targets #382166

Merged
merged 4 commits into from
Feb 19, 2025
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
15 changes: 12 additions & 3 deletions pkgs/development/compilers/rust/1_84.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
lib,
newScope,
callPackage,
CoreFoundation,
Security,
SystemConfiguration,
pkgsBuildTarget,
pkgsBuildBuild,
pkgsBuildHost,
Expand All @@ -28,6 +25,7 @@
llvm_19,
wrapCCWith,
overrideCC,
fetchpatch,
}@args:
let
llvmSharedFor =
Expand All @@ -50,6 +48,16 @@ import ./default.nix
rustcVersion = "1.84.1";
rustcSha256 = "Xi+11JYopUn3Zxssz5hVqzef1EKDGnwq8W4M3MMbs3U=";

rustcPatches = [
# Fix for including no_std targets by default, shipping in Rust 1.87
# https://github.com/rust-lang/rust/pull/137073
(fetchpatch {
name = "bootstrap-skip-nostd-docs";
url = "https://github.com/rust-lang/rust/commit/97962d7643300b91c102496ba3ab6d9279d2c536.patch";
hash = "sha256-DKl9PWqJP3mX4B1pFeRLQ8/sO6mx1JhbmVLTOOMLZI4=";
})
];

llvmSharedForBuild = llvmSharedFor pkgsBuildBuild;
llvmSharedForHost = llvmSharedFor pkgsBuildHost;
llvmSharedForTarget = llvmSharedFor pkgsBuildTarget;
Expand Down Expand Up @@ -135,5 +143,6 @@ import ./default.nix
"wrapCCWith"
"overrideCC"
"pkgsHostTarget"
"fetchpatch"
]
)
4 changes: 1 addition & 3 deletions pkgs/development/compilers/rust/cargo.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{ lib, stdenv, pkgsHostHost
, file, curl, pkg-config, python3, openssl, cmake, zlib
, installShellFiles, makeWrapper, rustPlatform, rustc
, CoreFoundation, Security
, auditable ? !cargo-auditable.meta.broken
, cargo-auditable
, pkgsBuildBuild
Expand Down Expand Up @@ -32,8 +31,7 @@ rustPlatform.buildRustPackage.override {
(lib.getDev pkgsHostHost.curl)
zlib
];
buildInputs = [ file curl python3 openssl zlib ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ CoreFoundation Security ];
buildInputs = [ file curl python3 openssl zlib ];

# cargo uses git-rs which is made for a version of libgit2 from recent master that
# is not compatible with the current version in nixpkgs.
Expand Down
3 changes: 1 addition & 2 deletions pkgs/development/compilers/rust/clippy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
lib,
rustPlatform,
rustc,
Security,
}:

rustPlatform.buildRustPackage {
Expand All @@ -19,7 +18,7 @@ rustPlatform.buildRustPackage {
# changes hash of vendor directory otherwise
dontUpdateAutotoolsGnuConfigScripts = true;

buildInputs = [ rustc.llvm ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ Security ];
buildInputs = [ rustc.llvm ];

# fixes: error: the option `Z` is only accepted on the nightly compiler
RUSTC_BOOTSTRAP = 1;
Expand Down
4 changes: 0 additions & 4 deletions pkgs/development/compilers/rust/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
}:
{ stdenv, lib
, newScope, callPackage
, CoreFoundation, Security, SystemConfiguration
, pkgsBuildBuild
, pkgsBuildHost
, pkgsBuildTarget
Expand Down Expand Up @@ -87,13 +86,11 @@ in
sysroot = if fastCross then self.rustc-unwrapped else null;
};
rustfmt = self.callPackage ./rustfmt.nix {
inherit Security;
inherit (self.buildRustPackages) rustc;
};
cargo = if (!fastCross) then self.callPackage ./cargo.nix {
# Use boot package set to break cycle
rustPlatform = bootRustPlatform;
inherit CoreFoundation Security;
} else self.callPackage ./cargo_cross.nix {};
cargo-auditable = self.callPackage ./cargo-auditable.nix { };
cargo-auditable-cargo-wrapper = self.callPackage ./cargo-auditable-cargo-wrapper.nix { };
Expand All @@ -102,7 +99,6 @@ in
# buildPackages.clippy uses the cross compiler and supports
# linting for the target platform.
rustPlatform = makeRustPlatform self;
inherit Security;
};
});
};
Expand Down
45 changes: 22 additions & 23 deletions pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,22 @@ stdenv.mkDerivation (finalAttrs: {
concatStringsSep "," (
[
stdenv.targetPlatform.rust.rustcTargetSpec

# Other targets that don't need any extra dependencies to build.
]
# Other targets that don't need any extra dependencies to build.
++ optionals (!fastCross) [
"wasm32-unknown-unknown"

# (build!=target): When cross-building a compiler we need to add
# the build platform as well so rustc can compile build.rs
# scripts.
"bpfel-unknown-none"
"bpfeb-unknown-none"
]
# (build!=target): When cross-building a compiler we need to add
# the build platform as well so rustc can compile build.rs
# scripts.
++ optionals (stdenv.buildPlatform != stdenv.targetPlatform && !fastCross) [
stdenv.buildPlatform.rust.rustcTargetSpec

# (host!=target): When building a cross-targeting compiler we
# need to add the host platform as well so rustc can compile
# build.rs scripts.
]
# (host!=target): When building a cross-targeting compiler we
# need to add the host platform as well so rustc can compile
# build.rs scripts.
++ optionals (stdenv.hostPlatform != stdenv.targetPlatform && !fastCross) [
stdenv.hostPlatform.rust.rustcTargetSpec
]
Expand Down Expand Up @@ -236,19 +235,19 @@ stdenv.mkDerivation (finalAttrs: {
# library and reuse compiler
buildPhase =
if fastCross then
"
runHook preBuild

mkdir -p build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-{std,rustc}/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/
ln -s ${rustc.unwrapped}/lib/rustlib/${stdenv.hostPlatform.rust.rustcTargetSpec}/libstd-*.so build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-std/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/libstd.so
ln -s ${rustc.unwrapped}/lib/rustlib/${stdenv.hostPlatform.rust.rustcTargetSpec}/librustc_driver-*.so build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/librustc.so
ln -s ${rustc.unwrapped}/bin/rustc build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/rustc-main
touch build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-std/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/.libstd.stamp
touch build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/.librustc.stamp
python ./x.py --keep-stage=0 --stage=1 build library

runHook postBuild
"
''
runHook preBuild

mkdir -p build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-{std,rustc}/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/
ln -s ${rustc.unwrapped}/lib/rustlib/${stdenv.hostPlatform.rust.rustcTargetSpec}/libstd-*.so build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-std/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/libstd.so
ln -s ${rustc.unwrapped}/lib/rustlib/${stdenv.hostPlatform.rust.rustcTargetSpec}/librustc_driver-*.so build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/librustc.so
ln -s ${rustc.unwrapped}/bin/rustc build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/rustc-main
touch build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-std/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/.libstd.stamp
touch build/${stdenv.hostPlatform.rust.rustcTargetSpec}/stage0-rustc/${stdenv.hostPlatform.rust.rustcTargetSpec}/release/.librustc.stamp
python ./x.py --keep-stage=0 --stage=1 build library

runHook postBuild
''
else
null;

Expand Down
3 changes: 1 addition & 2 deletions pkgs/development/compilers/rust/rustfmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
makeWrapper,
rustPlatform,
rustc,
Security,
asNightly ? false,
}:

Expand All @@ -26,7 +25,7 @@ rustPlatform.buildRustPackage {

buildInputs = [
rustc.llvm
] ++ lib.optional stdenv.hostPlatform.isDarwin Security;
];

# rustfmt uses the rustc_driver and std private libraries, and Rust's build process forces them to have
# an install name of `@rpath/...` [0] [1] instead of the standard on macOS, which is an absolute path
Expand Down
1 change: 0 additions & 1 deletion pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6578,7 +6578,6 @@ with pkgs;
wrapRustc = rustc-unwrapped: wrapRustcWith { inherit rustc-unwrapped; };

rust_1_84 = callPackage ../development/compilers/rust/1_84.nix {
inherit (darwin.apple_sdk.frameworks) CoreFoundation Security SystemConfiguration;
llvm_19 = llvmPackages_19.libllvm;
};
rust = rust_1_84;
Expand Down