Skip to content

Commit 8ae855b

Browse files
committed
Add upstream patch to allow building on aarch64-apple-darwin
Closes #72
1 parent 68ef4c7 commit 8ae855b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ impl Build {
157157
}
158158

159159
let os = match target {
160+
"aarch64-apple-darwin" => "darwin64-arm64-cc",
160161
// Note that this, and all other android targets, aren't using the
161162
// `android64-aarch64` (or equivalent) builtin target. That
162163
// apparently has a crazy amount of build logic in OpenSSL 1.1.1
@@ -446,6 +447,11 @@ fn cp_r(src: &Path, dst: &Path) {
446447
}
447448

448449
fn apply_patches(target: &str, inner: &Path) {
450+
apply_patches_musl(target, inner);
451+
apply_patches_aarch64_apple_darwin(target, inner);
452+
}
453+
454+
fn apply_patches_musl(target: &str, inner: &Path) {
449455
if !target.contains("musl") {
450456
return;
451457
}
@@ -462,6 +468,40 @@ fn apply_patches(target: &str, inner: &Path) {
462468
fs::write(path, buf).unwrap();
463469
}
464470

471+
fn apply_patches_aarch64_apple_darwin(target: &str, inner: &Path) {
472+
if target != "aarch64-apple-darwin" {
473+
return;
474+
}
475+
476+
// Apply build system changes to allow configuring and building
477+
// for Apple's ARM64 platform.
478+
// https://github.com/openssl/openssl/pull/12369
479+
480+
let path = inner.join("Configurations/10-main.conf");
481+
let mut buf = fs::read_to_string(&path).unwrap();
482+
483+
assert!(
484+
!buf.contains("darwin64-arm64-cc"),
485+
"{} already contains instructions for aarch64-apple-darwin",
486+
path.display(),
487+
);
488+
489+
const PATCH: &str = r#"
490+
"darwin64-arm64-cc" => {
491+
inherit_from => [ "darwin-common", asm("aarch64_asm") ],
492+
CFLAGS => add("-Wall"),
493+
cflags => add("-arch arm64"),
494+
lib_cppflags => add("-DL_ENDIAN"),
495+
bn_ops => "SIXTY_FOUR_BIT_LONG",
496+
perlasm_scheme => "ios64",
497+
},"#;
498+
499+
let x86_64_stanza = buf.find(r#" "darwin64-x86_64-cc""#).unwrap();
500+
buf.insert_str(x86_64_stanza, PATCH);
501+
502+
fs::write(path, buf).unwrap();
503+
}
504+
465505
fn sanitize_sh(path: &Path) -> String {
466506
if !cfg!(windows) {
467507
return path.to_str().unwrap().to_string();

0 commit comments

Comments
 (0)