This commit is contained in:
oxalica
2024-06-26 02:34:42 -04:00
parent 538c183a35
commit 71a5e540c1
7 changed files with 406 additions and 278 deletions

View File

@@ -4,16 +4,23 @@
config = "x86_64-w64-mingw32";
};
overlays = [ (import ../..) ];
}).callPackage (
{ mkShell, stdenv, rust-bin, windows, wine64 }:
}).callPackage
(
{
mkShell,
stdenv,
rust-bin,
windows,
wine64,
}:
mkShell {
nativeBuildInputs = [
rust-bin.stable.latest.minimal
];
nativeBuildInputs = [ rust-bin.stable.latest.minimal ];
depsBuildBuild = [ wine64 ];
buildInputs = [ windows.pthreads ];
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${stdenv.cc.targetPrefix}cc";
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER = "wine64";
}) {}
}
)
{ }

View File

@@ -6,9 +6,15 @@
useLLVM = true;
};
overlays = [ (import ../..) ];
}).callPackage (
}).callPackage
(
# We don't need WASI C compiler from nixpkgs, so use `mkShellNoCC`.
{ mkShellNoCC, stdenv, rust-bin, wasmtime }:
{
mkShellNoCC,
stdenv,
rust-bin,
wasmtime,
}:
mkShellNoCC {
nativeBuildInputs = [ rust-bin.stable.latest.minimal ];
@@ -18,5 +24,6 @@ mkShellNoCC {
# the bundled `lld` for linking.
# CARGO_TARGET_WASM32_WASI_LINKER = "${stdenv.cc.targetPrefix}cc";
CARGO_TARGET_WASM32_WASI_RUNNER = "wasmtime";
}) {}
}
)
{ }

View File

@@ -8,7 +8,9 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = { self, nixpkgs }@inputs: let
outputs =
{ self, nixpkgs }@inputs:
let
inherit (nixpkgs) lib;
inherit (lib) filterAttrs mapAttrs' replaceStrings;
@@ -25,16 +27,22 @@
#
# Note that this does not contain compatible attrs for mozilla-overlay.
mkRustBin =
{ distRoot ? defaultDistRoot }:
{
distRoot ? defaultDistRoot,
}:
pkgs:
lib.fix (rust-bin: import ./lib/rust-bin.nix {
lib.fix (
rust-bin:
import ./lib/rust-bin.nix {
inherit lib pkgs;
inherit (pkgs.rust) toRustTarget;
inherit (rust-bin) nightly;
manifests = mkManifests distRoot;
});
}
);
in {
in
{
lib = {
# Internal use only!
_internal = {
@@ -53,37 +61,34 @@
packages =
let
select = version: comps:
select =
version: comps:
if comps ? default then
comps.default // {
minimal = comps.minimal or (throw "missing profile 'minimal' for ${version}");
}
comps.default // { minimal = comps.minimal or (throw "missing profile 'minimal' for ${version}"); }
else
null;
result = rust-bin:
result =
rust-bin:
mapAttrs' (version: comps: {
name = if version == "latest"
then "rust"
else "rust_${replaceStrings ["."] ["_"] version}";
name = if version == "latest" then "rust" else "rust_${replaceStrings [ "." ] [ "_" ] version}";
value = select version comps;
}) rust-bin.stable //
mapAttrs' (version: comps: {
name = if version == "latest"
then "rust-nightly"
else "rust-nightly_${version}";
}) rust-bin.stable
// mapAttrs' (version: comps: {
name = if version == "latest" then "rust-nightly" else "rust-nightly_${version}";
value = select version comps;
}) rust-bin.nightly //
mapAttrs' (version: comps: {
name = if version == "latest"
then "rust-beta"
else "rust-beta_${version}";
}) rust-bin.nightly
// mapAttrs' (version: comps: {
name = if version == "latest" then "rust-beta" else "rust-beta_${version}";
value = select version comps;
}) rust-bin.beta;
result' = rust-bin: filterAttrs (name: drv: drv != null) (result rust-bin);
in
forEachSystem (system:
forEachSystem (
system:
result' (mkRustBin { } nixpkgs.legacyPackages.${system})
// { default = self.packages.${system}.rust; }
// {
default = self.packages.${system}.rust;
}
);
checks = forEachSystem (import ./tests inputs);

View File

@@ -41,14 +41,17 @@ let
"rustc-docs"
"rust-src" # This has only one special target `*`
];
rustPkgExtra = pkgs: target: let
singleTargetTups = map
(pkg: { inherit pkg target; })
(filter (p: hasAttr p pkgs && hasAttr target pkgs.${p}.target) singleTargetExtensions);
multiTargetTups = concatMap
(pkg: map (target: { inherit pkg target; }) (attrNames pkgs.${pkg}.target))
(filter (p: hasAttr p pkgs) multiTargetExtensions);
in {
rustPkgExtra =
pkgs: target:
let
singleTargetTups = map (pkg: { inherit pkg target; }) (
filter (p: hasAttr p pkgs && hasAttr target pkgs.${p}.target) singleTargetExtensions
);
multiTargetTups = concatMap (
pkg: map (target: { inherit pkg target; }) (attrNames pkgs.${pkg}.target)
) (filter (p: hasAttr p pkgs) multiTargetExtensions);
in
{
components = map (pkg: { inherit pkg target; }) components;
extensions = singleTargetTups ++ multiTargetTups;
};
@@ -77,20 +80,34 @@ let
renames = mapAttrs (from: to: { inherit to; }) (elemAt renamesList r);
pkg =
mapAttrs (pkgName: { u ? null /* Version appears in URL */, ... }@hashes: {
mapAttrs
(
pkgName:
{
u ? null, # Version appears in URL
...
}@hashes:
{
# We use rustc version for all components to reduce manifest size.
# This version is just used for component derivation name.
version = "${v} (000000000 ${d})"; # "<version> (<commit-hash> yyyy-mm-dd)"
target = let
results = mapAttrs' (targetIdx: hash: let
target =
let
results = mapAttrs' (
targetIdx: hash:
let
target = targets.${targetIdx};
pkgNameStripped = removeSuffix "-preview" pkgName;
targetTail = if targetIdx == "_" then "" else "-" + target;
urlVersion =
if u != null then u # Use specified version for URL if exists.
else if channel == "stable" then v # For stable channel, default to be rustc version.
else channel; # Otherwise, for beta/nightly channel, default to be "beta"/"nightly".
in {
if u != null then
u # Use specified version for URL if exists.
else if channel == "stable" then
v # For stable channel, default to be rustc version.
else
channel; # Otherwise, for beta/nightly channel, default to be "beta"/"nightly".
in
{
name = target;
value =
# Normally, hash is just the hash.
@@ -98,15 +115,26 @@ let
{
xz_url = "${distRoot}/${date}/${pkgNameStripped}-${urlVersion}${targetTail}.tar.xz";
xz_hash = hash;
} // (if pkgName == "rust" then rustPkgExtra pkg target else {})
}
// (if pkgName == "rust" then rustPkgExtra pkg target else { })
# But hash can be an integer to forward to another URL.
# This occurs in aarch64-apple-darwin rust-docs on 2022-02-02.
else
results.${targets."_${toString hash}"};
}) (removeAttrs hashes ["u"]);
}
) (removeAttrs hashes [ "u" ]);
in
results;
}) (removeAttrs manifest ["v" "d" "r" "p"]);
}
)
(
removeAttrs manifest [
"v"
"d"
"r"
"p"
]
);
profiles = if p == null then { } else elemAt profilesList p;

View File

@@ -129,7 +129,8 @@ let
];
# Darwin binaries usually just work... except for these linking to rustc from another drv.
postFixup = optionalString (hostPlatform.isDarwin && linksToRustc) ''
postFixup =
optionalString (hostPlatform.isDarwin && linksToRustc) ''
for f in $out/bin/*; do
install_name_tool -add_rpath "${self.rustc}/lib" "$f" || true
done
@@ -153,9 +154,15 @@ let
dsts=( "$out"/lib/rustlib/*/bin/gcc-ld/ld.lld )
if [[ ''${#dsts} -ne 0 ]]; then
mkdir -p $out/nix-support
substituteAll ${path + "/pkgs/build-support/wrapper-common/utils.bash"} $out/nix-support/utils.bash
substituteAll ${path + "/pkgs/build-support/bintools-wrapper/add-flags.sh"} $out/nix-support/add-flags.sh
substituteAll ${path + "/pkgs/build-support/bintools-wrapper/add-hardening.sh"} $out/nix-support/add-hardening.sh
substituteAll ${
path + "/pkgs/build-support/wrapper-common/utils.bash"
} $out/nix-support/utils.bash
substituteAll ${
path + "/pkgs/build-support/bintools-wrapper/add-flags.sh"
} $out/nix-support/add-flags.sh
substituteAll ${
path + "/pkgs/build-support/bintools-wrapper/add-hardening.sh"
} $out/nix-support/add-hardening.sh
for dst in "''${dsts[@]}"; do
# The ld.lld is path/name sensitive because itself is a wrapper. Keep its original name.

View File

@@ -338,26 +338,31 @@ let
# All extensions in this list will be installed for the target architectures.
# *Attention* If you want to install an extension like rust-src, that has no fixed architecture (arch *),
# you will need to specify this extension in the extensions options or it will not be installed!
toolchainFromManifest = manifest: let
toolchainFromManifest =
manifest:
let
# platform -> true
# For fail-fast test.
allPlatformSet =
listToAttrs (
allPlatformSet = listToAttrs (
flatten (
mapAttrsToList (compName: { target, ... }:
map (platform: { name = platform; value = true; })
(attrNames target)
) manifest.pkg));
mapAttrsToList (
compName:
{ target, ... }:
map (platform: {
name = platform;
value = true;
}) (attrNames target)
) manifest.pkg
)
);
# componentName -> true
# May also contains unavailable components. Just for fail-fast test.
allComponentSet =
mapAttrs (compName: _: true)
(manifest.pkg // manifest.renames);
allComponentSet = mapAttrs (compName: _: true) (manifest.pkg // manifest.renames);
# componentSet.x86_64-unknown-linux-gnu.cargo = <derivation>;
componentSet =
mapAttrs (platform: _:
componentSet = mapAttrs (
platform: _:
mkComponentSet {
inherit (manifest) version renames;
inherit platform;
@@ -380,24 +385,41 @@ let
}
) allPlatformSet;
mkProfile = name: profileComponents:
makeOverridable ({ extensions, targets, targetExtensions }:
mkProfile =
name: profileComponents:
makeOverridable
(
{
extensions,
targets,
targetExtensions,
}:
mkAggregated {
pname = "rust-${name}";
inherit (manifest) version date;
availableComponents = componentSet.${rustHostPlatform};
selectedComponents = resolveComponents {
name = "rust-${name}-${manifest.version}";
inherit allPlatformSet allComponentSet componentSet profileComponents targetExtensions;
inherit
allPlatformSet
allComponentSet
componentSet
profileComponents
targetExtensions
;
inherit (manifest) targetComponentsList;
extensions = extensions;
targets = unique ([
targets = unique (
[
rustHostPlatform # Build script requires host std.
rustTargetPlatform
] ++ targets);
]
++ targets
);
};
}
) {
)
{
extensions = [ ];
targets = [ ];
targetExtensions = [ ];
@@ -407,15 +429,18 @@ let
result =
# Individual components.
componentSet.${rustHostPlatform} //
componentSet.${rustHostPlatform}
//
# Profiles.
profiles // {
profiles
// {
# Legacy support for special pre-aggregated package.
# It has more components than `default` profile but less than `complete` profile.
rust =
let
pkg = mkProfile "legacy" [ "rust" ];
in if profiles != {} then
in
if profiles != { } then
trace ''
Rust ${manifest.version}:
Pre-aggregated package `rust` is not encouraged for stable channel since it contains almost all and uncertain components.

View File

@@ -89,54 +89,103 @@ optionalAttrs
rust-channel-of-stable = assertEq (rustChannelOf { channel = "stable"; }).rustc stable.latest.rustc;
rust-channel-of-beta = assertEq (rustChannelOf { channel = "beta"; }).rustc beta.latest.rustc;
rust-channel-of-nightly = assertEq (rustChannelOf { channel = "nightly"; }).rustc nightly.latest.rustc;
rust-channel-of-version = assertEq (rustChannelOf { channel = "1.48.0"; }).rustc stable."1.48.0".rustc;
rust-channel-of-nightly-date = assertEq (rustChannelOf { channel = "nightly"; date = "2021-01-01"; }).rustc nightly."2021-01-01".rustc;
rust-channel-of-beta-date = assertEq (rustChannelOf { channel = "beta"; date = "2021-01-01"; }).rustc beta."2021-01-01".rustc;
rust-channel-of-nightly = assertEq (rustChannelOf { channel = "nightly"; })
.rustc nightly.latest.rustc;
rust-channel-of-version = assertEq (rustChannelOf { channel = "1.48.0"; })
.rustc stable."1.48.0".rustc;
rust-channel-of-nightly-date = assertEq (rustChannelOf {
channel = "nightly";
date = "2021-01-01";
}).rustc nightly."2021-01-01".rustc;
rust-channel-of-beta-date = assertEq (rustChannelOf {
channel = "beta";
date = "2021-01-01";
}).rustc beta."2021-01-01".rustc;
rustup-toolchain-stable = assertEq (fromRustupToolchain { channel = "stable"; }) stable.latest.default;
rustup-toolchain-stable = assertEq (fromRustupToolchain {
channel = "stable";
}) stable.latest.default;
rustup-toolchain-beta = assertEq (fromRustupToolchain { channel = "beta"; }) beta.latest.default;
# rustup-toolchain-nightly = assertEq (fromRustupToolchain { channel = "nightly"; }) nightly.latest.default; # Not always available
rustup-toolchain-version = assertEq (fromRustupToolchain { channel = "1.51.0"; }) stable."1.51.0".default;
rustup-toolchain-nightly-date = assertEq (fromRustupToolchain { channel = "nightly-2021-01-01"; }) nightly."2021-01-01".default;
rustup-toolchain-beta-date = assertEq (fromRustupToolchain { channel = "beta-2021-01-01"; }) beta."2021-01-01".default;
rustup-toolchain-customization = assertEq
rustup-toolchain-version = assertEq (fromRustupToolchain {
channel = "1.51.0";
}) stable."1.51.0".default;
rustup-toolchain-nightly-date = assertEq (fromRustupToolchain {
channel = "nightly-2021-01-01";
}) nightly."2021-01-01".default;
rustup-toolchain-beta-date = assertEq (fromRustupToolchain {
channel = "beta-2021-01-01";
}) beta."2021-01-01".default;
rustup-toolchain-customization =
assertEq
(fromRustupToolchain {
channel = "1.51.0";
components = [ "rustfmt" "rustc-dev" ];
targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
components = [
"rustfmt"
"rustc-dev"
];
targets = [
"wasm32-unknown-unknown"
"aarch64-unknown-linux-gnu"
];
})
(stable."1.51.0".default.override {
extensions = [ "rustfmt" "rustc-dev" ];
targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
});
(
stable."1.51.0".default.override {
extensions = [
"rustfmt"
"rustc-dev"
];
targets = [
"wasm32-unknown-unknown"
"aarch64-unknown-linux-gnu"
];
}
);
rustup-toolchain-profile-missing = assertEq (builtins.tryEval (fromRustupToolchain { channel = "1.51.0"; profile = "non_existent"; })).success false;
rustup-toolchain-profile-too-early = assertEq (builtins.tryEval (fromRustupToolchain { channel = "1.29.0"; profile = "minimal"; })).success false;
rustup-toolchain-profile-fallback = assertEq (fromRustupToolchain { channel = "1.29.0"; }) stable."1.29.0".rust;
rustup-toolchain-profile-missing = assertEq (builtins.tryEval (fromRustupToolchain {
channel = "1.51.0";
profile = "non_existent";
})).success false;
rustup-toolchain-profile-too-early = assertEq (builtins.tryEval (fromRustupToolchain {
channel = "1.29.0";
profile = "minimal";
})).success false;
rustup-toolchain-profile-fallback = assertEq (fromRustupToolchain {
channel = "1.29.0";
}) stable."1.29.0".rust;
rustup-toolchain-file-toml = assertEq
(fromRustupToolchainFile ./rust-toolchain-toml)
(nightly."2021-03-25".default.override {
extensions = [ "rustfmt" "rustc-dev" ];
targets = [ "wasm32-unknown-unknown" "aarch64-unknown-linux-gnu" ];
});
rustup-toolchain-file-legacy = assertEq
(fromRustupToolchainFile ./rust-toolchain-legacy)
rustup-toolchain-file-toml = assertEq (fromRustupToolchainFile ./rust-toolchain-toml) (
nightly."2021-03-25".default.override {
extensions = [
"rustfmt"
"rustc-dev"
];
targets = [
"wasm32-unknown-unknown"
"aarch64-unknown-linux-gnu"
];
}
);
rustup-toolchain-file-legacy =
assertEq (fromRustupToolchainFile ./rust-toolchain-legacy)
nightly."2021-03-25".default;
rustup-toolchain-file-minimal = assertEq
(fromRustupToolchainFile ./rust-toolchain-minimal)
(nightly."2021-03-25".minimal.override {
extensions = [ "rustfmt" "rustc-dev" ];
rustup-toolchain-file-minimal = assertEq (fromRustupToolchainFile ./rust-toolchain-minimal) (
nightly."2021-03-25".minimal.override {
extensions = [
"rustfmt"
"rustc-dev"
];
targets = [ "aarch64-unknown-linux-gnu" ];
});
}
);
latest-nightly-default = rust-bin.selectLatestNightlyWith (toolchain: toolchain.default);
# Darwin specific tests.
} // optionalAttrs (system == "aarch64-darwin") {
url-forward = assertUrl
nightly."2022-02-02".rust-docs
}
// optionalAttrs (system == "aarch64-darwin") {
url-forward =
assertUrl nightly."2022-02-02".rust-docs
"https://static.rust-lang.org/dist/2022-02-02/rust-docs-nightly-x86_64-apple-darwin.tar.xz";
aarch64-darwin-use-x86-docs = rust-bin.stable."1.51.0".default.override {
targets = [ "x86_64-apple-darwin" ];