|
1 | 1 | extern crate cc; |
2 | 2 |
|
3 | 3 | use std::env; |
4 | | -use std::fs::{self, File}; |
5 | | -use std::io::{Read, Write}; |
| 4 | +use std::fs; |
6 | 5 | use std::path::{Path, PathBuf}; |
7 | 6 | use std::process::Command; |
8 | 7 |
|
@@ -158,6 +157,7 @@ impl Build { |
158 | 157 | } |
159 | 158 |
|
160 | 159 | let os = match target { |
| 160 | + "aarch64-apple-darwin" => "darwin64-arm64-cc", |
161 | 161 | // Note that this, and all other android targets, aren't using the |
162 | 162 | // `android64-aarch64` (or equivalent) builtin target. That |
163 | 163 | // apparently has a crazy amount of build logic in OpenSSL 1.1.1 |
@@ -448,24 +448,59 @@ fn cp_r(src: &Path, dst: &Path) { |
448 | 448 | } |
449 | 449 |
|
450 | 450 | 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) { |
451 | 456 | if !target.contains("musl") { |
452 | 457 | return; |
453 | 458 | } |
454 | 459 |
|
455 | 460 | // Undo part of https://github.com/openssl/openssl/commit/c352bd07ed2ff872876534c950a6968d75ef121e on MUSL |
456 | 461 | // since it doesn't have asm/unistd.h |
457 | | - let mut buf = String::new(); |
458 | 462 | let path = inner.join("crypto/rand/rand_unix.c"); |
459 | | - File::open(&path).unwrap().read_to_string(&mut buf).unwrap(); |
| 463 | + let buf = fs::read_to_string(&path).unwrap(); |
460 | 464 |
|
461 | 465 | let buf = buf |
462 | 466 | .replace("asm/unistd.h", "sys/syscall.h") |
463 | 467 | .replace("__NR_getrandom", "SYS_getrandom"); |
464 | 468 |
|
465 | | - File::create(&path) |
466 | | - .unwrap() |
467 | | - .write_all(buf.as_bytes()) |
468 | | - .unwrap(); |
| 469 | + fs::write(path, buf).unwrap(); |
| 470 | +} |
| 471 | + |
| 472 | +fn apply_patches_aarch64_apple_darwin(target: &str, inner: &Path) { |
| 473 | + if target != "aarch64-apple-darwin" { |
| 474 | + return; |
| 475 | + } |
| 476 | + |
| 477 | + // Apply build system changes to allow configuring and building |
| 478 | + // for Apple's ARM64 platform. |
| 479 | + // https://github.com/openssl/openssl/pull/12369 |
| 480 | + |
| 481 | + let path = inner.join("Configurations/10-main.conf"); |
| 482 | + let mut buf = fs::read_to_string(&path).unwrap(); |
| 483 | + |
| 484 | + assert!( |
| 485 | + !buf.contains("darwin64-arm64-cc"), |
| 486 | + "{} already contains instructions for aarch64-apple-darwin", |
| 487 | + path.display(), |
| 488 | + ); |
| 489 | + |
| 490 | + const PATCH: &str = r#" |
| 491 | + "darwin64-arm64-cc" => { |
| 492 | + inherit_from => [ "darwin-common", asm("aarch64_asm") ], |
| 493 | + CFLAGS => add("-Wall"), |
| 494 | + cflags => add("-arch arm64"), |
| 495 | + lib_cppflags => add("-DL_ENDIAN"), |
| 496 | + bn_ops => "SIXTY_FOUR_BIT_LONG", |
| 497 | + perlasm_scheme => "ios64", |
| 498 | + },"#; |
| 499 | + |
| 500 | + let x86_64_stanza = buf.find(r#" "darwin64-x86_64-cc""#).unwrap(); |
| 501 | + buf.insert_str(x86_64_stanza, PATCH); |
| 502 | + |
| 503 | + fs::write(path, buf).unwrap(); |
469 | 504 | } |
470 | 505 |
|
471 | 506 | fn sanitize_sh(path: &Path) -> String { |
|
0 commit comments