Update script as rust-src layout has changed

Use stub lib so `core` and `alloc` are handled symmetrically.

+41 -19
+15 -2
pkgs/build-support/rust/sysroot/Cargo.lock
··· 10 10 11 11 [[package]] 12 12 name = "compiler_builtins" 13 - version = "0.1.36" 13 + version = "0.1.52" 14 14 source = "registry+https://github.com/rust-lang/crates.io-index" 15 - checksum = "7cd0782e0a7da7598164153173e5a5d4d9b1da094473c98dce0ff91406112369" 15 + checksum = "b6591c2442ee984e2b264638a8b5e7ae44fd47b32d28e3a08e2e9c3cdb0c2fb0" 16 16 dependencies = [ 17 17 "rustc-std-workspace-core", 18 18 ] ··· 22 22 version = "0.0.0" 23 23 24 24 [[package]] 25 + name = "nixpkgs-sysroot-stub-crate" 26 + version = "0.0.0" 27 + dependencies = [ 28 + "alloc", 29 + "compiler_builtins", 30 + "core", 31 + ] 32 + 33 + [[package]] 25 34 name = "rustc-std-workspace-core" 26 35 version = "1.99.0" 27 36 dependencies = [ 28 37 "core", 29 38 ] 39 + 40 + [[patch.unused]] 41 + name = "rustc-std-workspace-alloc" 42 + version = "1.99.0"
+9 -7
pkgs/build-support/rust/sysroot/cargo.py
··· 6 6 7 7 base = { 8 8 'package': { 9 - 'name': 'alloc', 9 + 'name': 'nixpkgs-sysroot-stub-crate', 10 10 'version': '0.0.0', 11 11 'authors': ['The Rust Project Developers'], 12 12 'edition': '2018', ··· 17 17 'features': ['rustc-dep-of-std', 'mem'], 18 18 }, 19 19 'core': { 20 - 'path': os.path.join(rust_src, 'libcore'), 20 + 'path': os.path.join(rust_src, 'core'), 21 21 }, 22 - }, 23 - 'lib': { 24 - 'name': 'alloc', 25 - 'path': os.path.join(rust_src, 'liballoc/lib.rs'), 22 + 'alloc': { 23 + 'path': os.path.join(rust_src, 'alloc'), 24 + }, 26 25 }, 27 26 'patch': { 28 27 'crates-io': { 29 28 'rustc-std-workspace-core': { 30 - 'path': os.path.join(rust_src, 'tools/rustc-std-workspace-core'), 29 + 'path': os.path.join(rust_src, 'rustc-std-workspace-core'), 30 + }, 31 + 'rustc-std-workspace-alloc': { 32 + 'path': os.path.join(rust_src, 'rustc-std-workspace-alloc'), 31 33 }, 32 34 }, 33 35 },
+3 -2
pkgs/build-support/rust/sysroot/src.nix
··· 7 7 preferLocalBuild = true; 8 8 phases = [ "installPhase" ]; 9 9 installPhase = '' 10 - export RUSTC_SRC=${rustPlatform.rustcSrc.override { minimalContent = false; }} 10 + export RUSTC_SRC=${rustPlatform.rustLibSrc.override { }} 11 11 '' 12 12 + lib.optionalString (originalCargoToml != null) '' 13 13 export ORIG_CARGO=${originalCargoToml} 14 14 '' 15 15 + '' 16 16 ${buildPackages.python3.withPackages (ps: with ps; [ toml ])}/bin/python3 ${./cargo.py} 17 - mkdir -p $out 17 + mkdir -p $out/src 18 + touch $out/src/lib.rs 18 19 cp Cargo.toml $out/Cargo.toml 19 20 cp ${./Cargo.lock} $out/Cargo.lock 20 21 '';
+14 -8
pkgs/build-support/rust/sysroot/update-lockfile.sh
··· 1 1 #!/usr/bin/env nix-shell 2 2 #!nix-shell -i bash -p python3 python3.pkgs.toml cargo 3 3 4 - set -e 4 + set -eu pipefile 5 5 6 - HERE=$(dirname "${BASH_SOURCE[0]}") 6 + HERE=$(readlink -e $(dirname "${BASH_SOURCE[0]}")) 7 7 NIXPKGS_ROOT="$HERE/../../../.." 8 8 9 9 # https://unix.stackexchange.com/a/84980/390173 10 10 tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-lockfile') 11 - 12 11 cd "$tempdir" 13 - nix-build -E "with import (/. + \"${NIXPKGS_ROOT}\") {}; pkgs.rustPlatform.rustcSrc.override { minimalContent = false; }" 14 - RUSTC_SRC="$(pwd)/result" python3 "$HERE/cargo.py" 15 - RUSTC_BOOTSTRAP=1 cargo build || echo "Build failure is expected. All that's needed is the lockfile." 12 + mkdir -p src 13 + touch src/lib.rs 16 14 17 - cp Cargo.lock "$HERE" 15 + RUSTC_SRC=$(nix-build "${NIXPKGS_ROOT}" -A pkgs.rustPlatform.rustLibSrc --no-out-link) 16 + 17 + ln -s $RUSTC_SRC/{core,alloc} ./ 18 + 19 + export RUSTC_SRC 20 + python3 "$HERE/cargo.py" 18 21 19 - rm -rf "$tempdir" 22 + export RUSTC_BOOTSTRAP=1 23 + cargo generate-lockfile 20 24 25 + cp Cargo.lock "$HERE" 21 26 27 + rm -rf "$tempdir"