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 #3

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ Inside the recipe directory, add the following files.
``aarch64-apple-ios12.0-simulator``)
- ``BUILD_TRIPLET`` - the GCC compiler triplet for the build platform (e.g.,
``aarch64-apple-darwin``)
- ``CARGO_BUILD_TARGET`` - the Rust cargo build target for the platform
- ``PREFIX`` - a location where the compiled package can be installed in preparation
for packaging.

Expand Down
24 changes: 21 additions & 3 deletions recipes/cryptography/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package:
name: cryptography
version: 3.4.8
version: 41.0.4

{% if version and version < (3, 4, 9) %}

patches:
- random.patch
Expand All @@ -13,7 +15,23 @@ requirements:
build:
- cffi 1.15.1
- setuptools-rust 0.11.6
# "setuptools_rust @ git+https://github.com/freakboy3742/setuptools_rust@iOS-support",
host:
- openssl 1.1.1v
# - openssl 3.1.2

{% else %}

patches:
- mobile.patch

build:
script_env:
- OPENSSL_STATIC=1
- OPENSSL_DIR={platlib}/opt

requirements:
build:
- setuptools_rust @ git+https://github.com/freakboy3742/setuptools-rust@iOS-support
host:
- openssl 3.1.2

{% endif %}
12 changes: 12 additions & 0 deletions recipes/cryptography/patches/mobile.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff -ru cryptography-41.0.4-orig/src/rust/cryptography-cffi/build.rs cryptography-41.0.4/src/rust/cryptography-cffi/build.rs
--- cryptography-41.0.4-orig/src/rust/cryptography-cffi/build.rs 2023-09-20 00:20:46
+++ cryptography-41.0.4/src/rust/cryptography-cffi/build.rs 2023-09-29 13:05:45
@@ -11,7 +11,7 @@
let openssl_static = env::var("OPENSSL_STATIC")
.map(|x| x == "1")
.unwrap_or(false);
- if target.contains("apple") && openssl_static {
+ if target.contains("apple-darwin") && openssl_static {
// On (older) OSX we need to link against the clang runtime,
// which is hidden in some non-default path.
//
11 changes: 10 additions & 1 deletion src/forge/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,20 @@ def compile_env(self, **kwargs) -> dict[str:str]:
if (sdk_root / "usr" / "lib").is_dir():
ldflags += f" -L{sdk_root}/usr/lib"

cargo_build_target = {
"arm64-apple-ios": "aarch64-apple-ios",
"arm64-apple-ios-simulator": "aarch64-apple-ios-simulator",
# This one is odd; Rust doesn't provide an `x86_64-apple-ios-simulator`,
# but there's no such thing as an x86_64 ios *device*.
"x86_64-apple-ios-simulator": "x86_64-apple-ios",
}[self.cross_venv.platform_triplet]

env = {
"AR": ar,
"CC": cc,
"CFLAGS": cflags,
"LDFLAGS": ldflags,
"CARGO_BUILD_TARGET": cargo_build_target,
}
env.update(kwargs)

Expand Down Expand Up @@ -430,7 +439,7 @@ def build(self):
script_env = {}
for line in self.package.meta["build"]["script_env"]:
key, value = line.split("=", 1)
script_env[key] = value
script_env[key] = value.format(**self.cross_venv.scheme_paths)

# Set the cross host platform in the environment
script_env["_PYTHON_HOST_PLATFORM"] = self.cross_venv.platform_identifier
Expand Down
27 changes: 25 additions & 2 deletions src/forge/cross.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def __init__(self, sdk, sdk_version, arch):

# Prime the on-demand variable cache
self._sysconfig_data = None
self._scheme_paths = None
self._install_root = None
self._sdk_root = None

Expand Down Expand Up @@ -103,6 +104,28 @@ def sysconfig_data(self) -> dict[str, str]:

return self._sysconfig_data

@property
def scheme_paths(self) -> dict[str, str]:
"""The install scheme paths for the cross environment."""
if self._scheme_paths is None:
# Run a script in the cross-venv that outputs the config variables
config_var_repr = self.check_output(
[
"python",
"-c",
"import sysconfig; print(sysconfig.get_paths())",
],
encoding="UTF-8",
)

# Parse the output of the previous command as Python,
# turning it back into a dict.
config = {}
exec(f"data = {config_var_repr}", config, config)
self._scheme_paths = config["data"]

return self._scheme_paths

@property
def install_root(self) -> Path:
"""The path that serves as the installation root for native libraries.
Expand Down Expand Up @@ -296,8 +319,8 @@ def cross_kwargs(self, kwargs):
p
for p in os.getenv("PATH").split(os.pathsep)[1:]
if not (
# Exclude rbenv, npm, and other language environments
p.startswith(f"{Path.home()}/.")
# Exclude rbenv, npm, and other language environments, except for rust/cargo.
(p.startswith(f"{Path.home()}/.") and not p.endswith("/.cargo/bin"))
# Exclude homebrew
or p.startswith("/opt")
# Exclude local python installs
Expand Down