Skip to content

Commit 05df9ff

Browse files
committed
Add a wasm code size test for stringifying numbers
1 parent c104b5c commit 05df9ff

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-include ../../run-make-fulldeps/tools.mk
2+
3+
ifeq ($(TARGET),wasm32-unknown-unknown)
4+
all:
5+
$(RUSTC) foo.rs -C lto -O --target wasm32-unknown-unknown
6+
wc -c < $(TMPDIR)/foo.wasm
7+
[ "`wc -c < $(TMPDIR)/foo.wasm`" -lt "21000" ]
8+
else
9+
all:
10+
endif
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#![crate_type = "cdylib"]
2+
3+
extern "C" {
4+
fn observe(ptr: *const u8, len: usize);
5+
6+
fn get_u8() -> u8;
7+
fn get_i8() -> i8;
8+
fn get_u16() -> u16;
9+
fn get_i16() -> i16;
10+
fn get_u32() -> u32;
11+
fn get_i32() -> i32;
12+
fn get_u64() -> u64;
13+
fn get_i64() -> i64;
14+
fn get_usize() -> usize;
15+
fn get_isize() -> isize;
16+
}
17+
18+
macro_rules! stringify {
19+
( $($f:ident)* ) => {
20+
$(
21+
let s = $f().to_string();
22+
observe(s.as_ptr(), s.len());
23+
)*
24+
};
25+
}
26+
27+
#[no_mangle]
28+
pub unsafe extern "C" fn foo() {
29+
stringify!(get_u8);
30+
stringify!(get_i8);
31+
stringify!(get_u16);
32+
stringify!(get_i16);
33+
stringify!(get_u32);
34+
stringify!(get_i32);
35+
stringify!(get_u64);
36+
stringify!(get_i64);
37+
stringify!(get_usize);
38+
stringify!(get_isize);
39+
}

0 commit comments

Comments
 (0)