Skip to content

Build and run all tests as shared libraries #780

Merged
alexcrichton merged 5 commits intoWebAssembly:mainfrom
alexcrichton:shared-tests
Apr 3, 2026
Merged

Build and run all tests as shared libraries #780
alexcrichton merged 5 commits intoWebAssembly:mainfrom
alexcrichton:shared-tests

Conversation

@alexcrichton
Copy link
Copy Markdown
Collaborator

This PR is derived from #779 to build and run dynamically-linked tests in wasi-libc to help exercise shared-library-related support. This requires the fix from #779, for example, to get tests passing. This takes a different approach to testing, however, to build and run all tests as dynamically linked instead of only some particular tests. This avoids the need for a one-off test and additionally helps reuse all existing infrastructure for tests. This expands the test coverage more and documents a few cases where dynamic libraries don't work (long-float intrinsics and setjmp)

dicej and others added 2 commits April 1, 2026 18:28
This refactors the test building infrastructure to build all tests as
shared libraries in addition to the previous binaries which are all
statically linked.

This required a number of changes and fixes to get this working:

* `wit-bindgen`-generated code is compiled with `-fvisibility=hidden` to
  avoid exposing all of their symbols form shared libraries, notably
  which breaks wasip3 targets currently. These are all private
  implementation details anyway and don't need to be exported.

* Source files in the `wasi-emulated-process-clocks` library are
  reimplemented in terms of libc-like APIs instead of raw WASI APIs
  since the raw APIs are no longer visible across a shared library
  boundary.

* The `libc_test_support` library is deleted in favor of just adding the
  source files to all tests. This avoids needing to wrangle multiple
  libraries for both shared/static and is just easier to manage.

* Support for disabling warnings in third-party code is now per-file
  instead of per-target and some warnings for third-party executables
  have been moved around to help consolidate helper functions here.

* Dynamically-linked tests are compiled with
  `-Wl,--skip-wit-component,-shared` to manually run `wasm-tools
  component link` while still generating dynamic imports with `wasm-ld`.

* One instance of undefined behavior in the `preadwrite.c` test was
  fixed to account for stack data being undefined.
Copy link
Copy Markdown
Collaborator

@dicej dicej left a comment

Choose a reason for hiding this comment

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

Thanks so much for doing this!

add_libc_test(functional/argv.c CFLAGS -Wno-sign-compare)
add_libc_test(functional/basename.c)
add_libc_test(functional/clocale_mbfuncs.c)
add_libc_test(functional/clocale_mbfuncs.c CFLAGS -Wno-unused-variable -Wno-sign-compare)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity, why does each test have its own set of warning flags? Is the goal to incrementally add more flags for more tests and eventually use e.g. -Wall for all the tests?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

These are third-party tests from an external repo so we can't control the source code, but they're compiled with the default flags of -Wall -Wextra`, so this is used to get them. So hopefully just a one-time thing, and this is shuffling around where the flags are specified.

@alexcrichton alexcrichton merged commit 0db888c into WebAssembly:main Apr 3, 2026
32 checks passed
@alexcrichton alexcrichton deleted the shared-tests branch April 3, 2026 13:40
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.

2 participants