Skip to content

Commit a4faeb8

Browse files
committed
Add is_msvc function
1 parent 4e65081 commit a4faeb8

File tree

9 files changed

+26
-25
lines changed

9 files changed

+26
-25
lines changed

src/bootstrap/builder.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,8 +1711,7 @@ impl<'a> Builder<'a> {
17111711

17121712
let split_debuginfo_is_stable = target.contains("linux")
17131713
|| target.contains("apple")
1714-
|| (target.contains("msvc")
1715-
&& self.config.rust_split_debuginfo == SplitDebuginfo::Packed)
1714+
|| (target.is_msvc() && self.config.rust_split_debuginfo == SplitDebuginfo::Packed)
17161715
|| (target.contains("windows")
17171716
&& self.config.rust_split_debuginfo == SplitDebuginfo::Off);
17181717

@@ -1877,7 +1876,7 @@ impl<'a> Builder<'a> {
18771876
// the options through environment variables that are fetched and understood by both.
18781877
//
18791878
// FIXME: the guard against msvc shouldn't need to be here
1880-
if target.contains("msvc") {
1879+
if target.is_msvc() {
18811880
if let Some(ref cl) = self.config.llvm_clang_cl {
18821881
cargo.env("CC", cl).env("CXX", cl);
18831882
}

src/bootstrap/cc_detect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
3939
Some(PathBuf::from(ar))
4040
} else if let Some(ar) = env::var_os("AR") {
4141
Some(PathBuf::from(ar))
42-
} else if target.contains("msvc") {
42+
} else if target.is_msvc() {
4343
None
4444
} else if target.contains("musl") {
4545
Some(PathBuf::from("ar"))
@@ -78,7 +78,7 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
7878
cfg.static_crt(a);
7979
}
8080
None => {
81-
if target.contains("msvc") {
81+
if target.is_msvc() {
8282
cfg.static_crt(true);
8383
}
8484
if target.contains("musl") {

src/bootstrap/compile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ impl Step for Rustc {
822822
// is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
823823
// https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
824824
// https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827
825-
if builder.config.use_lld && !compiler.host.contains("msvc") {
825+
if builder.config.use_lld && !compiler.host.is_msvc() {
826826
cargo.rustflag("-Clink-args=-Wl,--icf=all");
827827
}
828828

@@ -1026,7 +1026,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
10261026
// found. This is to avoid the linker errors about undefined references to
10271027
// `__llvm_profile_instrument_memop` when linking `rustc_driver`.
10281028
let mut llvm_linker_flags = String::new();
1029-
if builder.config.llvm_profile_generate && target.contains("msvc") {
1029+
if builder.config.llvm_profile_generate && target.is_msvc() {
10301030
if let Some(ref clang_cl_path) = builder.config.llvm_clang_cl {
10311031
// Add clang's runtime library directory to the search path
10321032
let clang_rt_dir = get_clang_cl_resource_dir(clang_cl_path);
@@ -1051,7 +1051,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
10511051
// not for MSVC or macOS
10521052
if builder.config.llvm_static_stdcpp
10531053
&& !target.contains("freebsd")
1054-
&& !target.contains("msvc")
1054+
&& !target.is_msvc()
10551055
&& !target.contains("apple")
10561056
&& !target.contains("solaris")
10571057
{

src/bootstrap/config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ impl TargetSelection {
491491
pub fn is_synthetic(&self) -> bool {
492492
self.synthetic
493493
}
494+
495+
pub fn is_msvc(&self) -> bool {
496+
self.contains("msvc")
497+
}
494498
}
495499

496500
impl fmt::Display for TargetSelection {

src/bootstrap/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ impl Build {
905905
}
906906
} else {
907907
let base = self.llvm_out(target).join("build");
908-
let base = if !self.ninja() && target.contains("msvc") {
908+
let base = if !self.ninja() && target.is_msvc() {
909909
if self.config.llvm_optimize {
910910
if self.config.llvm_release_debuginfo {
911911
base.join("RelWithDebInfo")
@@ -1249,9 +1249,7 @@ impl Build {
12491249
// need to use CXX compiler as linker to resolve the exception functions
12501250
// that are only existed in CXX libraries
12511251
Some(self.cxx.borrow()[&target].path().into())
1252-
} else if target != self.config.build
1253-
&& util::use_host_linker(target)
1254-
&& !target.contains("msvc")
1252+
} else if target != self.config.build && util::use_host_linker(target) && !target.is_msvc()
12551253
{
12561254
Some(self.cc(target))
12571255
} else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
@@ -1264,7 +1262,7 @@ impl Build {
12641262
// LLD is used through `-fuse-ld=lld` rather than directly.
12651263
// Only MSVC targets use LLD directly at the moment.
12661264
fn is_fuse_ld_lld(&self, target: TargetSelection) -> bool {
1267-
self.config.use_lld && !target.contains("msvc")
1265+
self.config.use_lld && !target.is_msvc()
12681266
}
12691267

12701268
fn lld_flags(&self, target: TargetSelection) -> impl Iterator<Item = String> {
@@ -1760,7 +1758,7 @@ to download LLVM rather than building it.
17601758
// In these cases we automatically enable Ninja if we find it in the
17611759
// environment.
17621760
if !self.config.ninja_in_file
1763-
&& self.config.build.contains("msvc")
1761+
&& self.config.build.is_msvc()
17641762
&& cmd_finder.maybe_have("ninja").is_some()
17651763
{
17661764
return true;

src/bootstrap/llvm.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn prebuilt_llvm_config(
9898
let out_dir = builder.llvm_out(target);
9999

100100
let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build);
101-
if !builder.config.build.contains("msvc") || builder.ninja() {
101+
if !builder.config.build.is_msvc() || builder.ninja() {
102102
llvm_config_ret_dir.push("build");
103103
}
104104
llvm_config_ret_dir.push("bin");
@@ -397,7 +397,7 @@ impl Step for Llvm {
397397
ldflags.shared.push(" -latomic");
398398
}
399399

400-
if target.contains("msvc") {
400+
if target.is_msvc() {
401401
cfg.define("LLVM_USE_CRT_DEBUG", "MT");
402402
cfg.define("LLVM_USE_CRT_RELEASE", "MT");
403403
cfg.define("LLVM_USE_CRT_RELWITHDEBINFO", "MT");
@@ -626,7 +626,7 @@ fn configure_cmake(
626626
}
627627

628628
let sanitize_cc = |cc: &Path| {
629-
if target.contains("msvc") {
629+
if target.is_msvc() {
630630
OsString::from(cc.to_str().unwrap().replace("\\", "/"))
631631
} else {
632632
cc.as_os_str().to_owned()
@@ -636,7 +636,7 @@ fn configure_cmake(
636636
// MSVC with CMake uses msbuild by default which doesn't respect these
637637
// vars that we'd otherwise configure. In that case we just skip this
638638
// entirely.
639-
if target.contains("msvc") && !builder.ninja() {
639+
if target.is_msvc() && !builder.ninja() {
640640
return;
641641
}
642642

@@ -646,7 +646,7 @@ fn configure_cmake(
646646
};
647647

648648
// Handle msvc + ninja + ccache specially (this is what the bots use)
649-
if target.contains("msvc") && builder.ninja() && builder.config.ccache.is_some() {
649+
if target.is_msvc() && builder.ninja() && builder.config.ccache.is_some() {
650650
let mut wrap_cc = env::current_exe().expect("failed to get cwd");
651651
wrap_cc.set_file_name("sccache-plus-cl.exe");
652652

@@ -750,7 +750,7 @@ fn configure_cmake(
750750
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
751751
// We also do this if the user explicitly requested static libstdc++.
752752
if builder.config.llvm_static_stdcpp
753-
&& !target.contains("msvc")
753+
&& !target.is_msvc()
754754
&& !target.contains("netbsd")
755755
&& !target.contains("solaris")
756756
{
@@ -856,7 +856,7 @@ impl Step for Lld {
856856
// when doing PGO on CI, cmake or clang-cl don't automatically link clang's
857857
// profiler runtime in. In that case, we need to manually ask cmake to do it, to avoid
858858
// linking errors, much like LLVM's cmake setup does in that situation.
859-
if builder.config.llvm_profile_generate && target.contains("msvc") {
859+
if builder.config.llvm_profile_generate && target.is_msvc() {
860860
if let Some(clang_cl_path) = builder.config.llvm_clang_cl.as_ref() {
861861
// Find clang's runtime library directory and push that as a search path to the
862862
// cmake linker flags.

src/bootstrap/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ than building it.
237237
}
238238
}
239239

240-
if need_cmake && target.contains("msvc") {
240+
if need_cmake && target.is_msvc() {
241241
// There are three builds of cmake on windows: MSVC, MinGW, and
242242
// Cygwin. The Cygwin build does not have generators for Visual
243243
// Studio, so detect that here and error.

src/bootstrap/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,7 +1818,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
18181818
//
18191819
// Note that if we encounter `PATH` we make sure to append to our own `PATH`
18201820
// rather than stomp over it.
1821-
if !builder.config.dry_run() && target.contains("msvc") {
1821+
if !builder.config.dry_run() && target.is_msvc() {
18221822
for &(ref k, ref v) in builder.cc.borrow()[&target].env() {
18231823
if k != "PATH" {
18241824
cmd.env(k, v);
@@ -2948,7 +2948,7 @@ impl Step for TestHelpers {
29482948
// We may have found various cross-compilers a little differently due to our
29492949
// extra configuration, so inform cc of these compilers. Note, though, that
29502950
// on MSVC we still need cc's detection of env vars (ugh).
2951-
if !target.contains("msvc") {
2951+
if !target.is_msvc() {
29522952
if let Some(ar) = builder.ar(target) {
29532953
cfg.archiver(ar);
29542954
}

src/bootstrap/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl<'a> Builder<'a> {
823823
// On MSVC a tool may invoke a C compiler (e.g., compiletest in run-make
824824
// mode) and that C compiler may need some extra PATH modification. Do
825825
// so here.
826-
if compiler.host.contains("msvc") {
826+
if compiler.host.is_msvc() {
827827
let curpaths = env::var_os("PATH").unwrap_or_default();
828828
let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
829829
for &(ref k, ref v) in self.cc.borrow()[&compiler.host].env() {

0 commit comments

Comments
 (0)