Enable msvc for zero-extend-abi-param-passing
This commit is contained in:
parent
64ebd39da5
commit
b46237bdd7
@ -13,14 +13,31 @@
|
|||||||
/// Built from a C file.
|
/// Built from a C file.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
|
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
|
||||||
|
build_native_static_lib_internal(lib_name, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Builds an optimized static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
|
||||||
|
/// Built from a C file.
|
||||||
|
#[track_caller]
|
||||||
|
pub fn build_native_static_lib_optimized(lib_name: &str) -> PathBuf {
|
||||||
|
build_native_static_lib_internal(lib_name, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[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_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
|
||||||
let src = format!("{lib_name}.c");
|
let src = format!("{lib_name}.c");
|
||||||
let lib_path = static_lib_name(lib_name);
|
let lib_path = static_lib_name(lib_name);
|
||||||
if is_msvc() {
|
|
||||||
cc().arg("-c").out_exe(&obj_file).input(src).run();
|
let mut cc = cc();
|
||||||
} else {
|
if !is_msvc() {
|
||||||
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
|
cc.arg("-v");
|
||||||
};
|
}
|
||||||
|
if optimzed {
|
||||||
|
cc.optimize();
|
||||||
|
}
|
||||||
|
cc.arg("-c").out_exe(&obj_file).input(src).optimize().run();
|
||||||
|
|
||||||
let obj_file = if is_msvc() {
|
let obj_file = if is_msvc() {
|
||||||
PathBuf::from(format!("{lib_name}.obj"))
|
PathBuf::from(format!("{lib_name}.obj"))
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,6 +117,17 @@ pub fn output<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
|||||||
self.cmd.arg(path.as_ref());
|
self.cmd.arg(path.as_ref());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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() {
|
||||||
|
self.cmd.arg("-O2");
|
||||||
|
} else {
|
||||||
|
self.cmd.arg("-O3");
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `EXTRACFLAGS`
|
/// `EXTRACFLAGS`
|
||||||
|
@ -45,7 +45,7 @@ pub mod rfs {
|
|||||||
|
|
||||||
// These rely on external dependencies.
|
// These rely on external dependencies.
|
||||||
pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
|
pub use cc::{cc, cxx, extra_c_flags, extra_cxx_flags, Cc};
|
||||||
pub use c_build::{build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_cxx};
|
pub use c_build::{build_native_dynamic_lib, build_native_static_lib, build_native_static_lib_optimized, build_native_static_lib_cxx};
|
||||||
pub use clang::{clang, Clang};
|
pub use clang::{clang, Clang};
|
||||||
pub use htmldocck::htmldocck;
|
pub use htmldocck::htmldocck;
|
||||||
pub use llvm::{
|
pub use llvm::{
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// LLVM optimization choices. See additional note below for an
|
// LLVM optimization choices. See additional note below for an
|
||||||
// example.
|
// example.
|
||||||
|
|
||||||
#[link(name = "bad")]
|
#[link(name = "bad", kind = "static")]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn c_read_value(a: u32, b: u32, c: u32) -> u16;
|
pub fn c_read_value(a: u32, b: u32, c: u32) -> u16;
|
||||||
}
|
}
|
||||||
|
@ -6,20 +6,13 @@
|
|||||||
// while simultaneously interfacing with a C library and using the -O3 flag.
|
// while simultaneously interfacing with a C library and using the -O3 flag.
|
||||||
// See https://github.com/rust-lang/rust/issues/97463
|
// See https://github.com/rust-lang/rust/issues/97463
|
||||||
|
|
||||||
//@ ignore-msvc
|
|
||||||
// Reason: the rustc compilation fails due to an unresolved external symbol
|
|
||||||
|
|
||||||
//@ ignore-cross-compile
|
//@ ignore-cross-compile
|
||||||
// Reason: The compiled binary is executed.
|
// Reason: The compiled binary is executed.
|
||||||
|
use run_make_support::{build_native_static_lib_optimized, run, rustc};
|
||||||
use run_make_support::{cc, is_msvc, llvm_ar, run, rustc, static_lib_name};
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// The issue exercised by this test specifically needs needs `-O`
|
// The issue exercised by this test specifically needs an optimized native static lib.
|
||||||
// flags (like `-O3`) to reproduce. Thus, we call `cc()` instead of
|
build_native_static_lib_optimized("bad");
|
||||||
// the nicer `build_native_static_lib`.
|
rustc().input("param_passing.rs").opt_level("3").run();
|
||||||
cc().arg("-c").arg("-O3").out_exe("bad.o").input("bad.c").run();
|
|
||||||
llvm_ar().obj_to_ar().output_input(static_lib_name("bad"), "bad.o").run();
|
|
||||||
rustc().input("param_passing.rs").arg("-lbad").opt_level("3").run();
|
|
||||||
run("param_passing");
|
run("param_passing");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user