From 160cf87086694f6d2007e7d427a6dee089266e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Thu, 11 Feb 2021 19:17:06 +0100 Subject: [PATCH] rustPlatform.maturinBuildHook: init This build hook can be used to build Python packages using maturin. --- pkgs/build-support/rust/hooks/default.nix | 11 ++++++ .../rust/hooks/maturin-build-hook.sh | 39 +++++++++++++++++++ .../compilers/rust/make-rust-platform.nix | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 pkgs/build-support/rust/hooks/maturin-build-hook.sh diff --git a/pkgs/build-support/rust/hooks/default.nix b/pkgs/build-support/rust/hooks/default.nix index e33d5813a13..d4b2cc15605 100644 --- a/pkgs/build-support/rust/hooks/default.nix +++ b/pkgs/build-support/rust/hooks/default.nix @@ -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) {}; } diff --git a/pkgs/build-support/rust/hooks/maturin-build-hook.sh b/pkgs/build-support/rust/hooks/maturin-build-hook.sh new file mode 100644 index 00000000000..7e2599d9224 --- /dev/null +++ b/pkgs/build-support/rust/hooks/maturin-build-hook.sh @@ -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 diff --git a/pkgs/development/compilers/rust/make-rust-platform.nix b/pkgs/development/compilers/rust/make-rust-platform.nix index 728f459d887..1ea97b48c44 100644 --- a/pkgs/development/compilers/rust/make-rust-platform.nix +++ b/pkgs/development/compilers/rust/make-rust-platform.nix @@ -26,5 +26,5 @@ rec { # Hooks inherit (callPackage ../../../build-support/rust/hooks { inherit cargo; - }) cargoBuildHook cargoSetupHook; + }) cargoBuildHook cargoSetupHook maturinBuildHook; }