From c5208518faa423b96e6d1fecaa6428a2fa4eb9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 13 Dec 2023 07:47:25 +0100 Subject: [PATCH] Add `TargetSelection::is_windows` method --- src/bootstrap/src/core/build_steps/dist.rs | 4 ++-- src/bootstrap/src/core/build_steps/llvm.rs | 10 +++++----- src/bootstrap/src/core/builder.rs | 8 ++------ src/bootstrap/src/core/config/config.rs | 10 +++++++--- src/bootstrap/src/utils/helpers.rs | 6 +++--- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index c485481b9a1..98e267713da 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -1319,7 +1319,7 @@ fn run(self, builder: &Builder<'_>) -> Option { return None; } - if self.compiler.host.contains("windows") { + if self.compiler.host.is_windows() { builder.info( "dist currently disabled for windows by rustc_codegen_cranelift. skipping", ); @@ -1658,7 +1658,7 @@ fn filter(contents: &str, marker: &str) -> String { builder.run(&mut cmd); } - if target.contains("windows") { + if target.is_windows() { let exe = tmp.join("exe"); let _ = fs::remove_dir_all(&exe); diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 8de208cd09c..4b2d3e9ab4b 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -283,7 +283,7 @@ fn run(self, builder: &Builder<'_>) -> LlvmResult { }; builder.update_submodule(&Path::new("src").join("llvm-project")); - if builder.llvm_link_shared() && target.contains("windows") { + if builder.llvm_link_shared() && target.is_windows() { panic!("shared linking to LLVM is not currently supported on {}", target.triple); } @@ -361,7 +361,7 @@ fn run(self, builder: &Builder<'_>) -> LlvmResult { // Disable zstd to avoid a dependency on libzstd.so. cfg.define("LLVM_ENABLE_ZSTD", "OFF"); - if !target.contains("windows") { + if !target.is_windows() { cfg.define("LLVM_ENABLE_ZLIB", "ON"); } else { cfg.define("LLVM_ENABLE_ZLIB", "OFF"); @@ -607,7 +607,7 @@ fn configure_cmake( cfg.define("CMAKE_SYSTEM_NAME", "DragonFly"); } else if target.contains("freebsd") { cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD"); - } else if target.contains("windows") { + } else if target.is_windows() { cfg.define("CMAKE_SYSTEM_NAME", "Windows"); } else if target.contains("haiku") { cfg.define("CMAKE_SYSTEM_NAME", "Haiku"); @@ -772,7 +772,7 @@ fn configure_cmake( && !target.contains("netbsd") && !target.contains("solaris") { - if target.contains("apple") || target.contains("windows") { + if target.contains("apple") || target.is_windows() { ldflags.push_all("-static-libstdc++"); } else { ldflags.push_all("-Wl,-Bsymbolic -static-libstdc++"); @@ -1295,7 +1295,7 @@ fn run(self, builder: &Builder<'_>) -> Self::Output { cfg.define("__LIBUNWIND_IS_NATIVE_ONLY", None); cfg.define("NDEBUG", None); } - if self.target.contains("windows") { + if self.target.is_windows() { cfg.define("_LIBUNWIND_HIDE_SYMBOLS", "1"); cfg.define("_LIBUNWIND_IS_NATIVE_ONLY", "1"); } diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 054c3ab14c0..28761a7ee4b 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -1653,10 +1653,7 @@ pub fn cargo( // flesh out rpath support more fully in the future. rustflags.arg("-Zosx-rpath-install-name"); Some(format!("-Wl,-rpath,@loader_path/../{libdir}")) - } else if !target.contains("windows") - && !target.contains("aix") - && !target.contains("xous") - { + } else if !target.is_windows() && !target.contains("aix") && !target.contains("xous") { rustflags.arg("-Clink-args=-Wl,-z,origin"); Some(format!("-Wl,-rpath,$ORIGIN/../{libdir}")) } else { @@ -1729,8 +1726,7 @@ pub fn cargo( let split_debuginfo_is_stable = target.contains("linux") || target.contains("apple") || (target.is_msvc() && self.config.rust_split_debuginfo == SplitDebuginfo::Packed) - || (target.contains("windows") - && self.config.rust_split_debuginfo == SplitDebuginfo::Off); + || (target.is_windows() && self.config.rust_split_debuginfo == SplitDebuginfo::Off); if !split_debuginfo_is_stable { rustflags.arg("-Zunstable-options"); diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index c3db5641ea4..ff51760e193 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -421,10 +421,10 @@ fn from_str(s: &str) -> Result { impl SplitDebuginfo { /// Returns the default `-Csplit-debuginfo` value for the current target. See the comment for /// `rust.split-debuginfo` in `config.example.toml`. - fn default_for_platform(target: &str) -> Self { + fn default_for_platform(target: TargetSelection) -> Self { if target.contains("apple") { SplitDebuginfo::Unpacked - } else if target.contains("windows") { + } else if target.is_windows() { SplitDebuginfo::Packed } else { SplitDebuginfo::Off @@ -527,6 +527,10 @@ pub fn is_synthetic(&self) -> bool { pub fn is_msvc(&self) -> bool { self.contains("msvc") } + + pub fn is_windows(&self) -> bool { + self.contains("windows") + } } impl fmt::Display for TargetSelection { @@ -1595,7 +1599,7 @@ fn get_table(option: &str) -> Result { .as_deref() .map(SplitDebuginfo::from_str) .map(|v| v.expect("invalid value for rust.split_debuginfo")) - .unwrap_or(SplitDebuginfo::default_for_platform(&config.build.triple)); + .unwrap_or(SplitDebuginfo::default_for_platform(config.build)); optimize = optimize_toml; omit_git_hash = omit_git_hash_toml; config.rust_new_symbol_mangling = new_symbol_mangling; diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index 133792d85e8..f1ce5c92f78 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -49,7 +49,7 @@ macro_rules! t { /// Given an executable called `name`, return the filename for the /// executable for a particular target. pub fn exe(name: &str, target: TargetSelection) -> String { - if target.contains("windows") { + if target.is_windows() { format!("{name}.exe") } else if target.contains("uefi") { format!("{name}.efi") @@ -72,7 +72,7 @@ pub fn is_debug_info(name: &str) -> bool { /// Returns the corresponding relative library directory that the compiler's /// dylibs will be found in. pub fn libdir(target: TargetSelection) -> &'static str { - if target.contains("windows") { "bin" } else { "lib" } + if target.is_windows() { "bin" } else { "lib" } } /// 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 { || target.contains("aarch64") || target.contains("s390x") || target.contains("riscv64gc") - } else if target.contains("darwin") || target.contains("windows") { + } else if target.contains("darwin") || target.is_windows() { target.contains("x86_64") } else { false