@@ -157,6 +157,7 @@ impl Build {
157
157
}
158
158
159
159
let os = match target {
160
+ "aarch64-apple-darwin" => "darwin64-arm64-cc" ,
160
161
// Note that this, and all other android targets, aren't using the
161
162
// `android64-aarch64` (or equivalent) builtin target. That
162
163
// apparently has a crazy amount of build logic in OpenSSL 1.1.1
@@ -446,6 +447,11 @@ fn cp_r(src: &Path, dst: &Path) {
446
447
}
447
448
448
449
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 ) {
449
455
if !target. contains ( "musl" ) {
450
456
return ;
451
457
}
@@ -462,6 +468,40 @@ fn apply_patches(target: &str, inner: &Path) {
462
468
fs:: write ( path, buf) . unwrap ( ) ;
463
469
}
464
470
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
+
465
505
fn sanitize_sh ( path : & Path ) -> String {
466
506
if !cfg ! ( windows) {
467
507
return path. to_str ( ) . unwrap ( ) . to_string ( ) ;
0 commit comments