diff --git a/README.rst b/README.rst index ce089ad..982d73a 100644 --- a/README.rst +++ b/README.rst @@ -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. diff --git a/recipes/cryptography/meta.yaml b/recipes/cryptography/meta.yaml index 6f3f0eb..8e49c0f 100644 --- a/recipes/cryptography/meta.yaml +++ b/recipes/cryptography/meta.yaml @@ -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 @@ -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 %} diff --git a/recipes/cryptography/patches/mobile.patch b/recipes/cryptography/patches/mobile.patch new file mode 100644 index 0000000..855044d --- /dev/null +++ b/recipes/cryptography/patches/mobile.patch @@ -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. + // diff --git a/src/forge/build.py b/src/forge/build.py index 1387191..6252e3a 100644 --- a/src/forge/build.py +++ b/src/forge/build.py @@ -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) @@ -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 diff --git a/src/forge/cross.py b/src/forge/cross.py index 1517b87..0df54f1 100644 --- a/src/forge/cross.py +++ b/src/forge/cross.py @@ -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 @@ -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. @@ -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