Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypthography cross build produces host's rust library #205807

Closed
Cynerd opened this issue Dec 12, 2022 · 5 comments
Closed

crypthography cross build produces host's rust library #205807

Cynerd opened this issue Dec 12, 2022 · 5 comments
Labels
0.kind: bug Something is broken 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: rust

Comments

@Cynerd
Copy link
Contributor

Cynerd commented Dec 12, 2022

Describe the bug

By attempting to cross-compile python cryptography I get build but rust bindings are build for host architecture.

Steps To Reproduce

Steps to reproduce the behavior:

  1. nix build .#legacyPackages.x86_64-linux.pkgsCross.aarch64-multiplatform.python3Packages.cryptography
  2. file result/lib/python3.10/site-packages/cryptography/hazmat/bindings/_rust.abi3.so gives x86-64
  3. file result/lib/python3.10/site-packages/cryptography/hazmat/bindings/_openssl.abi3.so gives aarch64

Expected behavior

The rust should be cross compiled as well.

Additional context

Add any other context about the problem here.

I tried to look into it and discovered this PyO3/setuptools-rust#294 but nothing more.

Notify maintainers

@SuperSandro2000

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.0.10, NixOS, 23.05 (Stoat), 23.05.20221209.9e4a15b`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.12.0`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
@Cynerd Cynerd added the 0.kind: bug Something is broken label Dec 12, 2022
@SuperSandro2000
Copy link
Member

FYI @Artturin didn't you work on python cross or am I mistaken your for someone else?

@Mindavi Mindavi added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Dec 12, 2022
@Artturin
Copy link
Member

Artturin commented Dec 12, 2022

FYI @Artturin didn't you work on python cross or am I mistaken your for someone else?

yeah i did but this is unrelated to python

python3.10-cryptography> error[E0463]: can't find crate for `core`
python3.10-cryptography>   |
python3.10-cryptography>   = note: the `aarch64-unknown-linux-gnu` target may not be installed
python3.10-cryptography>   = help: consider downloading the target with `rustup target add aarch64-unknown-linux-gnu`
python3.10-cryptography> error[E0463]: can't find crate for `compiler_builtins`
python3.10-cryptography> error[E0463]: can't find crate for `core`
python3.10-cryptography>    --> /build/cryptography-38.0.3-vendor.tar.gz/scopeguard/src/lib.rs:192:1
python3.10-cryptography>     |
python3.10-cryptography> 192 | extern crate core as std;
python3.10-cryptography>     | ^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
python3.10-cryptography>     |
python3.10-cryptography>     = note: the `aarch64-unknown-linux-gnu` target may not be installed
python3.10-cryptography>     = help: consider downloading the target with `rustup target add aarch64-unknown-linux-gnu`
...
diff --git a/pkgs/development/python-modules/cryptography/default.nix b/pkgs/development/python-modules/cryptography/default.nix
index 0bbc30cd23c..828e20d7982 100644
--- a/pkgs/development/python-modules/cryptography/default.nix
+++ b/pkgs/development/python-modules/cryptography/default.nix
@@ -4,6 +4,7 @@
 , buildPythonPackage
 , fetchPypi
 , rustPlatform
+, rust
 , setuptools-rust
 , openssl
 , Security
@@ -49,7 +50,7 @@ buildPythonPackage rec {
   ] ++ [
     rustPlatform.cargoSetupHook
     setuptools-rust
-  ] ++ (with rustPlatform; [ rust.cargo rust.rustc ]);
+  ] ++ (with rustPlatform.rust; [ cargo rustc ]);
 
   buildInputs = [ openssl ]
     ++ lib.optionals stdenv.isDarwin [ Security libiconv ];
@@ -69,6 +70,11 @@ buildPythonPackage rec {
     pytz
   ];
 
+  CARGO_BUILD_TARGET = "${rust.toRustTargetSpec stdenv.hostPlatform}";
+
+  PKG_CONFIG_ALLOW_CROSS =
+    if stdenv.buildPlatform != stdenv.hostPlatform then 1 else 0;
+
   pytestFlagsArray = [
     "--disable-pytest-warnings"
   ];

@Cynerd
Copy link
Contributor Author

Cynerd commented Dec 13, 2022

This seems to be something generic for all python packages with rust extension. I also tried other packages that use setultools-rust, and all I tried were built for the host platform, not for the target.

Probably somebody skilled with Cargo should look into it.

@Cynerd
Copy link
Contributor Author

Cynerd commented Dec 30, 2022

I might have gotten a little bit further...

diff --git a/pkgs/development/python-modules/cryptography/default.nix b/pkgs/development/python-modules/cryptography/default.nix
index d5e4af33f60..560b8861fdc 100644
--- a/pkgs/development/python-modules/cryptography/default.nix
+++ b/pkgs/development/python-modules/cryptography/default.nix
@@ -2,8 +2,12 @@
 , stdenv
 , callPackage
 , buildPythonPackage
+, python
 , fetchPypi
 , rustPlatform
+, rust
+, rustc
+, cargo
 , setuptools-rust
 , openssl
 , Security
@@ -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
+  ];
 
   buildInputs = [ openssl ]
     ++ lib.optionals stdenv.isDarwin [ Security libiconv ];
@@ -69,6 +75,9 @@ buildPythonPackage rec {
     pytz
   ];
 
+  CARGO_BUILD_TARGET = "${rust.toRustTargetSpec stdenv.hostPlatform}";
+  PYO3_CROSS_LIB_DIR = "${python}/lib/${python.libPrefix}";
+
   pytestFlagsArray = [
     "--disable-pytest-warnings"
   ];

But still, it fails to build when cross-compiling. For some reason, it can't find linker.

@Cynerd
Copy link
Contributor Author

Cynerd commented Dec 30, 2022

It seems that I might have crack it. The pull request is here #208401.

@Mindavi Mindavi changed the title crypthography cross build procudes host's rust library crypthography cross build produces host's rust library Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: rust
Projects
None yet
Development

No branches or pull requests

4 participants