Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c520851

Browse files
committedDec 13, 2023
Add TargetSelection::is_windows method
1 parent 77d1699 commit c520851

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed
 

‎src/bootstrap/src/core/build_steps/dist.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ impl Step for CodegenBackend {
13191319
return None;
13201320
}
13211321

1322-
if self.compiler.host.contains("windows") {
1322+
if self.compiler.host.is_windows() {
13231323
builder.info(
13241324
"dist currently disabled for windows by rustc_codegen_cranelift. skipping",
13251325
);
@@ -1658,7 +1658,7 @@ impl Step for Extended {
16581658
builder.run(&mut cmd);
16591659
}
16601660

1661-
if target.contains("windows") {
1661+
if target.is_windows() {
16621662
let exe = tmp.join("exe");
16631663
let _ = fs::remove_dir_all(&exe);
16641664

‎src/bootstrap/src/core/build_steps/llvm.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl Step for Llvm {
283283
};
284284

285285
builder.update_submodule(&Path::new("src").join("llvm-project"));
286-
if builder.llvm_link_shared() && target.contains("windows") {
286+
if builder.llvm_link_shared() && target.is_windows() {
287287
panic!("shared linking to LLVM is not currently supported on {}", target.triple);
288288
}
289289

@@ -361,7 +361,7 @@ impl Step for Llvm {
361361
// Disable zstd to avoid a dependency on libzstd.so.
362362
cfg.define("LLVM_ENABLE_ZSTD", "OFF");
363363

364-
if !target.contains("windows") {
364+
if !target.is_windows() {
365365
cfg.define("LLVM_ENABLE_ZLIB", "ON");
366366
} else {
367367
cfg.define("LLVM_ENABLE_ZLIB", "OFF");
@@ -607,7 +607,7 @@ fn configure_cmake(
607607
cfg.define("CMAKE_SYSTEM_NAME", "DragonFly");
608608
} else if target.contains("freebsd") {
609609
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
610-
} else if target.contains("windows") {
610+
} else if target.is_windows() {
611611
cfg.define("CMAKE_SYSTEM_NAME", "Windows");
612612
} else if target.contains("haiku") {
613613
cfg.define("CMAKE_SYSTEM_NAME", "Haiku");
@@ -772,7 +772,7 @@ fn configure_cmake(
772772
&& !target.contains("netbsd")
773773
&& !target.contains("solaris")
774774
{
775-
if target.contains("apple") || target.contains("windows") {
775+
if target.contains("apple") || target.is_windows() {
776776
ldflags.push_all("-static-libstdc++");
777777
} else {
778778
ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++");
@@ -1295,7 +1295,7 @@ impl Step for Libunwind {
12951295
cfg.define("__LIBUNWIND_IS_NATIVE_ONLY", None);
12961296
cfg.define("NDEBUG", None);
12971297
}
1298-
if self.target.contains("windows") {
1298+
if self.target.is_windows() {
12991299
cfg.define("_LIBUNWIND_HIDE_SYMBOLS", "1");
13001300
cfg.define("_LIBUNWIND_IS_NATIVE_ONLY", "1");
13011301
}

‎src/bootstrap/src/core/builder.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1653,10 +1653,7 @@ impl<'a> Builder<'a> {
16531653
// flesh out rpath support more fully in the future.
16541654
rustflags.arg("-Zosx-rpath-install-name");
16551655
Some(format!("-Wl,-rpath,@loader_path/../{libdir}"))
1656-
} else if !target.contains("windows")
1657-
&& !target.contains("aix")
1658-
&& !target.contains("xous")
1659-
{
1656+
} else if !target.is_windows() && !target.contains("aix") && !target.contains("xous") {
16601657
rustflags.arg("-Clink-args=-Wl,-z,origin");
16611658
Some(format!("-Wl,-rpath,$ORIGIN/../{libdir}"))
16621659
} else {
@@ -1729,8 +1726,7 @@ impl<'a> Builder<'a> {
17291726
let split_debuginfo_is_stable = target.contains("linux")
17301727
|| target.contains("apple")
17311728
|| (target.is_msvc() && self.config.rust_split_debuginfo == SplitDebuginfo::Packed)
1732-
|| (target.contains("windows")
1733-
&& self.config.rust_split_debuginfo == SplitDebuginfo::Off);
1729+
|| (target.is_windows() && self.config.rust_split_debuginfo == SplitDebuginfo::Off);
17341730

17351731
if !split_debuginfo_is_stable {
17361732
rustflags.arg("-Zunstable-options");

‎src/bootstrap/src/core/config/config.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,10 @@ impl std::str::FromStr for SplitDebuginfo {
421421
impl SplitDebuginfo {
422422
/// Returns the default `-Csplit-debuginfo` value for the current target. See the comment for
423423
/// `rust.split-debuginfo` in `config.example.toml`.
424-
fn default_for_platform(target: &str) -> Self {
424+
fn default_for_platform(target: TargetSelection) -> Self {
425425
if target.contains("apple") {
426426
SplitDebuginfo::Unpacked
427-
} else if target.contains("windows") {
427+
} else if target.is_windows() {
428428
SplitDebuginfo::Packed
429429
} else {
430430
SplitDebuginfo::Off
@@ -527,6 +527,10 @@ impl TargetSelection {
527527
pub fn is_msvc(&self) -> bool {
528528
self.contains("msvc")
529529
}
530+
531+
pub fn is_windows(&self) -> bool {
532+
self.contains("windows")
533+
}
530534
}
531535

532536
impl fmt::Display for TargetSelection {
@@ -1595,7 +1599,7 @@ impl Config {
15951599
.as_deref()
15961600
.map(SplitDebuginfo::from_str)
15971601
.map(|v| v.expect("invalid value for rust.split_debuginfo"))
1598-
.unwrap_or(SplitDebuginfo::default_for_platform(&config.build.triple));
1602+
.unwrap_or(SplitDebuginfo::default_for_platform(config.build));
15991603
optimize = optimize_toml;
16001604
omit_git_hash = omit_git_hash_toml;
16011605
config.rust_new_symbol_mangling = new_symbol_mangling;

‎src/bootstrap/src/utils/helpers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub use t;
4949
/// Given an executable called `name`, return the filename for the
5050
/// executable for a particular target.
5151
pub fn exe(name: &str, target: TargetSelection) -> String {
52-
if target.contains("windows") {
52+
if target.is_windows() {
5353
format!("{name}.exe")
5454
} else if target.contains("uefi") {
5555
format!("{name}.efi")
@@ -72,7 +72,7 @@ pub fn is_debug_info(name: &str) -> bool {
7272
/// Returns the corresponding relative library directory that the compiler's
7373
/// dylibs will be found in.
7474
pub fn libdir(target: TargetSelection) -> &'static str {
75-
if target.contains("windows") { "bin" } else { "lib" }
75+
if target.is_windows() { "bin" } else { "lib" }
7676
}
7777

7878
/// Adds a list of lookup paths to `cmd`'s dynamic library lookup path.
@@ -191,7 +191,7 @@ pub fn target_supports_cranelift_backend(target: TargetSelection) -> bool {
191191
|| target.contains("aarch64")
192192
|| target.contains("s390x")
193193
|| target.contains("riscv64gc")
194-
} else if target.contains("darwin") || target.contains("windows") {
194+
} else if target.contains("darwin") || target.is_windows() {
195195
target.contains("x86_64")
196196
} else {
197197
false

0 commit comments

Comments
 (0)
Failed to load comments.