Add is_msvc function

This commit is contained in:
Jakub Beránek 2023-09-29 18:16:17 +02:00
parent 42dfac5e08
commit b3c9ffdc77
No known key found for this signature in database
GPG Key ID: 909CD0D26483516B
9 changed files with 26 additions and 23 deletions

View File

@ -870,7 +870,7 @@ fn run(self, builder: &Builder<'_>) {
// is already on by default in MSVC optimized builds, which is interpreted as --icf=all: // is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
// https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746 // https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
// https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827 // https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827
if builder.config.use_lld && !compiler.host.contains("msvc") { if builder.config.use_lld && !compiler.host.is_msvc() {
cargo.rustflag("-Clink-args=-Wl,--icf=all"); cargo.rustflag("-Clink-args=-Wl,--icf=all");
} }
@ -1089,7 +1089,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
// found. This is to avoid the linker errors about undefined references to // found. This is to avoid the linker errors about undefined references to
// `__llvm_profile_instrument_memop` when linking `rustc_driver`. // `__llvm_profile_instrument_memop` when linking `rustc_driver`.
let mut llvm_linker_flags = String::new(); let mut llvm_linker_flags = String::new();
if builder.config.llvm_profile_generate && target.contains("msvc") { if builder.config.llvm_profile_generate && target.is_msvc() {
if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl { if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl {
// Add clang's runtime library directory to the search path // Add clang's runtime library directory to the search path
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path); let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path);
@ -1114,7 +1114,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
// not for MSVC or macOS // not for MSVC or macOS
if builder.config.llvm_static_stdcpp if builder.config.llvm_static_stdcpp
&& !target.contains("freebsd") && !target.contains("freebsd")
&& !target.contains("msvc") && !target.is_msvc()
&& !target.contains("apple") && !target.contains("apple")
&& !target.contains("solaris") && !target.contains("solaris")
{ {

View File

@ -98,7 +98,7 @@ pub fn prebuilt_llvm_config(
let out_dir = builder.llvm_out(target); let out_dir = builder.llvm_out(target);
let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build); let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build);
if !builder.config.build.contains("msvc") || builder.ninja() { if !builder.config.build.is_msvc() || builder.ninja() {
llvm_config_ret_dir.push("build"); llvm_config_ret_dir.push("build");
} }
llvm_config_ret_dir.push("bin"); llvm_config_ret_dir.push("bin");
@ -411,7 +411,7 @@ fn run(self, builder: &Builder<'_>) -> LlvmResult {
ldflags.shared.push(" -latomic"); ldflags.shared.push(" -latomic");
} }
if target.contains("msvc") { if target.is_msvc() {
cfg.define("LLVM_USE_CRT_DEBUG", "MT"); cfg.define("LLVM_USE_CRT_DEBUG", "MT");
cfg.define("LLVM_USE_CRT_RELEASE", "MT"); cfg.define("LLVM_USE_CRT_RELEASE", "MT");
cfg.define("LLVM_USE_CRT_RELWITHDEBINFO", "MT"); cfg.define("LLVM_USE_CRT_RELWITHDEBINFO", "MT");
@ -644,7 +644,7 @@ fn configure_cmake(
} }
let sanitize_cc = |cc: &Path| { let sanitize_cc = |cc: &Path| {
if target.contains("msvc") { if target.is_msvc() {
OsString::from(cc.to_str().unwrap().replace("\\", "/")) OsString::from(cc.to_str().unwrap().replace("\\", "/"))
} else { } else {
cc.as_os_str().to_owned() cc.as_os_str().to_owned()
@ -654,7 +654,7 @@ fn configure_cmake(
// MSVC with CMake uses msbuild by default which doesn't respect these // MSVC with CMake uses msbuild by default which doesn't respect these
// vars that we'd otherwise configure. In that case we just skip this // vars that we'd otherwise configure. In that case we just skip this
// entirely. // entirely.
if target.contains("msvc") && !builder.ninja() { if target.is_msvc() && !builder.ninja() {
return; return;
} }
@ -664,7 +664,7 @@ fn configure_cmake(
}; };
// Handle msvc + ninja + ccache specially (this is what the bots use) // Handle msvc + ninja + ccache specially (this is what the bots use)
if target.contains("msvc") && builder.ninja() && builder.config.ccache.is_some() { if target.is_msvc() && builder.ninja() && builder.config.ccache.is_some() {
let mut wrap_cc = env::current_exe().expect("failed to get cwd"); let mut wrap_cc = env::current_exe().expect("failed to get cwd");
wrap_cc.set_file_name("sccache-plus-cl.exe"); wrap_cc.set_file_name("sccache-plus-cl.exe");
@ -768,7 +768,7 @@ fn configure_cmake(
// For distribution we want the LLVM tools to be *statically* linked to libstdc++. // For distribution we want the LLVM tools to be *statically* linked to libstdc++.
// We also do this if the user explicitly requested static libstdc++. // We also do this if the user explicitly requested static libstdc++.
if builder.config.llvm_static_stdcpp if builder.config.llvm_static_stdcpp
&& !target.contains("msvc") && !target.is_msvc()
&& !target.contains("netbsd") && !target.contains("netbsd")
&& !target.contains("solaris") && !target.contains("solaris")
{ {
@ -874,7 +874,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
// when doing PGO on CI, cmake or clang-cl don't automatically link clang's // when doing PGO on CI, cmake or clang-cl don't automatically link clang's
// profiler runtime in. In that case, we need to manually ask cmake to do it, to avoid // profiler runtime in. In that case, we need to manually ask cmake to do it, to avoid
// linking errors, much like LLVM's cmake setup does in that situation. // linking errors, much like LLVM's cmake setup does in that situation.
if builder.config.llvm_profile_generate && target.contains("msvc") { if builder.config.llvm_profile_generate && target.is_msvc() {
if let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref() { if let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref() {
// Find clang's runtime library directory and push that as a search path to the // Find clang's runtime library directory and push that as a search path to the
// cmake linker flags. // cmake linker flags.

View File

@ -1931,7 +1931,7 @@ fn run(self, builder: &Builder<'_>) {
// //
// Note that if we encounter `PATH` we make sure to append to our own `PATH` // Note that if we encounter `PATH` we make sure to append to our own `PATH`
// rather than stomp over it. // rather than stomp over it.
if !builder.config.dry_run() && target.contains("msvc") { if !builder.config.dry_run() && target.is_msvc() {
for &(ref k, ref v) in builder.cc.borrow()[&target].env() { for &(ref k, ref v) in builder.cc.borrow()[&target].env() {
if k != "PATH" { if k != "PATH" {
cmd.env(k, v); cmd.env(k, v);
@ -3070,7 +3070,7 @@ fn run(self, builder: &Builder<'_>) {
// We may have found various cross-compilers a little differently due to our // We may have found various cross-compilers a little differently due to our
// extra configuration, so inform cc of these compilers. Note, though, that // extra configuration, so inform cc of these compilers. Note, though, that
// on MSVC we still need cc's detection of env vars (ugh). // on MSVC we still need cc's detection of env vars (ugh).
if !target.contains("msvc") { if !target.is_msvc() {
if let Some(ar) = builder.ar(target) { if let Some(ar) = builder.ar(target) {
cfg.archiver(ar); cfg.archiver(ar);
} }

View File

@ -833,7 +833,7 @@ pub fn tool_cmd(&self, tool: Tool) -> Command {
// On MSVC a tool may invoke a C compiler (e.g., compiletest in run-make // On MSVC a tool may invoke a C compiler (e.g., compiletest in run-make
// mode) and that C compiler may need some extra PATH modification. Do // mode) and that C compiler may need some extra PATH modification. Do
// so here. // so here.
if compiler.host.contains("msvc") { if compiler.host.is_msvc() {
let curpaths = env::var_os("PATH").unwrap_or_default(); let curpaths = env::var_os("PATH").unwrap_or_default();
let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>(); let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
for &(ref k, ref v) in self.cc.borrow()[&compiler.host].env() { for &(ref k, ref v) in self.cc.borrow()[&compiler.host].env() {

View File

@ -1729,8 +1729,7 @@ pub fn cargo(
let split_debuginfo_is_stable = target.contains("linux") let split_debuginfo_is_stable = target.contains("linux")
|| target.contains("apple") || target.contains("apple")
|| (target.contains("msvc") || (target.is_msvc() && self.config.rust_split_debuginfo == SplitDebuginfo::Packed)
&& self.config.rust_split_debuginfo == SplitDebuginfo::Packed)
|| (target.contains("windows") || (target.contains("windows")
&& self.config.rust_split_debuginfo == SplitDebuginfo::Off); && self.config.rust_split_debuginfo == SplitDebuginfo::Off);
@ -1909,7 +1908,7 @@ pub fn cargo(
// the options through environment variables that are fetched and understood by both. // the options through environment variables that are fetched and understood by both.
// //
// FIXME: the guard against msvc shouldn't need to be here // FIXME: the guard against msvc shouldn't need to be here
if target.contains("msvc") { if target.is_msvc() {
if let Some(ref cl) = self.config.llvm_clang_cl { if let Some(ref cl) = self.config.llvm_clang_cl {
cargo.env("CC", cl).env("CXX", cl); cargo.env("CC", cl).env("CXX", cl);
} }

View File

@ -489,6 +489,10 @@ pub fn ends_with(&self, needle: &str) -> bool {
pub fn is_synthetic(&self) -> bool { pub fn is_synthetic(&self) -> bool {
self.synthetic self.synthetic
} }
pub fn is_msvc(&self) -> bool {
self.contains("msvc")
}
} }
impl fmt::Display for TargetSelection { impl fmt::Display for TargetSelection {

View File

@ -237,7 +237,7 @@ pub fn check(build: &mut Build) {
} }
} }
if need_cmake && target.contains("msvc") { if need_cmake && target.is_msvc() {
// There are three builds of cmake on windows: MSVC, MinGW, and // There are three builds of cmake on windows: MSVC, MinGW, and
// Cygwin. The Cygwin build does not have generators for Visual // Cygwin. The Cygwin build does not have generators for Visual
// Studio, so detect that here and error. // Studio, so detect that here and error.

View File

@ -862,7 +862,7 @@ fn llvm_filecheck(&self, target: TargetSelection) -> PathBuf {
} }
} else { } else {
let base = self.llvm_out(target).join("build"); let base = self.llvm_out(target).join("build");
let base = if !self.ninja() && target.contains("msvc") { let base = if !self.ninja() && target.is_msvc() {
if self.config.llvm_optimize { if self.config.llvm_optimize {
if self.config.llvm_release_debuginfo { if self.config.llvm_release_debuginfo {
base.join("RelWithDebInfo") base.join("RelWithDebInfo")
@ -1255,7 +1255,7 @@ fn linker(&self, target: TargetSelection) -> Option<PathBuf> {
Some(self.cxx.borrow()[&target].path().into()) Some(self.cxx.borrow()[&target].path().into())
} else if target != self.config.build } else if target != self.config.build
&& helpers::use_host_linker(target) && helpers::use_host_linker(target)
&& !target.contains("msvc") && !target.is_msvc()
{ {
Some(self.cc(target)) Some(self.cc(target))
} else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target { } else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
@ -1268,7 +1268,7 @@ fn linker(&self, target: TargetSelection) -> Option<PathBuf> {
// LLD is used through `-fuse-ld=lld` rather than directly. // LLD is used through `-fuse-ld=lld` rather than directly.
// Only MSVC targets use LLD directly at the moment. // Only MSVC targets use LLD directly at the moment.
fn is_fuse_ld_lld(&self, target: TargetSelection) -> bool { fn is_fuse_ld_lld(&self, target: TargetSelection) -> bool {
self.config.use_lld && !target.contains("msvc") self.config.use_lld && !target.is_msvc()
} }
fn lld_flags(&self, target: TargetSelection) -> impl Iterator<Item = String> { fn lld_flags(&self, target: TargetSelection) -> impl Iterator<Item = String> {
@ -1764,7 +1764,7 @@ fn ninja(&self) -> bool {
// In these cases we automatically enable Ninja if we find it in the // In these cases we automatically enable Ninja if we find it in the
// environment. // environment.
if !self.config.ninja_in_file if !self.config.ninja_in_file
&& self.config.build.contains("msvc") && self.config.build.is_msvc()
&& cmd_finder.maybe_have("ninja").is_some() && cmd_finder.maybe_have("ninja").is_some()
{ {
return true; return true;

View File

@ -39,7 +39,7 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
Some(PathBuf::from(ar)) Some(PathBuf::from(ar))
} else if let Some(ar) = env::var_os("AR") { } else if let Some(ar) = env::var_os("AR") {
Some(PathBuf::from(ar)) Some(PathBuf::from(ar))
} else if target.contains("msvc") { } else if target.is_msvc() {
None None
} else if target.contains("musl") { } else if target.contains("musl") {
Some(PathBuf::from("ar")) Some(PathBuf::from("ar"))
@ -78,7 +78,7 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
cfg.static_crt(a); cfg.static_crt(a);
} }
None => { None => {
if target.contains("msvc") { if target.is_msvc() {
cfg.static_crt(true); cfg.static_crt(true);
} }
if target.contains("musl") { if target.contains("musl") {