diff options
Diffstat (limited to 'tests/run-make/wasm-import-module')
-rw-r--r-- | tests/run-make/wasm-import-module/Makefile | 8 | ||||
-rw-r--r-- | tests/run-make/wasm-import-module/bar.rs | 18 | ||||
-rw-r--r-- | tests/run-make/wasm-import-module/foo.js | 18 | ||||
-rw-r--r-- | tests/run-make/wasm-import-module/foo.rs | 7 |
4 files changed, 51 insertions, 0 deletions
diff --git a/tests/run-make/wasm-import-module/Makefile b/tests/run-make/wasm-import-module/Makefile new file mode 100644 index 000000000..18cef16aa --- /dev/null +++ b/tests/run-make/wasm-import-module/Makefile @@ -0,0 +1,8 @@ +include ../../run-make-fulldeps/tools.mk + + # only-wasm32-bare + +all: + $(RUSTC) foo.rs --target wasm32-unknown-unknown + $(RUSTC) bar.rs -C lto -O --target wasm32-unknown-unknown + $(NODE) foo.js $(TMPDIR)/bar.wasm diff --git a/tests/run-make/wasm-import-module/bar.rs b/tests/run-make/wasm-import-module/bar.rs new file mode 100644 index 000000000..1b988c783 --- /dev/null +++ b/tests/run-make/wasm-import-module/bar.rs @@ -0,0 +1,18 @@ +#![crate_type = "cdylib"] +#![deny(warnings)] + +extern crate foo; + +#[link(wasm_import_module = "./me")] +extern "C" { + #[link_name = "me_in_dep"] + fn dep(); +} + +#[no_mangle] +pub extern "C" fn foo() { + unsafe { + foo::dep(); + dep(); + } +} diff --git a/tests/run-make/wasm-import-module/foo.js b/tests/run-make/wasm-import-module/foo.js new file mode 100644 index 000000000..3ea47fcc9 --- /dev/null +++ b/tests/run-make/wasm-import-module/foo.js @@ -0,0 +1,18 @@ +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 imports = WebAssembly.Module.imports(m); +console.log('imports', imports); +assert.strictEqual(imports.length, 2); + +assert.strictEqual(imports[0].kind, 'function'); +assert.strictEqual(imports[1].kind, 'function'); + +let modules = [imports[0].module, imports[1].module]; +modules.sort(); + +assert.strictEqual(modules[0], './dep'); +assert.strictEqual(modules[1], './me'); diff --git a/tests/run-make/wasm-import-module/foo.rs b/tests/run-make/wasm-import-module/foo.rs new file mode 100644 index 000000000..bbeaf99bc --- /dev/null +++ b/tests/run-make/wasm-import-module/foo.rs @@ -0,0 +1,7 @@ +#![crate_type = "rlib"] +#![deny(warnings)] + +#[link(wasm_import_module = "./dep")] +extern "C" { + pub fn dep(); +} |