Migrate wasm-exceptions-nostd to rmake

This commit is contained in:
Jerry Wang 2024-06-23 17:03:36 -04:00
parent 189232bc42
commit 68b6bb27c1
4 changed files with 20 additions and 15 deletions

View File

@ -186,5 +186,4 @@ run-make/track-pgo-dep-info/Makefile
run-make/translation/Makefile run-make/translation/Makefile
run-make/type-mismatch-same-crate-name/Makefile run-make/type-mismatch-same-crate-name/Makefile
run-make/unstable-flag-required/Makefile run-make/unstable-flag-required/Makefile
run-make/wasm-exceptions-nostd/Makefile
run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile run-make/x86_64-fortanix-unknown-sgx-lvi/Makefile

View File

@ -1,12 +0,0 @@
include ../tools.mk
# only-wasm32-bare
# Add a few command line args to make exceptions work
RUSTC := $(RUSTC) -C llvm-args=-wasm-enable-eh
RUSTC := $(RUSTC) -C target-feature=+exception-handling
RUSTC := $(RUSTC) -C panic=unwind
all:
$(RUSTC) src/lib.rs --target wasm32-unknown-unknown
$(NODE) verify.mjs $(TMPDIR)/lib.wasm

View File

@ -0,0 +1,18 @@
//@ only-wasm32-bare
use std::path::Path;
use run_make_support::{cmd, env_var, rustc};
fn main() {
// Add a few command line args to make exceptions work
rustc()
.input(Path::new("src").join("lib.rs"))
.target("wasm32-unknown-unknown")
.panic("unwind")
.arg("-Cllvm-args=-wasm-enable-eh")
.arg("-Ctarget-feature=+exception-handling")
.run();
cmd(&env_var("NODE")).arg("verify.mjs").arg("lib.wasm").run();
}

View File

@ -17,8 +17,8 @@ fn panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
use alloc::boxed::Box; use alloc::boxed::Box;
use alloc::string::ToString; use alloc::string::ToString;
let msg = info.message().map(|msg| msg.to_string()).unwrap_or("(no message)".to_string()); let msg = info.message().to_string();
let exception = Box::new(msg.to_string()); let exception = Box::new(msg);
unsafe { unsafe {
let exception_raw = Box::into_raw(exception); let exception_raw = Box::into_raw(exception);
wasm_throw(exception_raw as *mut u8); wasm_throw(exception_raw as *mut u8);