@@ -199,16 +199,6 @@ impl Step for Std {
199
199
200
200
builder. require_submodule ( "library/stdarch" , None ) ;
201
201
202
- // Profiler information requires LLVM's compiler-rt
203
- if builder. config . profiler {
204
- builder. require_submodule (
205
- "src/llvm-project" ,
206
- Some (
207
- "The `build.profiler` config option requires `compiler-rt` sources from LLVM." ,
208
- ) ,
209
- ) ;
210
- }
211
-
212
202
let mut target_deps = builder. ensure ( StartupObjects { compiler, target } ) ;
213
203
214
204
let compiler_to_use = builder. compiler_for ( compiler. stage , compiler. host , target) ;
@@ -466,15 +456,45 @@ pub fn std_crates_for_run_make(run: &RunConfig<'_>) -> Vec<String> {
466
456
}
467
457
}
468
458
459
+ /// Tries to find LLVM's `compiler-rt` source directory, for building `library/profiler_builtins`.
460
+ ///
461
+ /// Normally it lives in the `src/llvm-project` submodule, but if we will be using a
462
+ /// downloaded copy of CI LLVM, then we try to use the `compiler-rt` sources from
463
+ /// there instead, which lets us avoid checking out the LLVM submodule.
464
+ fn compiler_rt_for_profiler ( builder : & Builder < ' _ > ) -> PathBuf {
465
+ // Try to use `compiler-rt` sources from downloaded CI LLVM, if possible.
466
+ if builder. config . llvm_from_ci {
467
+ // CI LLVM might not have been downloaded yet, so try to download it now.
468
+ builder. config . maybe_download_ci_llvm ( ) ;
469
+ let ci_llvm_compiler_rt = builder. config . ci_llvm_root ( ) . join ( "compiler-rt" ) ;
470
+ if ci_llvm_compiler_rt. exists ( ) {
471
+ return ci_llvm_compiler_rt;
472
+ }
473
+ }
474
+
475
+ // Otherwise, fall back to requiring the LLVM submodule.
476
+ builder. require_submodule ( "src/llvm-project" , {
477
+ Some ( "The `build.profiler` config option requires `compiler-rt` sources from LLVM." )
478
+ } ) ;
479
+ builder. src . join ( "src/llvm-project/compiler-rt" )
480
+ }
481
+
469
482
/// Configure cargo to compile the standard library, adding appropriate env vars
470
483
/// and such.
471
484
pub fn std_cargo ( builder : & Builder < ' _ > , target : TargetSelection , stage : u32 , cargo : & mut Cargo ) {
472
485
if let Some ( target) = env:: var_os ( "MACOSX_STD_DEPLOYMENT_TARGET" ) {
473
486
cargo. env ( "MACOSX_DEPLOYMENT_TARGET" , target) ;
474
487
}
475
488
489
+ // Paths needed by `library/profiler_builtins/build.rs`.
476
490
if let Some ( path) = builder. config . profiler_path ( target) {
477
491
cargo. env ( "LLVM_PROFILER_RT_LIB" , path) ;
492
+ } else if builder. config . profiler_enabled ( target) {
493
+ let compiler_rt = compiler_rt_for_profiler ( builder) ;
494
+ // Currently this is separate from the env var used by `compiler_builtins`
495
+ // (below) so that adding support for CI LLVM here doesn't risk breaking
496
+ // the compiler builtins. But they could be unified if desired.
497
+ cargo. env ( "RUST_COMPILER_RT_FOR_PROFILER" , compiler_rt) ;
478
498
}
479
499
480
500
// Determine if we're going to compile in optimized C intrinsics to
@@ -507,8 +527,8 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
507
527
) ;
508
528
let compiler_builtins_root = builder. src . join ( "src/llvm-project/compiler-rt" ) ;
509
529
assert ! ( compiler_builtins_root. exists( ) ) ;
510
- // Note that `libprofiler_builtins/build.rs` also computes this so if
511
- // you're changing something here please also change that.
530
+ // The path to `compiler-rt` is also used by `profiler_builtins` (above),
531
+ // so if you're changing something here please also change that as appropriate .
512
532
cargo. env ( "RUST_COMPILER_RT_ROOT" , & compiler_builtins_root) ;
513
533
" compiler-builtins-c"
514
534
} else {
0 commit comments