Skip to content

Commit b46237b

Browse files
committed
Enable msvc for zero-extend-abi-param-passing
1 parent 64ebd39 commit b46237b

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

src/tools/run-make-support/src/external_deps/c_build.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,31 @@ use crate::targets::{is_darwin, is_msvc, is_windows};
1313
/// Built from a C file.
1414
#[track_caller]
1515
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
16+
build_native_static_lib_internal(lib_name, false)
17+
}
18+
19+
/// Builds an optimized static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
20+
/// Built from a C file.
21+
#[track_caller]
22+
pub fn build_native_static_lib_optimized(lib_name: &str) -> PathBuf {
23+
build_native_static_lib_internal(lib_name, true)
24+
}
25+
26+
#[track_caller]
27+
fn build_native_static_lib_internal(lib_name: &str, optimzed: bool) -> PathBuf {
1628
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
1729
let src = format!("{lib_name}.c");
1830
let lib_path = static_lib_name(lib_name);
19-
if is_msvc() {
20-
cc().arg("-c").out_exe(&obj_file).input(src).run();
21-
} else {
22-
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
23-
};
31+
32+
let mut cc = cc();
33+
if !is_msvc() {
34+
cc.arg("-v");
35+
}
36+
if optimzed {
37+
cc.optimize();
38+
}
39+
cc.arg("-c").out_exe(&obj_file).input(src).optimize().run();
40+
2441
let obj_file = if is_msvc() {
2542
PathBuf::from(format!("{lib_name}.obj"))
2643
} else {

src/tools/run-make-support/src/external_deps/cc.rs

+11
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,17 @@ impl Cc {
117117
self.cmd.arg(path.as_ref());
118118
self
119119
}
120+
121+
/// Optimize the output.
122+
/// Equivalent to `-O3` for GNU-compatible linkers or `-O2` for MSVC linkers.
123+
pub fn optimize(&mut self) -> &mut Self {
124+
if is_msvc() {
125+
self.cmd.arg("-O2");
126+
} else {
127+
self.cmd.arg("-O3");
128+
}
129+
self
130+
}
120131
}
121132

122133
/// `EXTRACFLAGS`

src/tools/run-make-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rust
4545

4646
// These rely on external dependencies.
4747
pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
48-
pub use c_build::{build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_cxx};
48+
pub use c_build::{build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_optimized, build_native_static_lib_cxx};
4949
pub use clang::{clang, Clang};
5050
pub use htmldocck::htmldocck;
5151
pub use llvm::{

tests/run-make/zero-extend-abi-param-passing/param_passing.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// LLVM optimization choices. See additional note below for an
33
// example.
44

5-
#[link(name = "bad")]
5+
#[link(name = "bad", kind = "static")]
66
extern "C" {
77
pub fn c_read_value(a: u32, b: u32, c: u32) -> u16;
88
}

tests/run-make/zero-extend-abi-param-passing/rmake.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,13 @@
66
// while simultaneously interfacing with a C library and using the -O3 flag.
77
// See https://github.com/rust-lang/rust/issues/97463
88

9-
//@ ignore-msvc
10-
// Reason: the rustc compilation fails due to an unresolved external symbol
11-
129
//@ ignore-cross-compile
1310
// Reason: The compiled binary is executed.
14-
15-
use run_make_support::{cc, is_msvc, llvm_ar, run, rustc, static_lib_name};
11+
use run_make_support::{build_native_static_lib_optimized, run, rustc};
1612

1713
fn main() {
18-
// The issue exercised by this test specifically needs needs `-O`
19-
// flags (like `-O3`) to reproduce. Thus, we call `cc()` instead of
20-
// the nicer `build_native_static_lib`.
21-
cc().arg("-c").arg("-O3").out_exe("bad.o").input("bad.c").run();
22-
llvm_ar().obj_to_ar().output_input(static_lib_name("bad"), "bad.o").run();
23-
rustc().input("param_passing.rs").arg("-lbad").opt_level("3").run();
14+
// The issue exercised by this test specifically needs an optimized native static lib.
15+
build_native_static_lib_optimized("bad");
16+
rustc().input("param_passing.rs").opt_level("3").run();
2417
run("param_passing");
2518
}

0 commit comments

Comments
 (0)