@@ -158,6 +158,7 @@ impl Build {
158
158
}
159
159
160
160
let os = match target {
161
+ "aarch64-apple-darwin" => "darwin64-arm64-cc" ,
161
162
// Note that this, and all other android targets, aren't using the
162
163
// `android64-aarch64` (or equivalent) builtin target. That
163
164
// apparently has a crazy amount of build logic in OpenSSL 1.1.1
@@ -447,6 +448,11 @@ fn cp_r(src: &Path, dst: &Path) {
447
448
}
448
449
449
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 ) {
450
456
if !target. contains ( "musl" ) {
451
457
return ;
452
458
}
@@ -467,6 +473,44 @@ fn apply_patches(target: &str, inner: &Path) {
467
473
. unwrap ( ) ;
468
474
}
469
475
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
+
470
514
fn sanitize_sh ( path : & Path ) -> String {
471
515
if !cfg ! ( windows) {
472
516
return path. to_str ( ) . unwrap ( ) . to_string ( ) ;
0 commit comments