wasm-micro-runtime icon indicating copy to clipboard operation
wasm-micro-runtime copied to clipboard

Single thread/disabled threading mode?

Open ericlewis opened this issue 3 years ago • 2 comments
trafficstars

Hi all, firstly want to say this is such a cool project! I have been working on porting to a new platform which is a bit quirky in how it works- primarily that it does not have a traditional sort of OS or threading model.

For now I have stubbed all the os_mutex_X calls, but there is still parts of the codebase which expose threading (libc-wasi/sandboxed-system-primitives) that are specifically handled via pthread, I was wondering if there is a way to disable that or how I should go about providing different bindings or whatever is necessary.

Edit: I see that it says libc_wasi, does that mean that this wasi implementation specifically relies on libc? (dumb question I know), and if that is the case is it possibly to provide alternative wasi implementations that aren't libc based?

ericlewis avatar Apr 01 '22 14:04 ericlewis

Hi, the libc-wasi may depend on some thread related APIs, not sure whether they are required by single-thread mode, you might try providing the empty implementation (e.g. return 0) for them to have a test. Another implementation of the wasi is to use libc-uvwasi with cmake -DWAMR_BUILD_LIBC_UVWASI=1, but it depends on uvwasi and libwasi, which might be more complex and use more thread APIs.

Not sure whether you need to the file/io operations support? If not, you can just try using the libc-builtin with cmake -DWAMR_BUILD_LIBC_WASI=0 to disable libc-wasi. And for wasm app, add options below for wasi-sdk to compile it:

    -Wl,--export=main -Wl,--export=__main_argc_argv \
    -Wl,--export=__heap_base -Wl,--export=__data_end \
    -Wl,--no-entry -Wl,--allow-undefined

Refer to build wasm app for more details. Thanks.

wenyongh avatar Apr 07 '22 07:04 wenyongh

Yeah- building it with WASI off works!

ericlewis avatar Apr 11 '22 16:04 ericlewis