Skip to content

Create a static wasm C API instead of shared - #1602

Closed
basvandijk wants to merge 4 commits into
WebAssembly:mainfrom
basvandijk:shared
Closed

basvandijk wants to merge 4 commits into
WebAssembly:mainfrom
basvandijk:shared

Conversation

@basvandijk

Copy link
Copy Markdown

This enables building the wabt-sys Rust crate statically using musl.

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]
```

@binji binji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, @sbc100 wdyt?

Comment thread CMakeLists.txt
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread CMakeLists.txt
Comment on lines +370 to +374
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 ()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Suggested change
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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the static build not work on windows?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Base automatically changed from master to main March 22, 2021 16:57
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.
@keithw

keithw commented Feb 13, 2023

Copy link
Copy Markdown
Member

Hi folks -- this has been dormant for almost two years. Is it ok to close or can we get it in mergeable state?

@keithw

keithw commented Mar 7, 2023

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants