build-support/rust: Split out sysroot src derivation

Hoping to make it usable for `buildRustCrate` too.
This commit is contained in:
John Ericson 2021-10-07 22:20:10 +00:00
parent 2c7f62379f
commit cbd00bab80
5 changed files with 23 additions and 11 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

@ -0,0 +1,21 @@
{ lib, stdenv, rustPlatform, buildPackages
, originalCargoToml ? null
}:
stdenv.mkDerivation {
name = "cargo-src";
preferLocalBuild = true;
phases = [ "installPhase" ];
installPhase = ''
export RUSTC_SRC=${rustPlatform.rustcSrc.override { minimalContent = false; }}
''
+ lib.optionalString (originalCargoToml != null) ''
export 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
'';
}