Only provide is_windows_msvc to gate on windows-msvc
And not both `is_windows_msvc` and `is_msvc`.
This commit is contained in:
parent
200f132367
commit
87a41210d4
8 changed files with 29 additions and 34 deletions
|
|
@ -2,7 +2,7 @@
|
|||
//! libraries which are target-dependent.
|
||||
|
||||
use crate::target;
|
||||
use crate::targets::is_msvc;
|
||||
use crate::targets::is_windows_msvc;
|
||||
|
||||
/// Construct the static library name based on the target.
|
||||
#[track_caller]
|
||||
|
|
@ -10,7 +10,7 @@ use crate::targets::is_msvc;
|
|||
pub fn static_lib_name(name: &str) -> String {
|
||||
assert!(!name.contains(char::is_whitespace), "static library name cannot contain whitespace");
|
||||
|
||||
if is_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
|
||||
if is_windows_msvc() { format!("{name}.lib") } else { format!("lib{name}.a") }
|
||||
}
|
||||
|
||||
/// Construct the dynamic library name based on the target.
|
||||
|
|
@ -45,7 +45,7 @@ pub fn dynamic_lib_extension() -> &'static str {
|
|||
#[track_caller]
|
||||
#[must_use]
|
||||
pub fn msvc_import_dynamic_lib_name(name: &str) -> String {
|
||||
assert!(is_msvc(), "this function is exclusive to MSVC");
|
||||
assert!(is_windows_msvc(), "this function is exclusive to MSVC");
|
||||
assert!(!name.contains(char::is_whitespace), "import library name cannot contain whitespace");
|
||||
|
||||
format!("{name}.dll.lib")
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::artifact_names::{dynamic_lib_name, static_lib_name};
|
|||
use crate::external_deps::c_cxx_compiler::{cc, cxx};
|
||||
use crate::external_deps::llvm::llvm_ar;
|
||||
use crate::path_helpers::path;
|
||||
use crate::targets::{is_darwin, is_msvc, is_windows};
|
||||
use crate::targets::{is_darwin, is_windows, is_windows_msvc};
|
||||
|
||||
// FIXME(Oneirical): These native build functions should take a Path-based generic.
|
||||
|
||||
|
|
@ -24,12 +24,12 @@ pub fn build_native_static_lib_optimized(lib_name: &str) -> PathBuf {
|
|||
|
||||
#[track_caller]
|
||||
fn build_native_static_lib_internal(lib_name: &str, optimzed: bool) -> PathBuf {
|
||||
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
|
||||
let obj_file = if is_windows_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
|
||||
let src = format!("{lib_name}.c");
|
||||
let lib_path = static_lib_name(lib_name);
|
||||
|
||||
let mut cc = cc();
|
||||
if !is_msvc() {
|
||||
if !is_windows_msvc() {
|
||||
cc.arg("-v");
|
||||
}
|
||||
if optimzed {
|
||||
|
|
@ -37,7 +37,7 @@ fn build_native_static_lib_internal(lib_name: &str, optimzed: bool) -> PathBuf {
|
|||
}
|
||||
cc.arg("-c").out_exe(&obj_file).input(src).optimize().run();
|
||||
|
||||
let obj_file = if is_msvc() {
|
||||
let obj_file = if is_windows_msvc() {
|
||||
PathBuf::from(format!("{lib_name}.obj"))
|
||||
} else {
|
||||
PathBuf::from(format!("{lib_name}.o"))
|
||||
|
|
@ -50,16 +50,17 @@ fn build_native_static_lib_internal(lib_name: &str, optimzed: bool) -> PathBuf {
|
|||
/// [`std::env::consts::DLL_PREFIX`] and [`std::env::consts::DLL_EXTENSION`].
|
||||
#[track_caller]
|
||||
pub fn build_native_dynamic_lib(lib_name: &str) -> PathBuf {
|
||||
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
|
||||
let obj_file = if is_windows_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
|
||||
let src = format!("{lib_name}.c");
|
||||
let lib_path = dynamic_lib_name(lib_name);
|
||||
if is_msvc() {
|
||||
if is_windows_msvc() {
|
||||
cc().arg("-c").out_exe(&obj_file).input(src).run();
|
||||
} else {
|
||||
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
|
||||
};
|
||||
let obj_file = if is_msvc() { format!("{lib_name}.obj") } else { format!("{lib_name}.o") };
|
||||
if is_msvc() {
|
||||
let obj_file =
|
||||
if is_windows_msvc() { format!("{lib_name}.obj") } else { format!("{lib_name}.o") };
|
||||
if is_windows_msvc() {
|
||||
let out_arg = format!("-out:{lib_path}");
|
||||
cc().input(&obj_file).args(&["-link", "-dll", &out_arg]).run();
|
||||
} else if is_darwin() {
|
||||
|
|
@ -79,15 +80,15 @@ pub fn build_native_dynamic_lib(lib_name: &str) -> PathBuf {
|
|||
/// Built from a C++ file.
|
||||
#[track_caller]
|
||||
pub fn build_native_static_lib_cxx(lib_name: &str) -> PathBuf {
|
||||
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
|
||||
let obj_file = if is_windows_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
|
||||
let src = format!("{lib_name}.cpp");
|
||||
let lib_path = static_lib_name(lib_name);
|
||||
if is_msvc() {
|
||||
if is_windows_msvc() {
|
||||
cxx().arg("-EHs").arg("-c").out_exe(&obj_file).input(src).run();
|
||||
} else {
|
||||
cxx().arg("-c").out_exe(&obj_file).input(src).run();
|
||||
};
|
||||
let obj_file = if is_msvc() {
|
||||
let obj_file = if is_windows_msvc() {
|
||||
PathBuf::from(format!("{lib_name}.obj"))
|
||||
} else {
|
||||
PathBuf::from(format!("{lib_name}.o"))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use std::path::Path;
|
||||
|
||||
use crate::command::Command;
|
||||
use crate::{env_var, is_msvc};
|
||||
use crate::{env_var, is_windows_msvc};
|
||||
|
||||
/// Construct a new platform-specific C compiler invocation.
|
||||
///
|
||||
|
|
@ -82,7 +82,7 @@ impl Cc {
|
|||
pub fn out_exe(&mut self, name: &str) -> &mut Self {
|
||||
let mut path = std::path::PathBuf::from(name);
|
||||
|
||||
if is_msvc() {
|
||||
if is_windows_msvc() {
|
||||
path.set_extension("exe");
|
||||
let fe_path = path.clone();
|
||||
path.set_extension("");
|
||||
|
|
@ -108,7 +108,7 @@ impl Cc {
|
|||
/// Optimize the output.
|
||||
/// Equivalent to `-O3` for GNU-compatible linkers or `-O2` for MSVC linkers.
|
||||
pub fn optimize(&mut self) -> &mut Self {
|
||||
if is_msvc() {
|
||||
if is_windows_msvc() {
|
||||
self.cmd.arg("-O2");
|
||||
} else {
|
||||
self.cmd.arg("-O3");
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::{is_msvc, is_win7, is_windows, uname};
|
||||
use crate::{is_win7, is_windows, is_windows_msvc, uname};
|
||||
|
||||
/// `EXTRACFLAGS`
|
||||
pub fn extra_c_flags() -> Vec<&'static str> {
|
||||
if is_windows() {
|
||||
if is_msvc() {
|
||||
if is_windows_msvc() {
|
||||
let mut libs =
|
||||
vec!["ws2_32.lib", "userenv.lib", "bcrypt.lib", "ntdll.lib", "synchronization.lib"];
|
||||
if is_win7() {
|
||||
|
|
@ -29,7 +29,7 @@ pub fn extra_c_flags() -> Vec<&'static str> {
|
|||
/// `EXTRACXXFLAGS`
|
||||
pub fn extra_cxx_flags() -> Vec<&'static str> {
|
||||
if is_windows() {
|
||||
if is_msvc() { vec![] } else { vec!["-lstdc++"] }
|
||||
if is_windows_msvc() { vec![] } else { vec!["-lstdc++"] }
|
||||
} else {
|
||||
match &uname()[..] {
|
||||
"Darwin" => vec!["-lc++"],
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::command::Command;
|
|||
use crate::env::env_var;
|
||||
use crate::path_helpers::cwd;
|
||||
use crate::util::set_host_compiler_dylib_path;
|
||||
use crate::{is_aix, is_darwin, is_msvc, is_windows, target, uname};
|
||||
use crate::{is_aix, is_darwin, is_windows, is_windows_msvc, target, uname};
|
||||
|
||||
/// Construct a new `rustc` invocation. This will automatically set the library
|
||||
/// search path as `-L cwd()`. Use [`bare_rustc`] to avoid this.
|
||||
|
|
@ -377,7 +377,7 @@ impl Rustc {
|
|||
// So we end up with the following hack: we link use static:-bundle to only
|
||||
// link the parts of libstdc++ that we actually use, which doesn't include
|
||||
// the dependency on the pthreads DLL.
|
||||
if !is_msvc() {
|
||||
if !is_windows_msvc() {
|
||||
self.cmd.arg("-lstatic:-bundle=stdc++");
|
||||
};
|
||||
} else if is_darwin() {
|
||||
|
|
|
|||
|
|
@ -83,6 +83,6 @@ pub use crate::string::{
|
|||
};
|
||||
// Helpers for checking target information.
|
||||
pub use crate::targets::{
|
||||
apple_os, is_aix, is_darwin, is_msvc, is_win7, is_windows, is_windows_gnu, is_windows_msvc,
|
||||
apple_os, is_aix, is_darwin, is_win7, is_windows, is_windows_gnu, is_windows_msvc,
|
||||
llvm_components_contain, target, uname,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use regex::Regex;
|
||||
|
||||
use crate::{Rustc, is_msvc};
|
||||
use crate::{Rustc, is_windows_msvc};
|
||||
|
||||
/// Asserts that `rustc` uses LLD for linking when executed.
|
||||
pub fn assert_rustc_uses_lld(rustc: &mut Rustc) {
|
||||
|
|
@ -22,7 +22,7 @@ pub fn assert_rustc_doesnt_use_lld(rustc: &mut Rustc) {
|
|||
|
||||
fn get_stderr_with_linker_messages(rustc: &mut Rustc) -> String {
|
||||
// lld-link is used if msvc, otherwise a gnu-compatible lld is used.
|
||||
let linker_version_flag = if is_msvc() { "--version" } else { "-Wl,-v" };
|
||||
let linker_version_flag = if is_windows_msvc() { "--version" } else { "-Wl,-v" };
|
||||
|
||||
let output = rustc.arg("-Wlinker-messages").link_arg(linker_version_flag).run();
|
||||
output.stderr_utf8()
|
||||
|
|
|
|||
|
|
@ -16,10 +16,10 @@ pub fn is_windows() -> bool {
|
|||
target().contains("windows")
|
||||
}
|
||||
|
||||
/// Check if target uses msvc.
|
||||
/// Check if target is windows-msvc.
|
||||
#[must_use]
|
||||
pub fn is_msvc() -> bool {
|
||||
target().contains("msvc")
|
||||
pub fn is_windows_msvc() -> bool {
|
||||
target().ends_with("windows-msvc")
|
||||
}
|
||||
|
||||
/// Check if target is windows-gnu.
|
||||
|
|
@ -28,12 +28,6 @@ pub fn is_windows_gnu() -> bool {
|
|||
target().ends_with("windows-gnu")
|
||||
}
|
||||
|
||||
/// Check if target is windows-msvc.
|
||||
#[must_use]
|
||||
pub fn is_windows_msvc() -> bool {
|
||||
target().ends_with("windows-msvc")
|
||||
}
|
||||
|
||||
/// Check if target is win7.
|
||||
#[must_use]
|
||||
pub fn is_win7() -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue