mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-25 16:33:15 +00:00
Merge pull request #145107 from Ericson2314/buildRustCrate-sysroot
build-support/rust: Fix sysroot for cross
This commit is contained in:
commit
f721e0f849
@ -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;
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
@ -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'),
|
||||
},
|
||||
},
|
||||
},
|
26
pkgs/build-support/rust/sysroot/src.nix
Normal file
26
pkgs/build-support/rust/sysroot/src.nix
Normal 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
|
||||
'';
|
||||
}
|
27
pkgs/build-support/rust/sysroot/update-lockfile.sh
Executable file
27
pkgs/build-support/rust/sysroot/update-lockfile.sh
Executable 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"
|
@ -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"
|
||||
])}}
|
||||
'';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user