Merge pull request #145107 from Ericson2314/buildRustCrate-sysroot

build-support/rust: Fix sysroot for cross
This commit is contained in:
John Ericson 2021-11-24 18:44:13 -05:00 committed by GitHub
commit f721e0f849
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 95 additions and 46 deletions

View file

@ -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;

View file

@ -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"

View file

@ -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",
]
@ -21,9 +21,22 @@ dependencies = [
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"

View file

@ -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'),
},
},
},

View file

@ -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
'';
}

View file

@ -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"

View file

@ -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"
])}}
'';
}