Skip to content

Support for multiple modules#338

Merged
tolauwae merged 23 commits into
mainfrom
feat/multiple-modules
May 11, 2026
Merged

Support for multiple modules#338
tolauwae merged 23 commits into
mainfrom
feat/multiple-modules

Conversation

@abelstuker
Copy link
Copy Markdown
Contributor

@abelstuker abelstuker commented Dec 9, 2025

This PR fixes #27 by adding support for multiple modules, including shared memory, tables, globals and cross-module function calls.

Currently no official Wasm nor unofficial tests have been included in the Latch spectest suite. To test the multiple module functionality, see the test examples in /tutorials/wat/main/mtuliple_modules_mX.wast. These example tests include the demonstration of:

You can provide multiple modules to the CLI by linking modules using the --link flag (e.g. ./wdcli mod1.wasm --link mod2.wasm mod3.wasm).

@abelstuker
Copy link
Copy Markdown
Contributor Author

Should we include Latch spectests to cover this multi-module extension?
In that case, I presume Latch must be upgraded first for it to be capable of handling the compilation and linking of multiple modules?

@tolauwae
Copy link
Copy Markdown
Member

tolauwae commented Apr 17, 2026

I currently get this error when trying out the example:

➜ main (feat/multiple-modules) ✗ wdcli mod1.wasm --link mod2.wasm mod3.wasm
Assert Failed (WARDuino/src/WARDuino/WARDuino.cpp:603): Imported global mutability mismatch: imported=139, expected=1     
➜ main (feat/multiple-modules) ✗ echo $?
1

Also I used the TOPLLab fork of wat2wasm to get the binaries:

➜ main (feat/multiple-modules) ✗ wat2wasm --version
1.0.32 (git~1.0.27-176-g09d542f4)TOPLLab

Maybe I need to update this version?

@abelstuker
Copy link
Copy Markdown
Contributor Author

@tolauwae
Mmmhh that's strange. I cannot reproduce this error (also using the TOPLLab wabt fork).
Are the wasm binaries formed as expected?

❯ wasm-objdump -x multiple_module_m1.wasm | grep global
 - global[0] i32 mutable=1 <- multiple_module_m3.counter

❯ wasm-objdump -x multiple_module_m3.wasm | grep global
 - global[0] i32 mutable=1 <counter> - init i32=100
 - global[0] -> "counter"

@tolauwae
Copy link
Copy Markdown
Member

Yes I get the same output.

@abelstuker
Copy link
Copy Markdown
Contributor Author

@tolauwae I see you compiled every multiple_module_mX.wast to modX.wasm. This, however, only works when you also update the import modules in those .wast files, as they expect the names of the (imported) modules to be in the multiple_module_mX format. Otherwise, they can't find the modules to import, resulting in this seemingly unrelated error.

@tolauwae
Copy link
Copy Markdown
Member

I should have realised that 😅

@tolauwae tolauwae force-pushed the feat/multiple-modules branch from 57c44c9 to ecf0ef8 Compare May 9, 2026 11:51
@tolauwae tolauwae marked this pull request as ready for review May 9, 2026 11:51
@tolauwae tolauwae enabled auto-merge (squash) May 9, 2026 11:51
@tolauwae
Copy link
Copy Markdown
Member

tolauwae commented May 9, 2026

Rebased. There were a lot of conflicts so I will run additional tests. But looks ready to merge.

@tolauwae tolauwae self-requested a review May 10, 2026 19:12
Copy link
Copy Markdown
Member

@tolauwae tolauwae left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional tests seem to find no more issues.

➜ main (feat/multiple-modules) ✗ wdcli multiple_module_m1.wasm --link multiple_module_m2.wasm multiple_module_m3.wasm 
=== Multi-module test ===
Cross-module call: 5 + 20 = 25
Table callback to table in M3 at index 0
M3: callback executed
Global counter: 100
Global counter +2: 102
Shared memory read: 8888

@tolauwae tolauwae merged commit 889760e into main May 11, 2026
19 checks passed
@tolauwae tolauwae deleted the feat/multiple-modules branch May 11, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📑 Support multiple modules

2 participants