@ -3,6 +3,7 @@
, buildPackages
, cacert
, cargo
, cargoBuildHook
, cargoSetupHook
, fetchCargoTarball
, runCommandNoCC
@ -37,7 +38,6 @@
, cargoBuildFlags ? [ ]
, buildType ? " r e l e a s e "
, meta ? { }
, target ? rust . toRustTargetSpec stdenv . hostPlatform
, cargoVendorDir ? null
, checkType ? buildType
, depsExtraArgs ? { }
@ -71,6 +71,7 @@ let
# against the src fixed-output derivation to check consistency.
validateCargoDeps = ! ( cargoHash == " " && cargoSha256 == " " ) ;
target = rust . toRustTargetSpec stdenv . hostPlatform ;
targetIsJSON = lib . hasSuffix " . j s o n " target ;
useSysroot = targetIsJSON && ! __internal_dontAddSysroot ;
@ -86,10 +87,6 @@ let
originalCargoToml = src + /Cargo.toml ; # profile info is later extracted
} ;
ccForBuild = " ${ buildPackages . stdenv . cc } / b i n / ${ buildPackages . stdenv . cc . targetPrefix } c c " ;
cxxForBuild = " ${ buildPackages . stdenv . cc } / b i n / ${ buildPackages . stdenv . cc . targetPrefix } c + + " ;
ccForHost = " ${ stdenv . cc } / b i n / ${ stdenv . cc . targetPrefix } c c " ;
cxxForHost = " ${ stdenv . cc } / b i n / ${ stdenv . cc . targetPrefix } c + + " ;
releaseDir = " t a r g e t / ${ shortTarget } / ${ buildType } " ;
tmpDir = " ${ releaseDir } - t m p " ;
@ -102,11 +99,17 @@ assert useSysroot -> !(args.doCheck or true);
stdenv . mkDerivation ( ( removeAttrs args [ " d e p s E x t r a A r g s " ] ) // lib . optionalAttrs useSysroot {
RUSTFLAGS = " - - s y s r o o t ${ sysroot } " + ( args . RUSTFLAGS or " " ) ;
} // {
inherit cargoDeps ;
inherit buildAndTestSubdir cargoDeps releaseDir tmpDir ;
cargoBuildFlags = lib . concatStringsSep " " cargoBuildFlags ;
cargoBuildType = " - - ${ buildType } " ;
patchRegistryDeps = ./patch-registry-deps ;
nativeBuildInputs = nativeBuildInputs ++ [ cacert git cargo cargoSetupHook rustc ] ;
nativeBuildInputs = nativeBuildInputs ++
[ cacert git cargo cargoBuildHook cargoSetupHook rustc ] ;
buildInputs = buildInputs ++ lib . optional stdenv . hostPlatform . isMinGW windows . pthreads ;
patches = cargoPatches ++ patches ;
@ -125,38 +128,6 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs u
runHook postConfigure
'' ;
buildPhase = with builtins ; args . buildPhase or ''
$ { lib . optionalString ( buildAndTestSubdir != null ) " p u s h d ${ buildAndTestSubdir } " }
runHook preBuild
(
set - x
env \
" C C _ ${ rust . toRustTarget stdenv . buildPlatform } " = " ${ ccForBuild } " \
" C X X _ ${ rust . toRustTarget stdenv . buildPlatform } " = " ${ cxxForBuild } " \
" C C _ ${ rust . toRustTarget stdenv . hostPlatform } " = " ${ ccForHost } " \
" C X X _ ${ rust . toRustTarget stdenv . hostPlatform } " = " ${ cxxForHost } " \
cargo build - j $ NIX_BUILD_CORES \
$ { lib . optionalString ( buildType == " r e l e a s e " ) " - - r e l e a s e " } \
- - target $ { target } \
- - frozen $ { concatStringsSep " " cargoBuildFlags }
)
runHook postBuild
$ { lib . optionalString ( buildAndTestSubdir != null ) " p o p d " }
# This needs to be done after postBuild: packages like `cargo` do a pushd/popd in
# the pre/postBuild-hooks that need to be taken into account before gathering
# all binaries to install.
mkdir - p $ tmpDir
cp - r $ releaseDir /* $ t m p D i r /
bins = $ ( find $ tmpDir \
- maxdepth 1 \
- type f \
- executable ! \ ( - regex " . * \. \( s o . [ 0 - 9 . ] + \| s o \| a \| d y l i b \) " \ ) )
'' ;
checkPhase = args . checkPhase or ( let
argstr = " ${ lib . optionalString ( checkType == " r e l e a s e " ) " - - r e l e a s e " } - - t a r g e t ${ target } - - f r o z e n " ;
threads = if cargoParallelTestThreads then " $ N I X _ B U I L D _ C O R E S " else " 1 " ;
@ -173,11 +144,19 @@ stdenv.mkDerivation ((removeAttrs args ["depsExtraArgs"]) // lib.optionalAttrs u
strictDeps = true ;
inherit releaseDir tmpDir ;
installPhase = args . installPhase or ''
runHook preInstall
# This needs to be done after postBuild: packages like `cargo` do a pushd/popd in
# the pre/postBuild-hooks that need to be taken into account before gathering
# all binaries to install.
mkdir - p $ tmpDir
cp - r $ releaseDir /* $ t m p D i r /
bins = $ ( find $ tmpDir \
- maxdepth 1 \
- type f \
- executable ! \ ( - regex " . * \. \( s o . [ 0 - 9 . ] + \| s o \| a \| d y l i b \) " \ ) )
# rename the output dir to a architecture independent one
mapfile - t targets < < ( find " $ N I X _ B U I L D _ T O P " - type d | grep ' $ { tmpDir } $ ' )
for target in " ' ' ${ targets [ @ ] } " ; do