summaryrefslogtreecommitdiffstats
path: root/src/test/run-make/wasm-export-all-symbols
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/run-make/wasm-export-all-symbols
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/run-make/wasm-export-all-symbols')
-rw-r--r--src/test/run-make/wasm-export-all-symbols/Makefile19
-rw-r--r--src/test/run-make/wasm-export-all-symbols/bar.rs7
-rw-r--r--src/test/run-make/wasm-export-all-symbols/foo.rs3
-rw-r--r--src/test/run-make/wasm-export-all-symbols/main.rs3
-rw-r--r--src/test/run-make/wasm-export-all-symbols/verify.js32
5 files changed, 64 insertions, 0 deletions
diff --git a/src/test/run-make/wasm-export-all-symbols/Makefile b/src/test/run-make/wasm-export-all-symbols/Makefile
new file mode 100644
index 000000000..7e47ba485
--- /dev/null
+++ b/src/test/run-make/wasm-export-all-symbols/Makefile
@@ -0,0 +1,19 @@
+-include ../../run-make-fulldeps/tools.mk
+
+# only-wasm32-bare
+
+all:
+ $(RUSTC) bar.rs --target wasm32-unknown-unknown
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown
+ $(NODE) verify.js $(TMPDIR)/foo.wasm
+ $(RUSTC) main.rs --target wasm32-unknown-unknown
+ $(NODE) verify.js $(TMPDIR)/main.wasm
+ $(RUSTC) bar.rs --target wasm32-unknown-unknown -O
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown -O
+ $(NODE) verify.js $(TMPDIR)/foo.wasm
+ $(RUSTC) main.rs --target wasm32-unknown-unknown -O
+ $(NODE) verify.js $(TMPDIR)/main.wasm
+ $(RUSTC) foo.rs --target wasm32-unknown-unknown -C lto
+ $(NODE) verify.js $(TMPDIR)/foo.wasm
+ $(RUSTC) main.rs --target wasm32-unknown-unknown -C lto
+ $(NODE) verify.js $(TMPDIR)/main.wasm
diff --git a/src/test/run-make/wasm-export-all-symbols/bar.rs b/src/test/run-make/wasm-export-all-symbols/bar.rs
new file mode 100644
index 000000000..ac9c20a57
--- /dev/null
+++ b/src/test/run-make/wasm-export-all-symbols/bar.rs
@@ -0,0 +1,7 @@
+#![crate_type = "rlib"]
+
+#[no_mangle]
+pub extern fn foo() {}
+
+#[no_mangle]
+pub static FOO: u64 = 42;
diff --git a/src/test/run-make/wasm-export-all-symbols/foo.rs b/src/test/run-make/wasm-export-all-symbols/foo.rs
new file mode 100644
index 000000000..4811b24bc
--- /dev/null
+++ b/src/test/run-make/wasm-export-all-symbols/foo.rs
@@ -0,0 +1,3 @@
+#![crate_type = "cdylib"]
+
+extern crate bar;
diff --git a/src/test/run-make/wasm-export-all-symbols/main.rs b/src/test/run-make/wasm-export-all-symbols/main.rs
new file mode 100644
index 000000000..0edda7d7b
--- /dev/null
+++ b/src/test/run-make/wasm-export-all-symbols/main.rs
@@ -0,0 +1,3 @@
+extern crate bar;
+
+fn main() {}
diff --git a/src/test/run-make/wasm-export-all-symbols/verify.js b/src/test/run-make/wasm-export-all-symbols/verify.js
new file mode 100644
index 000000000..72db3356f
--- /dev/null
+++ b/src/test/run-make/wasm-export-all-symbols/verify.js
@@ -0,0 +1,32 @@
+const fs = require('fs');
+const process = require('process');
+const assert = require('assert');
+const buffer = fs.readFileSync(process.argv[2]);
+
+let m = new WebAssembly.Module(buffer);
+let list = WebAssembly.Module.exports(m);
+console.log('exports', list);
+
+const my_exports = {};
+let nexports = 0;
+
+for (const entry of list) {
+ if (entry.kind == 'function'){
+ nexports += 1;
+ }
+ my_exports[entry.name] = entry.kind;
+}
+
+if (my_exports.foo != "function")
+ throw new Error("`foo` wasn't defined");
+
+if (my_exports.FOO != "global")
+ throw new Error("`FOO` wasn't defined");
+
+if (my_exports.main === undefined) {
+ if (nexports != 1)
+ throw new Error("should only have one function export");
+} else {
+ if (nexports != 2)
+ throw new Error("should only have two function exports");
+}