-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Building a wasm library without needing to define a main()
#332
Comments
main()
maybe using
|
Yes, that worked in the end (discovered a few weeks ago, but forgot to update this bug report). Perhaps the documentation should be a bit better though, especially for people who are new to WASM (it was not at all clear to me that "reactor" had anything to do with "library") |
The problem is that the term "library" in a build system normally means just a part of a program (either as a static or dynamic library). What a reactor is is a full (statically linked) program without a main function. There was no existing term for that so WASI invented the term "reactor". I believe in future versions that term will actually be dropped, but that is the history of the term. If what you really want is a dynamically loaded library (which is how most plugin systems are built) then WASI doesn't currently support that, but there are efforts to port/standardize the dynamic linking system used by emscripten, so it maybe be possible in the future. One way to tell if you need to use DSOs if that if your plugins share memory with each other or with some "main" program or with other shared libraries. With "reactors" each module has own complete copy of libc, along with all its global data, which makes calling across the program boundaries more like an RPC to completely separate program. |
My plugins are completely separate, though sharing libc (and thus reducing memory usage) would be nice. |
It seems there are different ways, please correct me if I was wrong @sbc100
|
Basically yes. Note that wasi-sdk does not currently support shared-everything linking or any kind of runtime linking. The only implementation that I know of today is in emscripten. In the emscripten model the main module includes libc and the side module(s) import all the libc symbols from the main module: https://emscripten.org/docs/compiling/Dynamic-Linking.html |
Reading this, it doesn't look like emscripten supports this model for it's WASI support? Only in the web case? Or at least WASI not not explicitly mentioned on that page. |
Yes, that is correct. |
I'm new to wasm, so I may be misunderstanding things. I'm using the wasi-sdk.cmake file to build a library that I will load as a plugin into a native program using WAMR.
However, in order to get a .wasm file out (and not a
.a
file) I need to useadd_executable(mylib.wasm src/test.cpp)
in cmake, which complains about missing themain
entrypoint. I could of course provide a dummy, but that seems pointless.add_library(mylib.wasm src/test.cpp)
I get a.a
archive instead.add_library(mylib.wasm SHARED src/test.cpp)
I get:mylib.wasm.so
which is not what I want, I think?)If I do allow errors (which is against the policy at my workplace), it still claims to need a
main
:What is the proper way to create a plugin style library using wasi-sdk (using cmake)? I will be calling functions from the host, I do not need a main as far as I know (I wouldn't need this in a native loadable library for sure).
The text was updated successfully, but these errors were encountered: