Update script as rust-src layout has changed

Use stub lib so `core` and `alloc` are handled symmetrically.
This commit is contained in:
John Ericson 2021-11-08 02:05:25 +00:00
parent cbd00bab80
commit c9c3de0131
4 changed files with 41 additions and 19 deletions

View file

@ -10,9 +10,9 @@ dependencies = [
[[package]] [[package]]
name = "compiler_builtins" name = "compiler_builtins"
version = "0.1.36" version = "0.1.52"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cd0782e0a7da7598164153173e5a5d4d9b1da094473c98dce0ff91406112369" checksum = "b6591c2442ee984e2b264638a8b5e7ae44fd47b32d28e3a08e2e9c3cdb0c2fb0"
dependencies = [ dependencies = [
"rustc-std-workspace-core", "rustc-std-workspace-core",
] ]
@ -21,9 +21,22 @@ dependencies = [
name = "core" name = "core"
version = "0.0.0" version = "0.0.0"
[[package]]
name = "nixpkgs-sysroot-stub-crate"
version = "0.0.0"
dependencies = [
"alloc",
"compiler_builtins",
"core",
]
[[package]] [[package]]
name = "rustc-std-workspace-core" name = "rustc-std-workspace-core"
version = "1.99.0" version = "1.99.0"
dependencies = [ dependencies = [
"core", "core",
] ]
[[patch.unused]]
name = "rustc-std-workspace-alloc"
version = "1.99.0"

View file

@ -6,7 +6,7 @@ orig_cargo = os.environ['ORIG_CARGO'] if 'ORIG_CARGO' in os.environ else None
base = { base = {
'package': { 'package': {
'name': 'alloc', 'name': 'nixpkgs-sysroot-stub-crate',
'version': '0.0.0', 'version': '0.0.0',
'authors': ['The Rust Project Developers'], 'authors': ['The Rust Project Developers'],
'edition': '2018', 'edition': '2018',
@ -17,17 +17,19 @@ base = {
'features': ['rustc-dep-of-std', 'mem'], 'features': ['rustc-dep-of-std', 'mem'],
}, },
'core': { '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': { 'patch': {
'crates-io': { 'crates-io': {
'rustc-std-workspace-core': { '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'),
}, },
}, },
}, },

View file

@ -7,14 +7,15 @@ stdenv.mkDerivation {
preferLocalBuild = true; preferLocalBuild = true;
phases = [ "installPhase" ]; phases = [ "installPhase" ];
installPhase = '' installPhase = ''
export RUSTC_SRC=${rustPlatform.rustcSrc.override { minimalContent = false; }} export RUSTC_SRC=${rustPlatform.rustLibSrc.override { }}
'' ''
+ lib.optionalString (originalCargoToml != null) '' + lib.optionalString (originalCargoToml != null) ''
export ORIG_CARGO=${originalCargoToml} export ORIG_CARGO=${originalCargoToml}
'' ''
+ '' + ''
${buildPackages.python3.withPackages (ps: with ps; [ toml ])}/bin/python3 ${./cargo.py} ${buildPackages.python3.withPackages (ps: with ps; [ toml ])}/bin/python3 ${./cargo.py}
mkdir -p $out mkdir -p $out/src
touch $out/src/lib.rs
cp Cargo.toml $out/Cargo.toml cp Cargo.toml $out/Cargo.toml
cp ${./Cargo.lock} $out/Cargo.lock cp ${./Cargo.lock} $out/Cargo.lock
''; '';

View file

@ -1,21 +1,27 @@
#!/usr/bin/env nix-shell #!/usr/bin/env nix-shell
#!nix-shell -i bash -p python3 python3.pkgs.toml cargo #!nix-shell -i bash -p python3 python3.pkgs.toml cargo
set -e set -eu pipefile
HERE=$(dirname "${BASH_SOURCE[0]}") HERE=$(readlink -e $(dirname "${BASH_SOURCE[0]}"))
NIXPKGS_ROOT="$HERE/../../../.." NIXPKGS_ROOT="$HERE/../../../.."
# https://unix.stackexchange.com/a/84980/390173 # https://unix.stackexchange.com/a/84980/390173
tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-lockfile') tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'update-lockfile')
cd "$tempdir" cd "$tempdir"
nix-build -E "with import (/. + \"${NIXPKGS_ROOT}\") {}; pkgs.rustPlatform.rustcSrc.override { minimalContent = false; }" mkdir -p src
RUSTC_SRC="$(pwd)/result" python3 "$HERE/cargo.py" touch src/lib.rs
RUSTC_BOOTSTRAP=1 cargo build || echo "Build failure is expected. All that's needed is the lockfile."
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" cp Cargo.lock "$HERE"
rm -rf "$tempdir" rm -rf "$tempdir"