Skip to content
Closed
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
15 changes: 13 additions & 2 deletions pkgs/development/python-modules/cryptography/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
, stdenv
, callPackage
, buildPythonPackage
, python
, fetchPypi
, rustPlatform
, rust
, rustc
, cargo
, setuptools-rust
, openssl
, Security
Expand Down Expand Up @@ -47,9 +51,11 @@ buildPythonPackage rec {
nativeBuildInputs = lib.optionals (!isPyPy) [
cffi
] ++ [
rustPlatform.cargoSetupHook
setuptools-rust
] ++ (with rustPlatform; [ rust.cargo rust.rustc ]);
rustPlatform.cargoSetupHook
rustc
cargo
Comment on lines +55 to +57
Copy link
Member

Choose a reason for hiding this comment

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

Can we assert/check in a setup hook this somewhere to make sure this is correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or should this be propagated inputs for setuptools-rust?

];

buildInputs = [ openssl ]
++ lib.optionals stdenv.isDarwin [ Security libiconv ];
Expand All @@ -69,6 +75,11 @@ buildPythonPackage rec {
pytz
];

CARGO_BUILD_TARGET = "${rust.toRustTargetSpec stdenv.hostPlatform}";
PYO3_CROSS_LIB_DIR = "${python}/lib/${python.libPrefix}";
"CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget stdenv.hostPlatform))}_LINKER" =
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
Comment on lines +78 to +81
Copy link
Member

Choose a reason for hiding this comment

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

i recommend adding a setup hook to setuptools-rust that does these

  CARGO_BUILD_TARGET_TARGET = "${rust.toRustTargetSpec targetPackages.stdenv.hostPlatform}";
  PYO3_CROSS_LIB_DIR_TARGET = "${targetPackages.python}/lib/${targetPackages.python.libPrefix}";
  CARGO_LINKER_VAR = "CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget targetPackages.stdenv.hostPlatform))}_LINKER"
	TARGET_LINKER = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc";

add the above to the setuptools-rust and a setup hook that exports them

export CARGO_BUILD_TARGET_TARGET=@CARGO_BUILD_TARGET@
export PYO3_CROSS_LIB_DIR_TARGET=@PYO3_CROSS_LIB_DIR@
export @CARGO_LINKER_VAR@=@TARGET_LINKER@

Comment on lines +78 to +81
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CARGO_BUILD_TARGET = "${rust.toRustTargetSpec stdenv.hostPlatform}";
PYO3_CROSS_LIB_DIR = "${python}/lib/${python.libPrefix}";
"CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget stdenv.hostPlatform))}_LINKER" =
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
CARGO_BUILD_TARGET = rust.toRustTargetSpec stdenv.hostPlatform;
PYO3_CROSS_LIB_DIR = "${python}/lib/${python.libPrefix}";
"CARGO_TARGET_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] (rust.toRustTarget stdenv.hostPlatform))}_LINKER" =
"${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";

Are those generic variables we want to set?
If so we should move them to a setup-hook like maturin or setuptools-rust

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is the question... I took those variables from here https://github.com/PyO3/setuptools-rust/blob/main/.github/workflows/ci.yml#L270 and here PyO3/setuptools-rust#294 (comment). The CARGO_BUILD_TARGET and PYO3_CROSS_LIB_DIR seem reasonable, but I am not sure about CARGO_TARGET_*. It is kind of weird to have to specify the linker. No other package except of crosvm has to do this (that is where I took it from anyway).

Copy link
Member

Choose a reason for hiding this comment

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

It is kind of weird to have to specify the linker.

Especially weird given that we already do this:

cargoConfig = ''
[host]
"linker" = "${ccForBuild}"
"rustflags" = [ "-C", "target-feature=${if stdenv.buildPlatform.isStatic then "+" else "-"}crt-static" ]
[target."${shortTarget}"]
"linker" = "${ccForHost}"
"rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ]
[unstable]
host-config = true
target-applies-to-host = true
'';


pytestFlagsArray = [
"--disable-pytest-warnings"
];
Expand Down