diff --git a/builtins-test-intrinsics/Cargo.toml b/builtins-test-intrinsics/Cargo.toml index 9b2e5bb7c..b1e9cda70 100644 --- a/builtins-test-intrinsics/Cargo.toml +++ b/builtins-test-intrinsics/Cargo.toml @@ -8,5 +8,9 @@ publish = false compiler_builtins = { path = "../", features = ["compiler-builtins"]} panic-handler = { path = '../crates/panic-handler' } +[target.'cfg(target_family = "windows")'.dependencies] +# `#![no_std]` on Windows needs `string.h` routines. +compiler_builtins = { path = "../", features = ["compiler-builtins", "mem"]} + [features] c = ["compiler_builtins/c"] diff --git a/builtins-test-intrinsics/build.rs b/builtins-test-intrinsics/build.rs index a38c6c1ff..1981943dc 100644 --- a/builtins-test-intrinsics/build.rs +++ b/builtins-test-intrinsics/build.rs @@ -8,4 +8,9 @@ fn main() { let target = builtins_configure::Target::from_env(); builtins_configure::configure_f16_f128(&target); builtins_configure::configure_aliases(&target); + + if target.os == "windows" { + // Needed for using the `mainCRTStartup` entrypoint + println!("cargo::rustc-link-arg=/subsystem:console"); + } } diff --git a/builtins-test-intrinsics/src/main.rs b/builtins-test-intrinsics/src/main.rs index e90cfb33d..9eab5590e 100644 --- a/builtins-test-intrinsics/src/main.rs +++ b/builtins-test-intrinsics/src/main.rs @@ -13,6 +13,9 @@ #![no_std] #![no_main] +// Ensure this repo's version of `compiler_builtins` gets used, rather than what gets injected from +// the sysroot. +extern crate compiler_builtins; extern crate panic_handler; #[cfg(all(not(thumb), not(windows), not(target_arch = "wasm32")))] @@ -626,12 +629,12 @@ fn run() { something_with_a_dtor(&|| assert_eq!(bb(1), 1)); - extern "C" { - fn rust_begin_unwind(x: usize); - } - - unsafe { - rust_begin_unwind(0); + // Ensure panic machinery gets linked, but still allow this to run to completion. + // FIXME(windows): we should have this on Windows too but it requires a lot more + // missing symbols. + #[cfg(not(windows))] + if bb(false) { + panic!(); } } @@ -648,15 +651,23 @@ fn something_with_a_dtor(f: &dyn Fn()) { } #[no_mangle] -#[cfg(not(thumb))] -fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int { +#[cfg(not(any(thumb, windows)))] +extern "C" fn main(_argc: core::ffi::c_int, _argv: *const *const u8) -> core::ffi::c_int { + run(); + 0 +} + +#[no_mangle] +#[cfg(windows)] +#[allow(non_snake_case)] +extern "C" fn mainCRTStartup() -> core::ffi::c_int { run(); 0 } #[no_mangle] #[cfg(thumb)] -pub fn _start() -> ! { +extern "C" fn _start() -> ! { run(); loop {} } @@ -673,15 +684,21 @@ pub fn __aeabi_unwind_cpp_pr0() {} #[no_mangle] pub fn __aeabi_unwind_cpp_pr1() {} -#[cfg(not(any(windows, target_os = "cygwin")))] -#[allow(non_snake_case)] #[no_mangle] +#[allow(non_snake_case)] +#[cfg(not(any(windows, target_os = "cygwin")))] pub fn _Unwind_Resume() {} -#[cfg(not(any(windows, target_os = "cygwin")))] -#[lang = "eh_personality"] #[no_mangle] -pub extern "C" fn eh_personality() {} +#[lang = "eh_personality"] +#[cfg(not(any(windows, target_os = "cygwin")))] +pub extern "system" fn eh_personality() {} + +#[cfg(windows)] +#[unsafe(no_mangle)] +extern "system" fn __CxxFrameHandler3() -> ! { + unimplemented!() +} #[cfg(any(all(windows, target_env = "gnu"), target_os = "cygwin"))] mod mingw_unwinding { diff --git a/ci/run.sh b/ci/run.sh index 3625dde79..0882b77eb 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -120,22 +120,28 @@ done rm -f "${rlib_paths[@]}" -build_intrinsics_test() { - cargo build --target "$target" -v --package builtins-test-intrinsics "$@" +run_intrinsics_test() { + # FIXME(windows): We should be able to run this test on Windows too, but it + # seems to run into a lot more missing symbols. + if [[ "${NO_STD:-}" = "1" || "$target" == *"windows" ]]; then + cmd=build + else + cmd=run + fi + + cargo "$cmd" --target "$target" -v --package builtins-test-intrinsics "$@" } # Verify that we haven't dropped any intrinsics/symbols -build_intrinsics_test -build_intrinsics_test --release -build_intrinsics_test --features c -build_intrinsics_test --features c --release +run_intrinsics_test +run_intrinsics_test --release +run_intrinsics_test --features c +run_intrinsics_test --features c --release # Verify that there are no undefined symbols to `panic` within our # implementations -CARGO_PROFILE_DEV_LTO=true \ - cargo build --target "$target" --package builtins-test-intrinsics -CARGO_PROFILE_RELEASE_LTO=true \ - cargo build --target "$target" --package builtins-test-intrinsics --release +CARGO_PROFILE_DEV_LTO=true run_intrinsics_test +CARGO_PROFILE_RELEASE_LTO=true run_intrinsics_test --release # Ensure no references to any symbols from core update_rlib_paths