diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/run-make/wasm-import-module | |
parent | Initial commit. (diff) | |
download | rustc-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-import-module')
-rw-r--r-- | src/test/run-make/wasm-import-module/Makefile | 8 | ||||
-rw-r--r-- | src/test/run-make/wasm-import-module/bar.rs | 18 | ||||
-rw-r--r-- | src/test/run-make/wasm-import-module/foo.js | 18 | ||||
-rw-r--r-- | src/test/run-make/wasm-import-module/foo.rs | 7 |
4 files changed, 51 insertions, 0 deletions
diff --git a/src/test/run-make/wasm-import-module/Makefile b/src/test/run-make/wasm-import-module/Makefile new file mode 100644 index 000000000..fe63e66f2 --- /dev/null +++ b/src/test/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/src/test/run-make/wasm-import-module/bar.rs b/src/test/run-make/wasm-import-module/bar.rs new file mode 100644 index 000000000..1b988c783 --- /dev/null +++ b/src/test/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/src/test/run-make/wasm-import-module/foo.js b/src/test/run-make/wasm-import-module/foo.js new file mode 100644 index 000000000..3ea47fcc9 --- /dev/null +++ b/src/test/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/src/test/run-make/wasm-import-module/foo.rs b/src/test/run-make/wasm-import-module/foo.rs new file mode 100644 index 000000000..bbeaf99bc --- /dev/null +++ b/src/test/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(); +} |