diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index b461a24a06168..2fa680a8e2334 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -4,7 +4,7 @@ use std::str::FromStr as _; use crate::command::Command; use crate::env::env_var; -use crate::path_helpers::cwd; +use crate::path_helpers::{cwd, source_root}; use crate::util::set_host_compiler_dylib_path; use crate::{is_aix, is_darwin, is_windows, is_windows_msvc, target, uname}; @@ -22,6 +22,37 @@ pub fn bare_rustc() -> Rustc { Rustc::bare() } +/// Construct a `rustc` invocation for building `minicore`. +/// +/// This function: +/// +/// - adds `tests/auxiliary/minicore.rs` as an input +/// - sets the crate name to `"minicore"` +/// - sets the crate type to `rlib` +/// +/// # Example +/// +/// ```ignore (illustrative) +/// rustc_minicore().target("wasm32-wasip1").target_cpu("mvp").output("libminicore.rlib").run(); +/// +/// rustc() +/// .input("foo.rs") +/// .target("wasm32-wasip1") +/// .target_cpu("mvp") +/// .extern_("minicore", path("libminicore.rlib")) +/// // ... +/// .run() +/// ``` +#[track_caller] +pub fn rustc_minicore() -> Rustc { + let mut builder = rustc(); + + let minicore_path = source_root().join("tests/auxiliary/minicore.rs"); + builder.input(minicore_path).crate_name("minicore").crate_type("rlib"); + + builder +} + /// A `rustc` invocation builder. #[derive(Debug)] #[must_use] diff --git a/src/tools/run-make-support/src/lib.rs b/src/tools/run-make-support/src/lib.rs index 52cc7ae9d3791..ba413724c2fe4 100644 --- a/src/tools/run-make-support/src/lib.rs +++ b/src/tools/run-make-support/src/lib.rs @@ -72,7 +72,7 @@ pub use crate::external_deps::llvm::{ llvm_readobj, }; pub use crate::external_deps::python::python_command; -pub use crate::external_deps::rustc::{self, Rustc, bare_rustc, rustc, rustc_path}; +pub use crate::external_deps::rustc::{self, Rustc, bare_rustc, rustc, rustc_minicore, rustc_path}; pub use crate::external_deps::rustdoc::{Rustdoc, bare_rustdoc, rustdoc}; // Path-related helpers. pub use crate::path_helpers::{ diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index 3b3472340e737..17f325d582785 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -288,6 +288,17 @@ pub mod mem { pub const fn align_of() -> usize; } +pub mod ptr { + #[inline] + #[rustc_diagnostic_item = "ptr_write_volatile"] + pub unsafe fn write_volatile(dst: *mut T, src: T) { + #[rustc_intrinsic] + pub unsafe fn volatile_store(dst: *mut T, val: T); + + unsafe { volatile_store(dst, src) }; + } +} + #[lang = "c_void"] #[repr(u8)] pub enum c_void { diff --git a/tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs b/tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs index 07fda1f3f4a34..baea8ff772548 100644 --- a/tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs +++ b/tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs @@ -7,7 +7,8 @@ #![no_main] #![allow(internal_features)] -use minicore::ptr; +extern crate minicore; +use minicore::*; #[no_mangle] pub fn main() -> ! { @@ -21,32 +22,3 @@ pub fn main() -> ! { unsafe { ptr::write_volatile(port_b, 2) }; } } - -// FIXME: replace with proper minicore once available (#130693) -mod minicore { - #[lang = "pointee_sized"] - pub trait PointeeSized {} - - #[lang = "meta_sized"] - pub trait MetaSized: PointeeSized {} - - #[lang = "sized"] - pub trait Sized: MetaSized {} - - #[lang = "copy"] - pub trait Copy {} - impl Copy for u32 {} - impl Copy for &u32 {} - impl Copy for *mut T {} - - pub mod ptr { - #[inline] - #[rustc_diagnostic_item = "ptr_write_volatile"] - pub unsafe fn write_volatile(dst: *mut T, src: T) { - #[rustc_intrinsic] - pub unsafe fn volatile_store(dst: *mut T, val: T); - - unsafe { volatile_store(dst, src) }; - } - } -} diff --git a/tests/run-make/avr-rjmp-offset/rmake.rs b/tests/run-make/avr-rjmp-offset/rmake.rs index 86d85e89f7883..a4a219436ad26 100644 --- a/tests/run-make/avr-rjmp-offset/rmake.rs +++ b/tests/run-make/avr-rjmp-offset/rmake.rs @@ -15,9 +15,11 @@ // crashes... so I'm going to disable this test for windows for now. //@ ignore-windows-gnu -use run_make_support::{llvm_objdump, rustc}; +use run_make_support::{llvm_objdump, path, rustc, rustc_minicore}; fn main() { + rustc_minicore().target("avr-none").target_cpu("avr").output("libminicore.rlib").run(); + rustc() .input("avr-rjmp-offsets.rs") .opt_level("s") @@ -36,6 +38,7 @@ fn main() { .linker("rust-lld") .link_arg("--entry=main") .output("compiled") + .extern_("minicore", path("libminicore.rlib")) .run(); let disassembly = llvm_objdump().disassemble().input("compiled").run().stdout_utf8(); diff --git a/tests/run-make/thumb-interworking/rmake.rs b/tests/run-make/thumb-interworking/rmake.rs index 1aa39ed1ce159..05ff73c78efb1 100644 --- a/tests/run-make/thumb-interworking/rmake.rs +++ b/tests/run-make/thumb-interworking/rmake.rs @@ -1,6 +1,8 @@ //@ needs-llvm-components: arm //@ needs-rust-lld -use run_make_support::{llvm_filecheck, llvm_objdump, path, rfs, run, rustc, source_root}; +use run_make_support::{ + llvm_filecheck, llvm_objdump, path, rfs, run, rustc, rustc_minicore, source_root, +}; // Test a thumb target calling arm functions. Doing so requires switching from thumb mode to arm // mode, calling the arm code, then switching back to thumb mode. Depending on the thumb version, @@ -25,21 +27,13 @@ fn main() { } fn helper(prefix: &str, target: &str) { - rustc() - .input(source_root().join("tests/auxiliary/minicore.rs")) - .crate_name("minicore") - .crate_type("rlib") - .target(target) - .output("libminicore.rlib") - .run(); - let minicore = path("libminicore.rlib"); + rustc_minicore().target(target).output("libminicore.rlib").run(); rustc() .input("main.rs") .panic("abort") .link_arg("-Tlink.ld") - .arg("--extern") - .arg(format!("minicore={}", minicore.display())) + .extern_("minicore", path("libminicore.rlib")) .target(target) .output(prefix) .run(); diff --git a/tests/run-make/wasm-unexpected-features/foo.rs b/tests/run-make/wasm-unexpected-features/foo.rs index 5c7aa2d619046..20c7bc0839ec4 100644 --- a/tests/run-make/wasm-unexpected-features/foo.rs +++ b/tests/run-make/wasm-unexpected-features/foo.rs @@ -4,6 +4,9 @@ #![needs_allocator] #![allow(internal_features)] +extern crate minicore; +use minicore::*; + #[rustc_std_internal_symbol] unsafe fn __rust_alloc(_size: usize, _align: usize) -> *mut u8 { 0 as *mut u8 @@ -23,21 +26,3 @@ extern "C" fn init() { __rust_alloc_error_handler(0, 0); } } - -mod minicore { - #[lang = "pointee_sized"] - pub trait PointeeSized {} - - #[lang = "meta_sized"] - pub trait MetaSized: PointeeSized {} - - #[lang = "sized"] - pub trait Sized: MetaSized {} - - #[lang = "copy"] - pub trait Copy {} - impl Copy for u8 {} - - #[lang = "drop_in_place"] - fn drop_in_place(_: *mut T) {} -} diff --git a/tests/run-make/wasm-unexpected-features/rmake.rs b/tests/run-make/wasm-unexpected-features/rmake.rs index 01eff54e823c9..44c6f3522267e 100644 --- a/tests/run-make/wasm-unexpected-features/rmake.rs +++ b/tests/run-make/wasm-unexpected-features/rmake.rs @@ -1,10 +1,11 @@ -//@ only-wasm32-wasip1 - +//@ needs-rust-lld use std::path::Path; -use run_make_support::{rfs, rustc, wasmparser}; +use run_make_support::{path, rfs, rustc, rustc_minicore, wasmparser}; fn main() { + rustc_minicore().target("wasm32-wasip1").target_cpu("mvp").output("libminicore.rlib").run(); + rustc() .input("foo.rs") .target("wasm32-wasip1") @@ -13,6 +14,7 @@ fn main() { .lto("fat") .linker_plugin_lto("on") .link_arg("--import-memory") + .extern_("minicore", path("libminicore.rlib")) .run(); verify_features(Path::new("foo.wasm")); }