Stream: general

Topic: wasm-merge with Rust tests


view this post on Zulip Enrico Loparco (Mar 06 2024 at 11:36):

Hello, I have a Rust workspace with multiple packages in it, each one with its own unit and integration tests.
Now, I want to have a single wasm file with all tests, how can I do it?

I tried using wasm-merge --rename-export-conflicts but, if I have two test files test1.wasm and test2.wasm, when I merge them into merge.wasm, only the tests in first one in the order are executed when running on a wasm runtime.

If I look at the wat representation, I see that both test1.wasm and test2.wasm export __main_void and _start. The merge.wasm that I generate also contains __main_void and _start.
Is there any workaround, like making tests export a different function name, so that I can call them directly from the runtime when running merge.wasm?

Thanks

view this post on Zulip bjorn3 (Mar 06 2024 at 16:46):

I think you did have to first have to rewrite all modules to rename their _start to unique names, then write a new module with _start which calls all renamed _start in order and then merge all these modules together. __main_void is generated by rustc and there is no way to make rustc use a different name. __main_void is called by _start and should never be called directly. _start is defined by the crt1.o of wasi-libc, which comes precompiled. Because of this all I think directly rewriting the wasm modules to change the export names is the best option you have. The alternative would be to skip rustc's testing infrastructure entirely and compile every test crate as cdylib and have them export a single function with a unique name which internally calls all tests.


Last updated: Oct 23 2024 at 20:03 UTC