diff --git a/pkgs/development/interpreters/python/hooks/default.nix b/pkgs/development/interpreters/python/hooks/default.nix index 001e477b9185b..144cc9bb1853d 100644 --- a/pkgs/development/interpreters/python/hooks/default.nix +++ b/pkgs/development/interpreters/python/hooks/default.nix @@ -160,6 +160,20 @@ in { }; } ./setuptools-check-hook.sh) {}; + setuptoolsRustBuildHook = callPackage ({ makePythonHook, setuptools-rust, rust }: + makePythonHook { + name = "setuptools-rust-setup-hook"; + propagatedBuildInputs = [ setuptools-rust ]; + substitutions = { + pyLibDir = "${python}/lib/${python.libPrefix}"; + cargoBuildTarget = rust.toRustTargetSpec stdenv.hostPlatform; + cargoLinkerVar = lib.toUpper ( + builtins.replaceStrings ["-"] ["_"] ( + rust.toRustTarget stdenv.hostPlatform)); + targetLinker = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; + }; + } ./setuptools-rust-hook.sh) {}; + unittestCheckHook = callPackage ({ makePythonHook }: makePythonHook { name = "unittest-check-hook"; diff --git a/pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh b/pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh new file mode 100644 index 0000000000000..917c19ef9b31b --- /dev/null +++ b/pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh @@ -0,0 +1,18 @@ +echo "Sourcing setuptools-rust-hook" + +setuptoolsRustSetup() { + # This can work only if rustPlatform.cargoSetupHook is also included + if ! command -v cargoSetupPostPatchHook >/dev/null; then + echo "ERROR: setuptools-rust has to be used alongside with rustPlatform.cargoSetupHook!" + exit 1 + fi + + export PYO3_CROSS_LIB_DIR="@pyLibDir@" + export CARGO_BUILD_TARGET=@cargoBuildTarget@ + # TODO theoretically setting linker should not be required because it is + # already set in pkgs/build-support/rust/hooks/default.nix but build fails + # on missing linker without this. + export CARGO_TARGET_@cargoLinkerVar@_LINKER=@targetLinker@ +} + +preConfigureHooks+=(setuptoolsRustSetup) diff --git a/pkgs/development/python-modules/cryptography/default.nix b/pkgs/development/python-modules/cryptography/default.nix index 2ebcb9efffe2a..8346b4f4418d1 100644 --- a/pkgs/development/python-modules/cryptography/default.nix +++ b/pkgs/development/python-modules/cryptography/default.nix @@ -6,7 +6,7 @@ , rustPlatform , cargo , rustc -, setuptools-rust +, setuptoolsRustBuildHook , openssl , Security , isPyPy @@ -54,7 +54,7 @@ buildPythonPackage rec { nativeBuildInputs = [ rustPlatform.cargoSetupHook - setuptools-rust + setuptoolsRustBuildHook cargo rustc pkg-config