diff --git a/src/lib.rs b/src/lib.rs index 1bf15503..f57a8a9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -157,6 +157,7 @@ impl Build { } let os = match target { + "aarch64-apple-darwin" => "darwin64-arm64-cc", // Note that this, and all other android targets, aren't using the // `android64-aarch64` (or equivalent) builtin target. That // apparently has a crazy amount of build logic in OpenSSL 1.1.1 @@ -446,6 +447,11 @@ fn cp_r(src: &Path, dst: &Path) { } fn apply_patches(target: &str, inner: &Path) { + apply_patches_musl(target, inner); + apply_patches_aarch64_apple_darwin(target, inner); +} + +fn apply_patches_musl(target: &str, inner: &Path) { if !target.contains("musl") { return; } @@ -462,6 +468,40 @@ fn apply_patches(target: &str, inner: &Path) { fs::write(path, buf).unwrap(); } +fn apply_patches_aarch64_apple_darwin(target: &str, inner: &Path) { + if target != "aarch64-apple-darwin" { + return; + } + + // Apply build system changes to allow configuring and building + // for Apple's ARM64 platform. + // https://github.com/openssl/openssl/pull/12369 + + let path = inner.join("Configurations/10-main.conf"); + let mut buf = fs::read_to_string(&path).unwrap(); + + assert!( + !buf.contains("darwin64-arm64-cc"), + "{} already contains instructions for aarch64-apple-darwin", + path.display(), + ); + + const PATCH: &str = r#" + "darwin64-arm64-cc" => { + inherit_from => [ "darwin-common", asm("aarch64_asm") ], + CFLAGS => add("-Wall"), + cflags => add("-arch arm64"), + lib_cppflags => add("-DL_ENDIAN"), + bn_ops => "SIXTY_FOUR_BIT_LONG", + perlasm_scheme => "ios64", + },"#; + + let x86_64_stanza = buf.find(r#" "darwin64-x86_64-cc""#).unwrap(); + buf.insert_str(x86_64_stanza, PATCH); + + fs::write(path, buf).unwrap(); +} + fn sanitize_sh(path: &Path) -> String { if !cfg!(windows) { return path.to_str().unwrap().to_string();