diff options
| author | John Ericson <git@JohnEricson.me> | 2021-11-24 19:04:20 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-24 19:04:20 -0500 |
| commit | 91e6a9a6568f751bb10222a937507e7e151a035e (patch) | |
| tree | 29fbc767805afa5e7e386d675a12f36e4923d407 | |
| parent | Merge pull request #146640 from imlonghao/borgmatic/release-21.05 (diff) | |
| parent | build-support/rust/sysroot/src: Use `dont*` instead of phase list (diff) | |
| download | nixpkgs-91e6a9a6568f751bb10222a937507e7e151a035e.tar.gz | |
Merge pull request #147317 from NixOS/backport-145107-to-release-21.05
[Backport release-21.05] build-support/rust: Fix sysroot for cross
| -rw-r--r-- | pkgs/build-support/rust/build-rust-package/sysroot/default.nix | 13 | ||||
| -rwxr-xr-x | pkgs/build-support/rust/build-rust-package/sysroot/update-lockfile.sh | 21 | ||||
| -rw-r--r-- | pkgs/build-support/rust/sysroot/Cargo.lock (renamed from pkgs/build-support/rust/build-rust-package/sysroot/Cargo.lock) | 17 | ||||
| -rw-r--r-- | pkgs/build-support/rust/sysroot/cargo.py (renamed from pkgs/build-support/rust/build-rust-package/sysroot/cargo.py) | 16 | ||||
| -rw-r--r-- | pkgs/build-support/rust/sysroot/src.nix | 26 | ||||
| -rwxr-xr-x | pkgs/build-support/rust/sysroot/update-lockfile.sh | 27 | ||||
| -rw-r--r-- | pkgs/development/compilers/rust/rust-src.nix | 21 |
7 files changed, 95 insertions, 46 deletions
diff --git a/pkgs/build-support/rust/build-rust-package/sysroot/default.nix b/pkgs/build-support/rust/build-rust-package/sysroot/default.nix index 4db7cf0dc392..1e0b901105cd 100644 --- a/pkgs/build-support/rust/build-rust-package/sysroot/default.nix +++ b/pkgs/build-support/rust/build-rust-package/sysroot/default.nix @@ -3,17 +3,8 @@ { shortTarget, originalCargoToml, target, RUSTFLAGS }: let - cargoSrc = stdenv.mkDerivation { - name = "cargo-src"; - preferLocalBuild = true; - phases = [ "installPhase" ]; - installPhase = '' - RUSTC_SRC=${rustPlatform.rustcSrc.override { minimalContent = false; }} ORIG_CARGO=${originalCargoToml} \ - ${buildPackages.python3.withPackages (ps: with ps; [ toml ])}/bin/python3 ${./cargo.py} - mkdir -p $out - cp Cargo.toml $out/Cargo.toml - cp ${./Cargo.lock} $out/Cargo.lock - ''; + cargoSrc = import ../../sysroot/src.nix { + inherit stdenv rustPlatform buildPackages originalCargoToml; }; in rustPlatform.buildRustPackage { inherit target RUSTFLAGS; diff --git a/pkgs/build-support/rust/build-rust-package/sysroot/update-lockfile.sh b/pkgs/build-support/rust/build-rust-package/sysroot/update-lockfile.sh deleted file mode 100755 index 83d29832384f..000000000000 --- a/pkgs/build-support/rust/build-rust-package/sysroot/update-lockfile.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash -p python3 python3.pkgs.toml cargo - -set -e - -HERE=$(dirname "${BASH_SOURCE[0]}") -NIXPKGS_ROOT="$HERE/../../../.." - -# https://unix.stackexchange.com/a/84980/390173 -tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-lockfile') - -cd "$tempdir" -nix-build -E "with import (/. + \"${NIXPKGS_ROOT}\") {}; pkgs.rustPlatform.rustcSrc.override { minimalContent = false; }" -RUSTC_SRC="$(pwd)/result" python3 "$HERE/cargo.py" -RUSTC_BOOTSTRAP=1 cargo build || echo "Build failure is expected. All that's needed is the lockfile." - -cp Cargo.lock "$HERE" - -rm -rf "$tempdir" - - diff --git a/pkgs/build-support/rust/build-rust-package/sysroot/Cargo.lock b/pkgs/build-support/rust/sysroot/Cargo.lock index 61fcef61744e..6ec6da6ae6e2 100644 --- a/pkgs/build-support/rust/build-rust-package/sysroot/Cargo.lock +++ b/pkgs/build-support/rust/sysroot/Cargo.lock @@ -10,9 +10,9 @@ dependencies = [ [[package]] name = "compiler_builtins" -version = "0.1.36" +version = "0.1.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd0782e0a7da7598164153173e5a5d4d9b1da094473c98dce0ff91406112369" +checksum = "b6591c2442ee984e2b264638a8b5e7ae44fd47b32d28e3a08e2e9c3cdb0c2fb0" dependencies = [ "rustc-std-workspace-core", ] @@ -22,8 +22,21 @@ name = "core" version = "0.0.0" [[package]] +name = "nixpkgs-sysroot-stub-crate" +version = "0.0.0" +dependencies = [ + "alloc", + "compiler_builtins", + "core", +] + +[[package]] name = "rustc-std-workspace-core" version = "1.99.0" dependencies = [ "core", ] + +[[patch.unused]] +name = "rustc-std-workspace-alloc" +version = "1.99.0" diff --git a/pkgs/build-support/rust/build-rust-package/sysroot/cargo.py b/pkgs/build-support/rust/sysroot/cargo.py index 09f6fba6d1c8..9d970eff79e8 100644 --- a/pkgs/build-support/rust/build-rust-package/sysroot/cargo.py +++ b/pkgs/build-support/rust/sysroot/cargo.py @@ -6,7 +6,7 @@ orig_cargo = os.environ['ORIG_CARGO'] if 'ORIG_CARGO' in os.environ else None base = { 'package': { - 'name': 'alloc', + 'name': 'nixpkgs-sysroot-stub-crate', 'version': '0.0.0', 'authors': ['The Rust Project Developers'], 'edition': '2018', @@ -17,17 +17,19 @@ base = { 'features': ['rustc-dep-of-std', 'mem'], }, 'core': { - 'path': os.path.join(rust_src, 'libcore'), + 'path': os.path.join(rust_src, 'core'), + }, + 'alloc': { + 'path': os.path.join(rust_src, 'alloc'), }, - }, - 'lib': { - 'name': 'alloc', - 'path': os.path.join(rust_src, 'liballoc/lib.rs'), }, 'patch': { 'crates-io': { 'rustc-std-workspace-core': { - 'path': os.path.join(rust_src, 'tools/rustc-std-workspace-core'), + 'path': os.path.join(rust_src, 'rustc-std-workspace-core'), + }, + 'rustc-std-workspace-alloc': { + 'path': os.path.join(rust_src, 'rustc-std-workspace-alloc'), }, }, }, diff --git a/pkgs/build-support/rust/sysroot/src.nix b/pkgs/build-support/rust/sysroot/src.nix new file mode 100644 index 000000000000..3d11b62dd315 --- /dev/null +++ b/pkgs/build-support/rust/sysroot/src.nix @@ -0,0 +1,26 @@ +{ lib, stdenv, rustPlatform, buildPackages +, originalCargoToml ? null +}: + +stdenv.mkDerivation { + name = "cargo-src"; + preferLocalBuild = true; + + unpackPhase = "true"; + dontConfigure = true; + dontBuild = true; + + installPhase = '' + export RUSTC_SRC=${rustPlatform.rustLibSrc.override { }} + '' + + lib.optionalString (originalCargoToml != null) '' + export ORIG_CARGO=${originalCargoToml} + '' + + '' + ${buildPackages.python3.withPackages (ps: with ps; [ toml ])}/bin/python3 ${./cargo.py} + mkdir -p $out/src + touch $out/src/lib.rs + cp Cargo.toml $out/Cargo.toml + cp ${./Cargo.lock} $out/Cargo.lock + ''; +} diff --git a/pkgs/build-support/rust/sysroot/update-lockfile.sh b/pkgs/build-support/rust/sysroot/update-lockfile.sh new file mode 100755 index 000000000000..d0596d1e5a62 --- /dev/null +++ b/pkgs/build-support/rust/sysroot/update-lockfile.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p python3 python3.pkgs.toml cargo + +set -eu pipefile + +HERE=$(readlink -e $(dirname "${BASH_SOURCE[0]}")) +NIXPKGS_ROOT="$HERE/../../../.." + +# https://unix.stackexchange.com/a/84980/390173 +tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-lockfile') +cd "$tempdir" +mkdir -p src +touch src/lib.rs + +RUSTC_SRC=$(nix-build "${NIXPKGS_ROOT}" -A pkgs.rustPlatform.rustLibSrc --no-out-link) + +ln -s $RUSTC_SRC/{core,alloc} ./ + +export RUSTC_SRC +python3 "$HERE/cargo.py" + +export RUSTC_BOOTSTRAP=1 +cargo generate-lockfile + +cp Cargo.lock "$HERE" + +rm -rf "$tempdir" diff --git a/pkgs/development/compilers/rust/rust-src.nix b/pkgs/development/compilers/rust/rust-src.nix index 489795ecec47..4239e92b0363 100644 --- a/pkgs/development/compilers/rust/rust-src.nix +++ b/pkgs/development/compilers/rust/rust-src.nix @@ -1,4 +1,4 @@ -{ stdenv, rustc, minimalContent ? true }: +{ lib, stdenv, rustc, minimalContent ? true }: stdenv.mkDerivation { name = "rust-src"; @@ -6,9 +6,20 @@ stdenv.mkDerivation { phases = [ "unpackPhase" "installPhase" ]; installPhase = '' mv src $out - rm -rf $out/{${if minimalContent - then "ci,doc,etc,grammar,llvm-project,llvm-emscripten,rtstartup,rustllvm,test,tools,vendor,stdarch" - else "ci,doc,etc,grammar,llvm-project,llvm-emscripten,rtstartup,rustllvm,test,vendor" - }} + rm -rf $out/{${lib.concatStringsSep "," ([ + "ci" + "doc" + "etc" + "grammar" + "llvm-project" + "llvm-emscripten" + "rtstartup" + "rustllvm" + "test" + "vendor" + ] ++ lib.optionals minimalContent [ + "tools" + "stdarch" + ])}} ''; } |
