Skip to content

[DRAFT] Add WASIp2 build and test support#3147

Draft
justsmth wants to merge 3 commits intoaws:mainfrom
justsmth:wasip2-support
Draft

[DRAFT] Add WASIp2 build and test support#3147
justsmth wants to merge 3 commits intoaws:mainfrom
justsmth:wasip2-support

Conversation

@justsmth
Copy link
Copy Markdown
Contributor

@justsmth justsmth commented Apr 8, 2026

Description of changes:

Depends on #3146 (portability guards).

Add support for building and testing AWS-LC on the wasm32-wasip2 target using the WASI SDK. WASI Preview 2 does not support pthreads, BSD sockets, or terminal I/O, so the corresponding capability flags in target.h are set when OPENSSL_WASM_WASI is defined.

This PR contains the WASI platform definitions, build infrastructure, and CI — the general-purpose portability guards it depends on are in #3146.

Platform detection (target.h):

  • Define OPENSSL_WASM_WASI and OPENSSL_WASM_EMSCRIPTEN sub-macros under OPENSSL_WASM.
  • WASI sets OPENSSL_NO_SOCK, OPENSSL_NO_TTY, and OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED.

New files:

  • util/wasi-sdk-toolchain.cmake — CMake toolchain file for cross-compiling to wasm32-wasip2.
  • tests/ci/run_wasi_tests.sh — CI script that builds AWS-LC and runs crypto_test, ssl_test, and urandom_test under wasmtime.
  • .github/workflows/wasi.yml — CI workflow for WASI builds.

Call-outs:

  • boringssl_gtest_main is built as an OBJECT library (instead of STATIC) on WASI to work around wasm-ld not pulling main from static archives.
  • The iovec redefinition guard in ssl/bio_ssl.cc is scoped to OPENSSL_WASM_WASI; WASI's libc provides iovec through standard headers so the redefinition would be a conflict.
  • The WASI CI workflow is kept separate from emscripten.yml.

Testing:

The wasi.yml CI workflow builds with WASI SDK 25 and runs tests under wasmtime 29.0.1. crypto_test, ssl_test, and urandom_test are executed with a gtest filter excluding tests that require fork, sockets, threads, or unsupported file operations.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.

…ENSSL_NO_TTY

Add compile-time guards to tests and source files for platforms that lack
sockets, threads, or terminal I/O. These guards use the existing
OPENSSL_NO_SOCK and OPENSSL_THREADS feature flags, and introduce a new
OPENSSL_NO_TTY flag.

- Guard BIO_new_ssl_connect declaration and implementation behind
  OPENSSL_NO_SOCK, matching the existing pattern for SSL_set_fd et al.
- Add OPENSSL_NO_TTY stub implementations in crypto/console/console.c.
- Guard socket-dependent tests with OPENSSL_NO_SOCK.
- Guard thread-dependent tests with OPENSSL_THREADS.
- Fix GTEST_HAS_DEATH_TEST checks to use value (not defined) so that
  defining it to 0 correctly disables death tests.
Add support for building and testing AWS-LC on the wasm32-wasip2 target
using the WASI SDK. WASI Preview 2 does not support pthreads, BSD
sockets, or terminal I/O.

Platform detection (target.h):
- Define OPENSSL_WASM_WASI and OPENSSL_WASM_EMSCRIPTEN sub-macros under
  OPENSSL_WASM.
- WASI sets OPENSSL_NO_SOCK, OPENSSL_NO_TTY, and
  OPENSSL_NO_THREADS_CORRUPT_MEMORY_AND_LEAK_SECRETS_IF_THREADED.

New files:
- util/wasi-sdk-toolchain.cmake: CMake toolchain file for cross-compiling
  to wasm32-wasip2 via the WASI SDK.
- tests/ci/run_wasi_tests.sh: CI script that builds AWS-LC and runs
  crypto_test, ssl_test, and urandom_test under wasmtime.
- .github/workflows/wasi.yml: CI workflow for WASI builds.

Build system changes:
- Skip pthread linking on Generic systems (WASI).
- Skip rwlock_static_init, OCSP integration test, and bssl_shim on
  Generic systems.
- Build boringssl_gtest_main as OBJECT library on WASI to work around
  wasm-ld not pulling main from static archives.

Source changes:
- Guard iovec redefinition in ssl/bio_ssl.cc for WASI.
- Guard fork-dependent tests and sys/wait.h includes.
- Add WASI-compatible temp file/dir utilities in test helpers.
@justsmth justsmth changed the title Add WASIp2 build and test support [DRAFT] Add WASIp2 build and test support Apr 8, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.95%. Comparing base (d20035a) to head (b231c84).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3147      +/-   ##
==========================================
- Coverage   78.13%   77.95%   -0.18%     
==========================================
  Files         689      689              
  Lines      122510   122510              
  Branches    17074    17094      +20     
==========================================
- Hits        95722    95507     -215     
- Misses      25889    26105     +216     
+ Partials      899      898       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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