Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pkgs/development/interpreters/python/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
18 changes: 18 additions & 0 deletions pkgs/development/interpreters/python/hooks/setuptools-rust-hook.sh
Original file line number Diff line number Diff line change
@@ -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@
Comment on lines +12 to +15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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@

If you need this, it means splicing isn't working right. That's usually caused by referencing things via rustPlatform. Don't do that. Use my next suggestion instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how not to use rustPlatform. How can I access the cargoSetupHook unless I am using buildRustPackage or through rustPlatform? I can't use buildRustPackage because this is a Python hook primarily.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand how not to use rustPlatform.

Let me be more explicit:

If you need this, it means splicing isn't working right. That's usually caused by referencing things rustc and cargo via rustPlatform. Don't do that. Use my next suggestion instead.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that you have applied this suggestion.

}

preConfigureHooks+=(setuptoolsRustSetup)
4 changes: 2 additions & 2 deletions pkgs/development/python-modules/cryptography/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
, rustPlatform
, cargo
, rustc
, setuptools-rust
, setuptoolsRustBuildHook
, openssl
, Security
, isPyPy
Expand Down Expand Up @@ -54,7 +54,7 @@ buildPythonPackage rec {

nativeBuildInputs = [
rustPlatform.cargoSetupHook
setuptools-rust
setuptoolsRustBuildHook
cargo
rustc
pkg-config
Expand Down