rustPlatform.maturinBuildHook: init

This build hook can be used to build Python packages using maturin.
This commit is contained in:
Daniël de Kok 2021-02-11 19:17:06 +01:00
parent 7876d1c252
commit 160cf87086
3 changed files with 51 additions and 1 deletions

View File

@ -4,6 +4,7 @@
, diffutils
, lib
, makeSetupHook
, maturin
, rust
, stdenv
, target ? rust.toRustTargetSpec stdenv.hostPlatform
@ -62,4 +63,14 @@ in {
'';
};
} ./cargo-setup-hook.sh) {};
maturinBuildHook = callPackage ({ }:
makeSetupHook {
name = "maturin-build-hook.sh";
deps = [ cargo maturin ];
substitutions = {
inherit ccForBuild ccForHost cxxForBuild cxxForHost
rustBuildPlatform rustTargetPlatform rustTargetPlatformSpec;
};
} ./maturin-build-hook.sh) {};
}

View File

@ -0,0 +1,39 @@
maturinBuildHook() {
echo "Executing maturinBuildHook"
runHook preBuild
if [ ! -z "${buildAndTestSubdir-}" ]; then
pushd "${buildAndTestSubdir}"
fi
(
set -x
env \
"CC_@rustBuildPlatform@=@ccForBuild@" \
"CXX_@rustBuildPlatform@=@cxxForBuild@" \
"CC_@rustTargetPlatform@=@ccForHost@" \
"CXX_@rustTargetPlatform@=@cxxForHost@" \
maturin build \
--cargo-extra-args="-j $NIX_BUILD_CORES --frozen" \
--target @rustTargetPlatformSpec@ \
--manylinux off \
--strip \
--release \
${maturinBuildFlags-}
)
runHook postBuild
if [ ! -z "${buildAndTestSubdir-}" ]; then
popd
fi
# Move the wheel to dist/ so that regular Python tooling can find it.
mkdir -p dist
mv target/wheels/*.whl dist/
echo "Finished maturinBuildHook"
}
buildPhase=maturinBuildHook

View File

@ -26,5 +26,5 @@ rec {
# Hooks
inherit (callPackage ../../../build-support/rust/hooks {
inherit cargo;
}) cargoBuildHook cargoSetupHook;
}) cargoBuildHook cargoSetupHook maturinBuildHook;
}