1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-18 19:51:17 +00:00

Merge pull request #212795 from Cynerd/setuptools-rust-hook

Setuptools rust hook for cross compilation
This commit is contained in:
Adam Joseph 2023-07-28 06:53:09 +00:00 committed by GitHub
commit 52d3944057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 2 deletions

View file

@ -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";

View file

@ -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)

View file

@ -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