Skip to content

Commit a66e5e5

Browse files
committed
Pick assembly files based on tools, not targets
When deciding whether to use MASM assembly files or the GNU assembly files it makes more sense to check the tool we're using to compile, as tools are what ultimately what decide which format is supported and accepted.
1 parent e1dc224 commit a66e5e5

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

psm/build.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@ fn find_assembly(
55
endian: &str,
66
os: &str,
77
env: &str,
8-
is_windows_host: bool,
8+
masm: bool,
99
) -> Option<(&'static str, bool)> {
1010
match (arch, endian, os, env) {
1111
// The implementations for stack switching exist, but, officially, doing so without Fibers
1212
// is not supported in Windows. For x86_64 the implementation actually works locally,
1313
// but failed tests in CI (???). Might want to have a feature for experimental support
1414
// here.
1515
("x86", _, "windows", "msvc") => {
16-
if is_windows_host {
16+
if masm {
1717
Some(("src/arch/x86_msvc.asm", false))
1818
} else {
1919
Some(("src/arch/x86_windows_gnu.s", false))
2020
}
2121
}
2222
("x86_64", _, "windows", "msvc") => {
23-
if is_windows_host {
23+
if masm {
2424
Some(("src/arch/x86_64_msvc.asm", false))
2525
} else {
2626
Some(("src/arch/x86_64_windows_gnu.s", false))
2727
}
2828
}
2929
("arm", _, "windows", "msvc") => Some(("src/arch/arm_armasm.asm", false)),
3030
("aarch64", _, "windows", "msvc") => {
31-
if is_windows_host {
31+
if masm {
3232
Some(("src/arch/aarch64_armasm.asm", false))
3333
} else {
3434
Some(("src/arch/aarch_aapcs64.s", false))
@@ -61,28 +61,6 @@ fn main() {
6161
let env = ::std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
6262
let os = ::std::env::var("CARGO_CFG_TARGET_OS").unwrap();
6363
let endian = ::std::env::var("CARGO_CFG_TARGET_ENDIAN").unwrap();
64-
// Handle cross compilation scenarios where we're using eg clang-cl
65-
// from a non-windows host, as by default cc will automatically try and
66-
// run the appropriate Microsoft assembler for the target architecture
67-
// if we give it a .asm file
68-
let is_windows_host = std::env::var("HOST")
69-
.unwrap_or_default()
70-
.contains("-windows-");
71-
72-
let asm =
73-
if let Some((asm, canswitch)) = find_assembly(&arch, &endian, &os, &env, is_windows_host) {
74-
println!("cargo:rustc-cfg=asm");
75-
if canswitch {
76-
println!("cargo:rustc-cfg=switchable_stack")
77-
}
78-
asm
79-
} else {
80-
println!(
81-
"cargo:warning=Target {}-{}-{} has no assembly files!",
82-
arch, os, env
83-
);
84-
return;
85-
};
8664

8765
// We are only assembling a single file and any flags in the environment probably
8866
// don't apply in this case, so we don't want to use them. Unfortunately, cc
@@ -95,13 +73,12 @@ fn main() {
9573
}
9674

9775
let mut cfg = cc::Build::new();
98-
9976
// There seems to be a bug with clang-cl where using
10077
// `/clang:-xassembler-with-cpp` is apparently accepted (ie no warnings
10178
// about unused/unknown arguments), but results in the same exact error
10279
// as if the flag was not present, so instead we take advantage of the
10380
// fact that we're not actually compiling any C/C++ code, only assembling
104-
// and can just use clang directly
81+
// and can just use clang directly.
10582
if cfg
10683
.get_compiler()
10784
.path()
@@ -114,6 +91,20 @@ fn main() {
11491
}
11592

11693
let msvc = cfg.get_compiler().is_like_msvc();
94+
let asm =
95+
if let Some((asm, canswitch)) = find_assembly(&arch, &endian, &os, &env, msvc) {
96+
println!("cargo:rustc-cfg=asm");
97+
if canswitch {
98+
println!("cargo:rustc-cfg=switchable_stack")
99+
}
100+
asm
101+
} else {
102+
println!(
103+
"cargo:warning=Target {}-{}-{} has no assembly files!",
104+
arch, os, env
105+
);
106+
return;
107+
};
117108

118109
if !msvc {
119110
cfg.flag("-xassembler-with-cpp");

0 commit comments

Comments
 (0)