diff options
| author | bors <bors@rust-lang.org> | 2022-07-11 20:32:06 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-11 20:32:06 +0000 |
| commit | 8a3325496f89373cb1631a944539ff38d0966fe8 (patch) | |
| tree | f9497dad9882cf4d9edce7b8514caa74a4da04e5 /src/bootstrap/compile.rs | |
| parent | 38b72154ded23847cd08a796d0c6708b5efac265 (diff) | |
| parent | 9027f825360a83a5f632d8317e96c5440a83ebc0 (diff) | |
Auto merge of #96978 - lqd:win_pgo2, r=Mark-Simulacrum
Utilize PGO for windows x64 rustc dist builds This PR adds PGO support for the CI x64 windows dist builds. These are the results from running the rustc-perf benchmarks:  Thanks to `@Kobzol,` `@michaelwoerister,` `@wesleywiser,` `@Mark-Simulacrum` for their precious help.
Diffstat (limited to 'src/bootstrap/compile.rs')
| -rw-r--r-- | src/bootstrap/compile.rs | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index c099fedc3a7..3d678b2290d 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -25,6 +25,7 @@ use crate::config::{LlvmLibunwind, TargetSelection}; use crate::dist; use crate::native; use crate::tool::SourceType; +use crate::util::get_clang_cl_resource_dir; use crate::util::{exe, is_debug_info, is_dylib, output, symlink_dir, t, up_to_date}; use crate::LLVM_TOOLS; use crate::{CLang, Compiler, DependencyType, GitRepo, Mode}; @@ -772,10 +773,38 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS if let Some(s) = target_config.and_then(|c| c.llvm_config.as_ref()) { cargo.env("CFG_LLVM_ROOT", s); } - // Some LLVM linker flags (-L and -l) may be needed to link rustc_llvm. + + // Some LLVM linker flags (-L and -l) may be needed to link `rustc_llvm`. Its build script + // expects these to be passed via the `LLVM_LINKER_FLAGS` env variable, separated by + // whitespace. + // + // For example: + // - on windows, when `clang-cl` is used with instrumentation, we need to manually add + // clang's runtime library resource directory so that the profiler runtime library can be + // found. This is to avoid the linker errors about undefined references to + // `__llvm_profile_instrument_memop` when linking `rustc_driver`. + let mut llvm_linker_flags = String::new(); + if builder.config.llvm_profile_generate && target.contains("msvc") { + if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl { + // Add clang's runtime library directory to the search path + let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path); + llvm_linker_flags.push_str(&format!("-L{}", clang_rt_dir.display())); + } + } + + // The config can also specify its own llvm linker flags. if let Some(ref s) = builder.config.llvm_ldflags { - cargo.env("LLVM_LINKER_FLAGS", s); + if !llvm_linker_flags.is_empty() { + llvm_linker_flags.push_str(" "); + } + llvm_linker_flags.push_str(s); + } + + // Set the linker flags via the env var that `rustc_llvm`'s build script will read. + if !llvm_linker_flags.is_empty() { + cargo.env("LLVM_LINKER_FLAGS", llvm_linker_flags); } + // Building with a static libstdc++ is only supported on linux right now, // not for MSVC or macOS if builder.config.llvm_static_stdcpp |
