Add a wasm code size test for stringifying numbers

This commit is contained in:
Nick Fitzgerald 2019-02-07 17:05:23 +01:00
parent c104b5c897
commit 05df9ff415
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,10 @@
-include ../../run-make-fulldeps/tools.mk
ifeq ($(TARGET),wasm32-unknown-unknown)
all:
$(RUSTC) foo.rs -C lto -O --target wasm32-unknown-unknown
wc -c < $(TMPDIR)/foo.wasm
[ "`wc -c < $(TMPDIR)/foo.wasm`" -lt "21000" ]
else
all:
endif

View File

@ -0,0 +1,39 @@
#![crate_type = "cdylib"]
extern "C" {
fn observe(ptr: *const u8, len: usize);
fn get_u8() -> u8;
fn get_i8() -> i8;
fn get_u16() -> u16;
fn get_i16() -> i16;
fn get_u32() -> u32;
fn get_i32() -> i32;
fn get_u64() -> u64;
fn get_i64() -> i64;
fn get_usize() -> usize;
fn get_isize() -> isize;
}
macro_rules! stringify {
( $($f:ident)* ) => {
$(
let s = $f().to_string();
observe(s.as_ptr(), s.len());
)*
};
}
#[no_mangle]
pub unsafe extern "C" fn foo() {
stringify!(get_u8);
stringify!(get_i8);
stringify!(get_u16);
stringify!(get_i16);
stringify!(get_u32);
stringify!(get_i32);
stringify!(get_u64);
stringify!(get_i64);
stringify!(get_usize);
stringify!(get_isize);
}