Skip to content

[DRAFT] Add wasm32-unknown-emscripten build and test support#1059

Draft
justsmth wants to merge 5 commits intoaws:mainfrom
justsmth:support-wasm-emscripten
Draft

[DRAFT] Add wasm32-unknown-emscripten build and test support#1059
justsmth wants to merge 5 commits intoaws:mainfrom
justsmth:support-wasm-emscripten

Conversation

@justsmth
Copy link
Copy Markdown
Contributor

Description of changes:

Adds support for building and testing aws-lc-rs targeting wasm32-unknown-emscripten, following the addition of Emscripten build support in AWS-LC.

Build fix (aws-lc-sys cc builder): Emscripten uses musl libc, which hides POSIX declarations (sigaction, fileno, etc.) behind feature test macros when compiling with strict -std=c11. The cc builder already defined _XOPEN_SOURCE=700 for Linux for the same reason; this PR extends that to Emscripten.

Jitter entropy on WASM: CPU jitter entropy is meaningless in a WASM sandbox, so disable_jitter_entropy() now defaults to true for wasm* targets. This also fixes a pre-existing awkwardness where the function returned Option<bool> and several call sites had subtly easy-to-misread conditions.

WASM stack size: The default Emscripten stack size (64KB) causes a stack overflow during regex compilation in tests. Increased to 1MB via a target-specific rustflags entry in .cargo/config.toml.

Thread-based tests: Three *_thread_safeness tests unconditionally spawn OS threads, which isn't supported in this Emscripten environment. They are gated out with #[cfg(not(target_arch = "wasm32"))].

Doctest with filesystem access: One doctest in signature.rs reads .der files from tests/data/, which aren't available in the Emscripten virtual filesystem. The file I/O is guarded with a hidden cfg! check so the doctest still compiles everywhere but only executes on non-WASM targets.

Call-outs:

  • Inverted jitter entropy conditions: The refactor of disable_jitter_entropy() from Option<bool> to bool introduced two inverted conditions (add_includes and compile_intermediates in cc_builder.rs). These are fixed in this PR but reviewers should verify the before/after logic is correct — when jitter entropy is not disabled, both the include path and object file compilation must be active.
  • New Dockerfile (docker/emscripten/Dockerfile): Builds on the cross-rs emscripten base image but replaces both the Emscripten SDK (upgraded to 3.1.74) and Node.js (upgraded to 20 LTS). The base image's Node.js is too old to support the WebAssembly Exception Handling proposal, which modern Rust compilers generate for this target. The /emsdk directory is made world-writable so the non-root cross-rs build user can write to the Emscripten cache.

Testing:

Tested end-to-end using cross test -p aws-lc-rs --target wasm32-unknown-emscripten with the new Dockerfile. Added wasm32-unknown-emscripten to the aws-lc-rs-cross-test CI matrix.

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.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.66%. Comparing base (c358484) to head (735e9e5).
⚠️ Report is 358 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1059      +/-   ##
==========================================
- Coverage   95.80%   92.66%   -3.14%     
==========================================
  Files          61       71      +10     
  Lines        8143    10149    +2006     
  Branches        0    10149   +10149     
==========================================
+ Hits         7801     9405    +1604     
- Misses        342      452     +110     
- Partials        0      292     +292     

☔ 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.

@justsmth justsmth force-pushed the support-wasm-emscripten branch from c19c53b to c03bdb0 Compare April 9, 2026 17:07
@justsmth justsmth force-pushed the support-wasm-emscripten branch from a7a01fd to 735e9e5 Compare April 10, 2026 15:05
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