Repository navigation
Create a static wasm C API instead of shared - #1602
basvandijk wants to merge 4 commits into
Conversation
This enabled building the `wabt-sys` Rust crate statically using musl.
Linking statically on Windows results in the following error on CI: ``` D:\a\wabt\wabt\out\Debug\wasm-c-api-trap.exe : fatal error LNK1120: 34 unresolved externals [D:\a\wabt\wabt\out\wasm-c-api-trap.vcxproj] ```
| if (WIN32) | ||
| add_library(wasm SHARED ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc) | ||
| else () | ||
| add_library(wasm STATIC ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc) |
There was a problem hiding this comment.
I'm not sure how cmake normally handles this but I would have thought this would be some kind of build option. Most libraries build as both dynamic and static right? We should try to follow cmake best practices whatever they are.
| if (WIN32) | ||
| add_library(wasm SHARED ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc) | ||
| else () | ||
| add_library(wasm STATIC ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc) | ||
| endif () |
There was a problem hiding this comment.
To quote the cmake docs:
If no type is given explicitly the type is STATIC or SHARED based on whether the current value of the variable BUILD_SHARED_LIBS is ON
So maybe we should just remove the SHARED type and make sure BUILD_SHARED_LIBS is correctly set to false when building statically:
| if (WIN32) | |
| add_library(wasm SHARED ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc) | |
| else () | |
| add_library(wasm STATIC ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc) | |
| endif () | |
| add_library(wasm ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc) |
@sbc100 WDYT?
There was a problem hiding this comment.
When setting add_library(wasm ${WABT_LIBRARY_SRC} src/interp/interp-wasm-c-api.cc) the build crashes on Windows. To fix that we need to:
if (WIN32)
set(BUILD_SHARED_LIBS ON)
endif ()
However I think that's worse from my previous solution since the previous solution only made a local change while this makes a global change which could have adverse effects. The previous solution is also more consistent with all other calls of add_library since they all specify the SHARED/STATIC type.
So I'm going back to my original solution. @sbc100 @binji WDYT? It would be great to get this merged.
There was a problem hiding this comment.
Why does the static build not work on windows?
There was a problem hiding this comment.
The CI reported a bunch of symbol not found errors IIRC. Maybe the logs still exists but I don't know you folks CI well enough to locate them.
If no type is given explicitly the type is STATIC or SHARED based on whether the current value of the variable BUILD_SHARED_LIBS is ON.
This reverts commit 7fb4fde.
|
Hi folks -- this has been dormant for almost two years. Is it ok to close or can we get it in mergeable state? |
Closing as nothing heard. Happy to revisit if this would be helpful. |
This enables building the
wabt-sysRust crate statically using musl.