diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/run-make/wasm-import-module | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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(); +} |