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

Cryptography 42 and rust #1261

Merged
merged 10 commits into from
Oct 17, 2024
Merged

Conversation

emanuele-f
Copy link
Contributor

@emanuele-f emanuele-f commented Oct 9, 2024

This adds support for building PyO3 modules like cryptography which depend on pyo3 >= 0.16.4.
Building rust modules requires installing the rust compiler android targets as follows:

# install the stable rust version
# Note cryptography 42 requires Rust >= 1.63.0
curl https://sh.rustup.rs -sSf | sh -s -- -y

# add the android targets for cross compilation
rustup target add aarch64-linux-android
rustup target add arm-linux-androideabi
rustup target add i686-linux-android
rustup target add x86_64-linux-android

Compared to #657, it's now possible to compile the cryptography module without issues because they migrated to PyO3 0.20, which removes the need to rebuild python, as sysconfig modules are not needed.

Moreover, since chaquopy updated the ndk to 26, this fixes ld: error: unable to find library -lunwind in recent Rust versions (see rust-lang/rust#103673), removing the constrain to use old Rust versions like 1.60; it's now possible to just use the latest stable Rust version. For example, it's now possible to compile the latest mitmproxy_rs module which requires a recent Rust version (see https://github.com/emanuele-f/chaquopy/tree/mitmproxy-11/server/pypi/packages/mitmproxy-rs); a separate PR will be provided to include this module in the supported packages.

Ps. double check if 4461dda breaks anything, as I can see that #1141 is still open even if the issue was identified.

This allows compiling Rust modules depending on pyo3 >= 0.16.4,
provided that module specifies a abi3-py* compatibility feature
and that the Rust compiler and toolchains are installed in the
build machine
They include modules which are locate into the cargo home
and libs located under the rustup toolchains dir, which
are outside of the source directory of valid_dirs
setuptools_rust/build.py", line 470, in get_dylib_ext_path
host_arch = host_platform.rsplit("-", 1)[1]
IndexError: list index out of range

Closes chaquo#1141
Cryptography 42.0.8 can now be built provided that the Rust
compiler and toolchains are installed into the build machine.

Note: legacy ciphers are disabled to prevent load-time crash
as if the CRYPTOGRAPHY_OPENSSL_NO_LEGACY environment variable
was set.
https://cryptography.io/en/latest/openssl/#legacy-provider-in-openssl-3-x

Closes chaquo#657
@mhsmith
Copy link
Member

mhsmith commented Oct 9, 2024

Thanks very much, I'll look at this as soon as I can.

@Michu44
Copy link

Michu44 commented Oct 10, 2024

@emanuele-f thank you so much for your contributions!
I have been trying to build cryptography 43 for the past 2 days, and still not much luck.

I've seen your email around here somewhere... any chance I can shoot you a direct message or Email somewhere? I could really use your help and we are happy to pay you if you could help us solve our current issues.

Edit:
Actually, you can find my contact info in my profile, can you pls. shoot me an email?

@emanuele-f
Copy link
Contributor Author

emanuele-f commented Oct 10, 2024

Hi @Michu44 , which python version are you targetting? I only tested this with Python 3.10.

After installing the rust toolchain and android targets as explained above, you should be able to build cryprography as any normal wheel, with the standard build-wheel.py invocation. Which errors do you get?

My email is [email protected] but probably better to discuss here, as it would be beneficial for other people too. Also my intention is to allow anyone to build this without any issues

@emanuele-f
Copy link
Contributor Author

Ps. building cryptography 43.0.1 for Python 3.10 from this PR branch requires minimal changes, just apply the following patch:

diff --git a/server/pypi/packages/cryptography/meta.yaml b/server/pypi/packages/cryptography/meta.yaml
index 0d042e84..59e63fd0 100644
--- a/server/pypi/packages/cryptography/meta.yaml
+++ b/server/pypi/packages/cryptography/meta.yaml
@@ -1,6 +1,6 @@
 package:
   name: cryptography
-  version: "42.0.8"
+  version: "43.0.1"
 
 requirements:
   build:
diff --git a/server/pypi/packages/cryptography/patches/pyo3_no_interpreter.patch b/server/pypi/packages/cryptography/patches/pyo3_no_interpreter.patch
index 3f03ced5..2d0b9d65 100644
--- a/server/pypi/packages/cryptography/patches/pyo3_no_interpreter.patch
+++ b/server/pypi/packages/cryptography/patches/pyo3_no_interpreter.patch
@@ -1,11 +1,11 @@
 --- src-original/src/rust/Cargo.toml
 +++ src/src/rust/Cargo.toml
-@@ -10,7 +10,7 @@
+@@ -17,7 +17,7 @@
  [dependencies]
  once_cell = "1"
  cfg-if = "1"
--pyo3 = { version = "0.20", features = ["abi3"] }
-+pyo3 = { version = "0.20", features = ["abi3", "abi3-py310"] }
- asn1 = { version = "0.15.5", default-features = false }
+-pyo3 = { version = "0.22.2", features = ["abi3"] }
++pyo3 = { version = "0.22.2", features = ["abi3", "abi3-py310"] }
+ asn1 = { version = "0.16.2", default-features = false }
  cryptography-cffi = { path = "cryptography-cffi" }
- cryptography-key-parsing = { path = "cryptography-key-parsing" }
+ cryptography-keepalive = { path = "cryptography-keepalive" }

@Michu44
Copy link

Michu44 commented Oct 11, 2024

@emanuele-f Thank you so much for the patch. I'll try and build this using your current code base then.
The end-goal for me is to get the current pyatv library to work on chaquopy, as it seams only cryptography seams to be missing at this point. I'll try and figure it out again with your PR.

@Michu44
Copy link

Michu44 commented Oct 11, 2024

@emanuele-f I'm targeting either 3.10 or 3.11 as pyatv is working on both.

@mhsmith mhsmith merged commit 13c1fce into chaquo:master Oct 17, 2024
@mhsmith
Copy link
Member

mhsmith commented Oct 17, 2024

I've now released cryptography 42.0.8 wheels for Python 3.10 - 3.13. Thanks again!

@emanuele-f
Copy link
Contributor Author

Awesome, thanks @mhsmith !

@maciekglowka

This comment was marked as off-topic.

@emanuele-f

This comment was marked as off-topic.

@maciekglowka

This comment was marked as off-topic.

@mhsmith mhsmith mentioned this pull request Nov 19, 2024
@mhsmith
Copy link
Member

mhsmith commented Nov 19, 2024

These comments would be more useful on the pydantic issue (#1017), so I've moved them there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants