rewrite test with #![no_core]
This commit is contained in:
parent
f978932903
commit
3a250b7939
4 changed files with 53 additions and 69 deletions
43
tests/run-make/wasm-unexpected-features/foo.rs
Normal file
43
tests/run-make/wasm-unexpected-features/foo.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#![no_core]
|
||||
#![crate_type = "cdylib"]
|
||||
#![feature(no_core, lang_items, allocator_internals, rustc_attrs)]
|
||||
#![needs_allocator]
|
||||
#![allow(internal_features)]
|
||||
|
||||
#[rustc_std_internal_symbol]
|
||||
unsafe fn __rust_alloc(_size: usize, _align: usize) -> *mut u8 {
|
||||
0 as *mut u8
|
||||
}
|
||||
|
||||
unsafe extern "Rust" {
|
||||
#[rustc_std_internal_symbol]
|
||||
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
|
||||
}
|
||||
|
||||
#[used]
|
||||
static mut BUF: [u8; 1024] = [0; 1024];
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn init() {
|
||||
unsafe {
|
||||
__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) {}
|
||||
}
|
||||
|
|
@ -2,31 +2,19 @@
|
|||
|
||||
use std::path::Path;
|
||||
|
||||
use run_make_support::{cargo, path, rfs, target, wasmparser};
|
||||
use run_make_support::{rfs, rustc, wasmparser};
|
||||
|
||||
fn main() {
|
||||
let target_dir = path("target");
|
||||
|
||||
cargo()
|
||||
.args([
|
||||
"rustc",
|
||||
"--manifest-path",
|
||||
"wasm32_test/Cargo.toml",
|
||||
"--profile",
|
||||
"release",
|
||||
"--target",
|
||||
"wasm32-wasip1",
|
||||
"-Zbuild-std=core,alloc,panic_abort",
|
||||
"--",
|
||||
"-Clink-arg=--import-memory",
|
||||
"-Clinker-plugin-lto=on",
|
||||
])
|
||||
.env("RUSTFLAGS", "-Ctarget-cpu=mvp")
|
||||
.env("CARGO_TARGET_DIR", &target_dir)
|
||||
rustc()
|
||||
.input("foo.rs")
|
||||
.target("wasm32-wasip1")
|
||||
.target_cpu("mvp")
|
||||
.opt_level("z")
|
||||
.lto("fat")
|
||||
.linker_plugin_lto("on")
|
||||
.link_arg("--import-memory")
|
||||
.run();
|
||||
|
||||
let wasm32_program_path = target_dir.join(target()).join("release").join("wasm32_program.wasm");
|
||||
verify_features(&wasm32_program_path);
|
||||
verify_features(Path::new("foo.wasm"));
|
||||
}
|
||||
|
||||
fn verify_features(path: &Path) {
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
[package]
|
||||
name = "wasm32_test"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
name = "wasm32_program"
|
||||
|
||||
[profile.release]
|
||||
codegen-units = 1
|
||||
lto = "fat"
|
||||
opt-level = "z"
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use core::mem::MaybeUninit;
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOC: GlobalDlmalloc = GlobalDlmalloc;
|
||||
|
||||
struct GlobalDlmalloc;
|
||||
|
||||
unsafe impl GlobalAlloc for GlobalDlmalloc {
|
||||
#[inline]
|
||||
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
||||
core::ptr::null_mut()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {}
|
||||
}
|
||||
|
||||
#[used]
|
||||
static mut BUF: MaybeUninit<[u8; 1024]> = MaybeUninit::uninit();
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
extern "C" fn init() {
|
||||
alloc::alloc::handle_alloc_error(Layout::new::<[u8; 64 * 1024]>());
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn my_panic(_: &core::panic::PanicInfo) -> ! {
|
||||
loop {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue