Skip to content

Commit

Permalink
Add is_msvc function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Dec 10, 2023
1 parent 42dfac5 commit b3c9ffd
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ impl Step for Rustc {
// 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/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");
}

Expand Down Expand Up @@ -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
// `__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 builder.config.llvm_profile_generate && target.is_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);
Expand All @@ -1114,7 +1114,7 @@ fn rustc_llvm_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetSelect
// not for MSVC or macOS
if builder.config.llvm_static_stdcpp
&& !target.contains("freebsd")
&& !target.contains("msvc")
&& !target.is_msvc()
&& !target.contains("apple")
&& !target.contains("solaris")
{
Expand Down
14 changes: 7 additions & 7 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ pub fn prebuilt_llvm_config(
let out_dir = builder.llvm_out(target);

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("bin");
Expand Down Expand Up @@ -411,7 +411,7 @@ impl Step for Llvm {
ldflags.shared.push(" -latomic");
}

if target.contains("msvc") {
if target.is_msvc() {
cfg.define("LLVM_USE_CRT_DEBUG", "MT");
cfg.define("LLVM_USE_CRT_RELEASE", "MT");
cfg.define("LLVM_USE_CRT_RELWITHDEBINFO", "MT");
Expand Down Expand Up @@ -644,7 +644,7 @@ fn configure_cmake(
}

let sanitize_cc = |cc: &Path| {
if target.contains("msvc") {
if target.is_msvc() {
OsString::from(cc.to_str().unwrap().replace("\\", "/"))
} else {
cc.as_os_str().to_owned()
Expand All @@ -654,7 +654,7 @@ fn configure_cmake(
// 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
// entirely.
if target.contains("msvc") && !builder.ninja() {
if target.is_msvc() && !builder.ninja() {
return;
}

Expand All @@ -664,7 +664,7 @@ fn configure_cmake(
};

// 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");
wrap_cc.set_file_name("sccache-plus-cl.exe");

Expand Down Expand Up @@ -768,7 +768,7 @@ fn configure_cmake(
// For distribution we want the LLVM tools to be *statically* linked to libstdc++.
// We also do this if the user explicitly requested static libstdc++.
if builder.config.llvm_static_stdcpp
&& !target.contains("msvc")
&& !target.is_msvc()
&& !target.contains("netbsd")
&& !target.contains("solaris")
{
Expand Down Expand Up @@ -874,7 +874,7 @@ impl Step for Lld {
// 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
// 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() {
// Find clang's runtime library directory and push that as a search path to the
// cmake linker flags.
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
//
// Note that if we encounter `PATH` we make sure to append to our own `PATH`
// 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() {
if k != "PATH" {
cmd.env(k, v);
Expand Down Expand Up @@ -3070,7 +3070,7 @@ impl Step for TestHelpers {
// We may have found various cross-compilers a little differently due to our
// extra configuration, so inform cc of these compilers. Note, though, that
// 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) {
cfg.archiver(ar);
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ impl<'a> Builder<'a> {
// 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
// so here.
if compiler.host.contains("msvc") {
if compiler.host.is_msvc() {
let curpaths = env::var_os("PATH").unwrap_or_default();
let curpaths = env::split_paths(&curpaths).collect::<Vec<_>>();
for &(ref k, ref v) in self.cc.borrow()[&compiler.host].env() {
Expand Down
5 changes: 2 additions & 3 deletions src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1729,8 +1729,7 @@ impl<'a> Builder<'a> {

let split_debuginfo_is_stable = target.contains("linux")
|| target.contains("apple")
|| (target.contains("msvc")
&& self.config.rust_split_debuginfo == SplitDebuginfo::Packed)
|| (target.is_msvc() && self.config.rust_split_debuginfo == SplitDebuginfo::Packed)
|| (target.contains("windows")
&& self.config.rust_split_debuginfo == SplitDebuginfo::Off);

Expand Down Expand Up @@ -1909,7 +1908,7 @@ impl<'a> Builder<'a> {
// the options through environment variables that are fetched and understood by both.
//
// 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 {
cargo.env("CC", cl).env("CXX", cl);
}
Expand Down
4 changes: 4 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ impl TargetSelection {
pub fn is_synthetic(&self) -> bool {
self.synthetic
}

pub fn is_msvc(&self) -> bool {
self.contains("msvc")
}
}

impl fmt::Display for TargetSelection {
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ than building it.
}
}

if need_cmake && target.contains("msvc") {
if need_cmake && target.is_msvc() {
// There are three builds of cmake on windows: MSVC, MinGW, and
// Cygwin. The Cygwin build does not have generators for Visual
// Studio, so detect that here and error.
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ impl Build {
}
} else {
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_release_debuginfo {
base.join("RelWithDebInfo")
Expand Down Expand Up @@ -1255,7 +1255,7 @@ impl Build {
Some(self.cxx.borrow()[&target].path().into())
} else if target != self.config.build
&& helpers::use_host_linker(target)
&& !target.contains("msvc")
&& !target.is_msvc()
{
Some(self.cc(target))
} else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
Expand All @@ -1268,7 +1268,7 @@ impl Build {
// LLD is used through `-fuse-ld=lld` rather than directly.
// Only MSVC targets use LLD directly at the moment.
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> {
Expand Down Expand Up @@ -1764,7 +1764,7 @@ to download LLVM rather than building it.
// In these cases we automatically enable Ninja if we find it in the
// environment.
if !self.config.ninja_in_file
&& self.config.build.contains("msvc")
&& self.config.build.is_msvc()
&& cmd_finder.maybe_have("ninja").is_some()
{
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/utils/cc_detect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn cc2ar(cc: &Path, target: TargetSelection) -> Option<PathBuf> {
Some(PathBuf::from(ar))
} else if let Some(ar) = env::var_os("AR") {
Some(PathBuf::from(ar))
} else if target.contains("msvc") {
} else if target.is_msvc() {
None
} else if target.contains("musl") {
Some(PathBuf::from("ar"))
Expand Down Expand Up @@ -78,7 +78,7 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
cfg.static_crt(a);
}
None => {
if target.contains("msvc") {
if target.is_msvc() {
cfg.static_crt(true);
}
if target.contains("musl") {
Expand Down

0 comments on commit b3c9ffd

Please sign in to comment.