Skip to content

Commit faaa040

Browse files
committed
Initial attempt at a modern cryptography patch.
1 parent b547d1d commit faaa040

File tree

6 files changed

+53
-31
lines changed

6 files changed

+53
-31
lines changed

README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ Inside the recipe directory, add the following files.
158158
``aarch64-apple-ios12.0-simulator``)
159159
- ``BUILD_TRIPLET`` - the GCC compiler triplet for the build platform (e.g.,
160160
``aarch64-apple-darwin``)
161+
- ``CARGO_BUILD_TARGET`` - the Rust cargo build target for the platform
161162
- ``PREFIX`` - a location where the compiled package can be installed in preparation
162163
for packaging.
163164

recipes/cryptography/meta.yaml

+5-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package:
22
name: cryptography
3-
version: 3.4.8
3+
version: 41.0.4
44

55
build:
66
script_env:
7-
- CRYPTOGRAPHY_DONT_BUILD_RUST=1
7+
- OPENSSL_STATIC=1
8+
- OPENSSL_DIR={platlib}/opt
89

910
requirements:
1011
build:
11-
- cffi 1.15.1
12-
- setuptools-rust 0.11.6
13-
# "setuptools_rust @ git+https://github.com/freakboy3742/setuptools_rust@iOS-support",
12+
- setuptools_rust @ git+https://github.com/freakboy3742/setuptools-rust@iOS-support
1413
host:
15-
- openssl 1.1.1v
16-
# - openssl 3.1.2
14+
- openssl 3.1.2
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff -ru cryptography-41.0.4-orig/src/rust/cryptography-cffi/build.rs cryptography-41.0.4/src/rust/cryptography-cffi/build.rs
2+
--- cryptography-41.0.4-orig/src/rust/cryptography-cffi/build.rs 2023-09-20 00:20:46
3+
+++ cryptography-41.0.4/src/rust/cryptography-cffi/build.rs 2023-09-29 13:05:45
4+
@@ -11,7 +11,7 @@
5+
let openssl_static = env::var("OPENSSL_STATIC")
6+
.map(|x| x == "1")
7+
.unwrap_or(false);
8+
- if target.contains("apple") && openssl_static {
9+
+ if target.contains("apple-darwin") && openssl_static {
10+
// On (older) OSX we need to link against the clang runtime,
11+
// which is hidden in some non-default path.
12+
//

recipes/cryptography/patches/random.patch

-21
This file was deleted.

src/forge/build.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,20 @@ def compile_env(self, **kwargs) -> dict[str:str]:
193193
if (sdk_root / "usr" / "lib").is_dir():
194194
ldflags += f" -L{sdk_root}/usr/lib"
195195

196+
cargo_build_target = {
197+
"arm64-apple-ios": "aarch64-apple-ios",
198+
"arm64-apple-ios-simulator": "aarch64-apple-ios-simulator",
199+
# This one is odd; Rust doesn't provide an `x86_64-apple-ios-simulator`,
200+
# but there's no such thing as an x86_64 ios *device*.
201+
"x86_64-apple-ios-simulator": "x86_64-apple-ios",
202+
}[self.cross_venv.platform_triplet]
203+
196204
env = {
197205
"AR": ar,
198206
"CC": cc,
199207
"CFLAGS": cflags,
200208
"LDFLAGS": ldflags,
209+
"CARGO_BUILD_TARGET": cargo_build_target,
201210
}
202211
env.update(kwargs)
203212
return env
@@ -415,7 +424,7 @@ def build(self):
415424
script_env = {}
416425
for line in self.package.meta["build"]["script_env"]:
417426
key, value = line.split("=", 1)
418-
script_env[key] = value
427+
script_env[key] = value.format(**self.cross_venv.scheme_paths)
419428

420429
# Set the cross host platform in the environment
421430
script_env["_PYTHON_HOST_PLATFORM"] = self.cross_venv.platform_identifier

src/forge/cross.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self, sdk, sdk_version, arch):
6464

6565
# Prime the on-demand variable cache
6666
self._sysconfig_data = None
67+
self._scheme_paths = None
6768
self._install_root = None
6869
self._sdk_root = None
6970

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

104105
return self._sysconfig_data
105106

107+
@property
108+
def scheme_paths(self) -> dict[str, str]:
109+
"""The install scheme paths for the cross environment."""
110+
if self._scheme_paths is None:
111+
# Run a script in the cross-venv that outputs the config variables
112+
config_var_repr = self.check_output(
113+
[
114+
"python",
115+
"-c",
116+
"import sysconfig; print(sysconfig.get_paths())",
117+
],
118+
encoding="UTF-8",
119+
)
120+
121+
# Parse the output of the previous command as Python,
122+
# turning it back into a dict.
123+
config = {}
124+
exec(f"data = {config_var_repr}", config, config)
125+
self._scheme_paths = config["data"]
126+
127+
return self._scheme_paths
128+
106129
@property
107130
def install_root(self) -> Path:
108131
"""The path that serves as the installation root for native libraries.
@@ -296,8 +319,8 @@ def cross_kwargs(self, kwargs):
296319
p
297320
for p in os.getenv("PATH").split(os.pathsep)[1:]
298321
if not (
299-
# Exclude rbenv, npm, and other language environments
300-
p.startswith("/Users/rkm/.")
322+
# Exclude rbenv, npm, and other language environments, except for rust/cargo.
323+
(p.startswith(f"{Path.home() / '.'}") and not p.endswith("/.cargo/bin"))
301324
# Exclude homebrew
302325
or p.startswith("/opt")
303326
# Exclude local python installs

0 commit comments

Comments
 (0)