Skip to content

Commit b95e4e3

Browse files
committed
Add upstream patch to allow building on aarch64-apple-darwin
Closes #72
1 parent 9e7d91a commit b95e4e3

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl Build {
158158
}
159159

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

449450
fn apply_patches(target: &str, inner: &Path) {
451+
apply_patches_musl(target, inner);
452+
apply_patches_aarch64_apple_darwin(target, inner);
453+
}
454+
455+
fn apply_patches_musl(target: &str, inner: &Path) {
450456
if !target.contains("musl") {
451457
return;
452458
}
@@ -467,6 +473,44 @@ fn apply_patches(target: &str, inner: &Path) {
467473
.unwrap();
468474
}
469475

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

0 commit comments

Comments
 (0)