Closed yowl closed 1 year ago
Worth mentioning here is what node.js does.
At the bottom of this document https://nodejs.org/api/wasi.html it describes how the node.js runtime initializes WASI modules/compoents. Ive not tested this because I have been focusing on wasmtime because it looks to be leading the way in terms of WIT support and wasm component linking and running. However on the surface it looks like with this change, if node.js was used as the host, then _initialize
would be called twice resulting in failure.
Yes, a good question, I will try to get a more definitive answer and update here, but my current understanding is that wasmtime will call _initialize
when it is invoking a WASI reactor module, but that is not the same thing as a WASM component (components are a lower level and dont require WASI). To invoke the c# wasm component it is passed to the instantiation of another module, as in the example https://docs.rs/wasmtime/latest/wasmtime/component/macro.bindgen.html .
This PR accepts the recommendation from NativeAOT_StaticInitialization and teherby removes
NativeAOT_StaticInitialization
and its initialisation. This enables the runtime to be initialised without the use of static c++ ctors which are not invoked presently for WASI reactor components.https://github.com/WebAssembly/wasi-libc/pull/74 https://github.com/WebAssembly/WASI/issues/13
Instead the initialisation from a WASI reactor component is done via the wasi-libc
_initialize
function. The call to this function is done in/Bootstrap/main.cpp
which is#if def
ed in for WASI andNATIVEAOT_DLL
WASI reactor components can now be compiled and executed (although the WIT codegen is not ready yet).
This change does introduce the problem of intialisation of
CustomNativeMain
from a WASI program as it is not distnguishable from a wasi reactor compoent, and the crt1.o for the program case does not contain_initialize
,_intialize
is only present for the reactor version of crt1 https://github.com/WebAssembly/wasi-libc/blob/9f51a7102085ec6a6ced5778f0864c9af9f50000/libc-bottom-half/crt/crt1-reactor.c#L7-L27To solve the problem of no
_initialize
for WASI +NATIVEAOT_DLL
from aCustomNativeMain
I added a__weak
dummy function.