about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh')
-rw-r--r--nixpkgs/pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh b/nixpkgs/pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh
new file mode 100644
index 000000000000..917c19ef9b31
--- /dev/null
+++ b/nixpkgs/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)