Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/tools/run-make-support/src/external_deps/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
11 changes: 11 additions & 0 deletions tests/auxiliary/minicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ pub mod mem {
pub const fn align_of<T>() -> usize;
}

pub mod ptr {
#[inline]
#[rustc_diagnostic_item = "ptr_write_volatile"]
pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
#[rustc_intrinsic]
pub unsafe fn volatile_store<T>(dst: *mut T, val: T);

unsafe { volatile_store(dst, src) };
}
}

#[lang = "c_void"]
#[repr(u8)]
pub enum c_void {
Expand Down
32 changes: 2 additions & 30 deletions tests/run-make/avr-rjmp-offset/avr-rjmp-offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#![no_main]
#![allow(internal_features)]

use minicore::ptr;
extern crate minicore;
use minicore::*;

#[no_mangle]
pub fn main() -> ! {
Expand All @@ -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<T: PointeeSized> Copy for *mut T {}

pub mod ptr {
#[inline]
#[rustc_diagnostic_item = "ptr_write_volatile"]
pub unsafe fn write_volatile<T>(dst: *mut T, src: T) {
#[rustc_intrinsic]
pub unsafe fn volatile_store<T>(dst: *mut T, val: T);

unsafe { volatile_store(dst, src) };
}
}
}
5 changes: 4 additions & 1 deletion tests/run-make/avr-rjmp-offset/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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();
Expand Down
16 changes: 5 additions & 11 deletions tests/run-make/thumb-interworking/rmake.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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();
Expand Down
21 changes: 3 additions & 18 deletions tests/run-make/wasm-unexpected-features/foo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<T>(_: *mut T) {}
}
8 changes: 5 additions & 3 deletions tests/run-make/wasm-unexpected-features/rmake.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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"));
}
Expand Down
Loading