Skip to content

Commit

Permalink
Add upstream patch to allow building on aarch64-apple-darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Sep 26, 2020
1 parent 68ef4c7 commit 8ae855b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
Expand Down

0 comments on commit 8ae855b

Please sign in to comment.