Skip to content

How to cross-compile cryptography with rust support?  #5814

Closed
@holzschu

Description

@holzschu

Hi,
I'm trying to compile the new version of cryptography, with rust support, for iOS and iOS simulator, on a Mac.

Cross-compiling the C files works by setting CFLAGS and CC inside the environment:

env CC=clang CXX=clang++ \
CPPFLAGS="-arch arm64 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -I$PREFIX  -I$PREFIX/Frameworks_iphoneos/include/ -DCRYPTOGRAPHY_OSRANDOM_ENGINE=CRYPTOGRAPHY_OSRANDOM_ENGINE_DEV_URANDOM" \
CFLAGS="-arch arm64 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -I$PREFIX  -I$PREFIX/Frameworks_iphoneos/include/  -DCRYPTOGRAPHY_OSRANDOM_ENGINE=CRYPTOGRAPHY_OSRANDOM_ENGINE_DEV_URANDOM " \
CXXFLAGS="-arch arm64 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -I$PREFIX  -I$PREFIX/Frameworks_iphoneos/include/  -DCRYPTOGRAPHY_OSRANDOM_ENGINE=CRYPTOGRAPHY_OSRANDOM_ENGINE_DEV_URANDOM" \
LDFLAGS="-arch arm64 -miphoneos-version-min=14.0 -isysroot $IOS_SDKROOT -F$PREFIX/Frameworks_iphoneos -framework ios_system -L$PREFIX/build/lib.darwin-arm64-3.9 -L$PREFIX/Frameworks_iphoneos/lib/" \
LDSHARED="clang -v -undefined error -dynamiclib -isysroot $IOS_SDKROOT -F$PREFIX/Frameworks_iphoneos -framework ios_system -L$PREFIX/build/lib.darwin-arm64-3.9 -lz -lpython3.9 -L$PREFIX/Frameworks_iphoneos/lib/" \
PLATFORM=iphoneos python3.9 setup.py build

(I'll admit the command line is a bit scary, but it's basically just setting flags).

However, setting flags for rustc does not work in the current release. I've tried adding RUSTFLAGS="--target=aarch64-apple-ios" to the previous command line, but all I get is an error:

(...)
running build_rust
cargo rustc --lib --manifest-path src/rust/Cargo.toml --features pyo3/abi3-py36 pyo3/extension-module --release --verbose -- --crate-type cdylib -C link-arg=-undefined -C link-arg=dynamic_lookup
error: cannot produce cdylib for `cryptography-rust v0.1.0 (/Users/holzschu/src/Xcode_iPad/Carnets/cpython/packages/cryptography-3.4.4/src/rust)` as the target `x86_64-apple-darwin` does not support these crate types

As you can see, the target in the error message is not the target specified on the --target flag, which is confusing. Adding the "--target" flag manually to the compile command works for a while longer:

> cargo rustc --lib --manifest-path src/rust/Cargo.toml --features pyo3/abi3-py36 pyo3/extension-module --release --verbose -- --crate-type cdylib -C link-arg=-undefined -C link-arg=dynamic_lookup --target=aarch64-apple-ios
   Compiling proc-macro2 v1.0.24
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.60
   Compiling libc v0.2.85
   Compiling cfg-if v1.0.0
   Compiling scopeguard v1.1.0
   Compiling inventory v0.1.10
   Compiling smallvec v1.6.1
   Compiling unindent v0.1.7
   Compiling pyo3 v0.13.1
   Compiling paste v1.0.4
   Compiling instant v0.1.9
   Compiling lock_api v0.4.2
   Compiling indoc v1.0.3
   Compiling quote v1.0.8
   Compiling parking_lot_core v0.8.2
   Compiling parking_lot v0.11.1
   Compiling pyo3-macros-backend v0.13.1
   Compiling inventory-impl v0.1.10
   Compiling ctor v0.1.19
   Compiling ghost v0.1.2
   Compiling pyo3-macros v0.13.1
   Compiling cryptography-rust v0.1.0 (/Users/holzschu/src/Xcode_iPad/Carnets/cpython/packages/cryptography-3.4.4/src/rust)
error: Unrecognized option: 'release'

error: could not compile `cryptography-rust`

To learn more, run the command again with --verbose.

My question is: what's the recommended method to cross-compile cryptography, and how to set flags for the rust compiler?

Python: 3.9
cffi: 1.14.2
pip: 21.0.1
setuptools: 53.0.0
setuptools_rust: 0.11.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions