@@ -547,20 +547,28 @@ mod c {
547
547
sources. extend ( & [ ( "__emutls_get_address" , "emutls.c" ) ] ) ;
548
548
}
549
549
550
+ // Optionally, link against a prebuilt compiler-rt library to supply
551
+ // optimized intrinsics instead of compiling a subset of compiler-rt
552
+ // from source.
553
+ let link_against_prebuilt_rt = env:: var_os ( "LLVM_COMPILER_RT_LIB" ) . is_some ( ) ;
554
+
550
555
// When compiling the C code we require the user to tell us where the
551
556
// source code is, and this is largely done so when we're compiling as
552
557
// part of rust-lang/rust we can use the same llvm-project repository as
553
558
// rust-lang/rust.
554
559
let root = match env:: var_os ( "RUST_COMPILER_RT_ROOT" ) {
555
560
Some ( s) => PathBuf :: from ( s) ,
561
+ // If a prebuild libcompiler-rt is provided, set a valid
562
+ // path to simplify later logic. Nothing should be compiled.
563
+ None if link_against_prebuilt_rt => PathBuf :: new ( ) ,
556
564
None => {
557
565
panic ! (
558
566
"RUST_COMPILER_RT_ROOT is not set. You may need to run \
559
567
`ci/download-compiler-rt.sh`."
560
568
) ;
561
569
}
562
570
} ;
563
- if !root. exists ( ) {
571
+ if !link_against_prebuilt_rt && ! root. exists ( ) {
564
572
panic ! ( "RUST_COMPILER_RT_ROOT={} does not exist" , root. display( ) ) ;
565
573
}
566
574
@@ -576,7 +584,7 @@ mod c {
576
584
let src_dir = root. join ( "lib/builtins" ) ;
577
585
if target. arch == "aarch64" && target. env != "msvc" && target. os != "uefi" {
578
586
// See below for why we're building these as separate libraries.
579
- build_aarch64_out_of_line_atomics_libraries ( & src_dir, cfg) ;
587
+ build_aarch64_out_of_line_atomics_libraries ( & src_dir, cfg, link_against_prebuilt_rt ) ;
580
588
581
589
// Some run-time CPU feature detection is necessary, as well.
582
590
let cpu_model_src = if src_dir. join ( "cpu_model.c" ) . exists ( ) {
@@ -590,20 +598,45 @@ mod c {
590
598
let mut added_sources = HashSet :: new ( ) ;
591
599
for ( sym, src) in sources. map . iter ( ) {
592
600
let src = src_dir. join ( src) ;
593
- if added_sources. insert ( src. clone ( ) ) {
601
+ if !link_against_prebuilt_rt && added_sources. insert ( src. clone ( ) ) {
594
602
cfg. file ( & src) ;
595
603
println ! ( "cargo:rerun-if-changed={}" , src. display( ) ) ;
596
604
}
597
605
println ! ( "cargo:rustc-cfg={}=\" optimized-c\" " , sym) ;
598
606
}
599
607
600
- cfg. compile ( "libcompiler-rt.a" ) ;
608
+ if link_against_prebuilt_rt {
609
+ let rt_builtins_ext = PathBuf :: from ( env:: var_os ( "LLVM_COMPILER_RT_LIB" ) . unwrap ( ) ) ;
610
+ if !rt_builtins_ext. exists ( ) {
611
+ panic ! (
612
+ "LLVM_COMPILER_RT_LIB={} does not exist" ,
613
+ rt_builtins_ext. display( )
614
+ ) ;
615
+ }
616
+ if let Some ( dir) = rt_builtins_ext. parent ( ) {
617
+ println ! ( "cargo::rustc-link-search=native={}" , dir. display( ) ) ;
618
+ }
619
+ if let Some ( lib) = rt_builtins_ext. file_name ( ) {
620
+ println ! (
621
+ "cargo::rustc-link-lib=static:+verbatim={}" ,
622
+ lib. to_str( ) . unwrap( )
623
+ ) ;
624
+ }
625
+ } else {
626
+ cfg. compile ( "libcompiler-rt.a" ) ;
627
+ }
601
628
}
602
629
603
- fn build_aarch64_out_of_line_atomics_libraries ( builtins_dir : & Path , cfg : & mut cc:: Build ) {
630
+ fn build_aarch64_out_of_line_atomics_libraries (
631
+ builtins_dir : & Path ,
632
+ cfg : & mut cc:: Build ,
633
+ link_against_prebuilt_rt : bool ,
634
+ ) {
604
635
let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
605
636
let outlined_atomics_file = builtins_dir. join ( "aarch64" ) . join ( "lse.S" ) ;
606
- println ! ( "cargo:rerun-if-changed={}" , outlined_atomics_file. display( ) ) ;
637
+ if !link_against_prebuilt_rt {
638
+ println ! ( "cargo:rerun-if-changed={}" , outlined_atomics_file. display( ) ) ;
639
+ }
607
640
608
641
cfg. include ( & builtins_dir) ;
609
642
@@ -616,6 +649,13 @@ mod c {
616
649
for ( model_number, model_name) in
617
650
& [ ( 1 , "relax" ) , ( 2 , "acq" ) , ( 3 , "rel" ) , ( 4 , "acq_rel" ) ]
618
651
{
652
+ let sym = format ! ( "__aarch64_{}{}_{}" , instruction_type, size, model_name) ;
653
+ println ! ( "cargo:rustc-cfg={}=\" optimized-c\" " , sym) ;
654
+
655
+ if link_against_prebuilt_rt {
656
+ continue ;
657
+ }
658
+
619
659
// The original compiler-rt build system compiles the same
620
660
// source file multiple times with different compiler
621
661
// options. Here we do something slightly different: we
@@ -639,9 +679,6 @@ mod c {
639
679
. unwrap ( ) ;
640
680
drop ( file) ;
641
681
cfg. file ( path) ;
642
-
643
- let sym = format ! ( "__aarch64_{}{}_{}" , instruction_type, size, model_name) ;
644
- println ! ( "cargo:rustc-cfg={}=\" optimized-c\" " , sym) ;
645
682
}
646
683
}
647
684
}
0 commit comments