Skip to content

Commit

Permalink
Initial attempt at a modern cryptography patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Sep 29, 2023
1 parent b547d1d commit faaa040
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 31 deletions.
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
12 changes: 5 additions & 7 deletions recipes/cryptography/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package:
name: cryptography
version: 3.4.8
version: 41.0.4

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

requirements:
build:
- cffi 1.15.1
- setuptools-rust 0.11.6
# "setuptools_rust @ git+https://github.com/freakboy3742/setuptools_rust@iOS-support",
- setuptools_rust @ git+https://github.com/freakboy3742/setuptools-rust@iOS-support
host:
- openssl 1.1.1v
# - openssl 3.1.2
- openssl 3.1.2
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.
//
21 changes: 0 additions & 21 deletions recipes/cryptography/patches/random.patch

This file was deleted.

11 changes: 10 additions & 1 deletion src/forge/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,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)
return env
Expand Down Expand Up @@ -415,7 +424,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("/Users/rkm/.")
# 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

0 comments on commit faaa040

Please sign in to comment.