Support cross-compiling to WebAssembly with a Swift SDK#1817
Merged
Conversation
This was referenced Jun 23, 2026
6c57297 to
0068608
Compare
0068608 to
a3950e6
Compare
keith
reviewed
Jun 24, 2026
keith
left a comment
Member
There was a problem hiding this comment.
didn't get all the way through yet but leaving what i have so far
d9c388f to
cfb60f4
Compare
keith
approved these changes
Jul 6, 2026
Builds on the linkshared and Swift SDK framework PRs. Adds the swift.wasm_sdk module extension tag: it downloads the swift.org WebAssembly Swift SDK artifact bundle matching a swift.toolchain and, using the shared framework, defines Swift and C/C++ toolchains targeting wasm32-unknown-wasip1, so plain swift_library / swift_binary targets build for WebAssembly under --platforms. swift_binary(linkshared = True) gains the WebAssembly reactor output here (-mexec-model=reactor, no main, exported functions). examples/cross_compilation builds a reactor and a static browser web app that drives it from JS.
- Drop the manual tags and the dedicated CI task; the example now builds and tests in the normal //examples/... wildcard on macOS and Linux. The wasm-only Reactor is target_compatible_with os:wasi so host wildcards skip it while the transition still builds it. - Make the example a real executed test: reactor_test runs the reactor under a hermetic wasmtime (dev dependency, downloaded per host) and asserts on the value Swift computes. - Re-enable swift.file_prefix_map for the wasm toolchain: the developer-dir remap moved behind a feature the wasm toolchain doesn't enable (bazelbuild#1825), so the worker no longer requires DEVELOPER_DIR and debug info stays hermetic. - Toss the top-level example README and move the example to a wasm/ subdirectory (done as part of the rebase; the old shared layout was reorganized by the Android PR), with its dev MODULE wiring split into wasm.MODULE.bazel following the Android pattern. Claude-Session: https://claude.ai/code/session_01SmG1kqA3qB4WsLGU2xavuJ
CI passes --test_env=HOME, and linux-sandbox mounts the agent's HOME read-only, so wasmtime's default compilation cache hard-failed with 'failed to create cache directory'. Set XDG_CACHE_HOME to the test tmpdir, and stop swallowing wasmtime's stderr so failures like this are visible in the test log. Claude-Session: https://claude.ai/code/session_01SmG1kqA3qB4WsLGU2xavuJ
- Rebase onto main (dissolves the example bzl_library targets removed by bazelbuild#1826 and the embedded file_prefix_map disables removed by bazelbuild#1824). - Use @bazel_tools//src/conditions for the wasmtime host select instead of bespoke config_settings. - Drop web/README.md (covered by the BUILD file) and trim comments. Claude-Session: https://claude.ai/code/session_01SmG1kqA3qB4WsLGU2xavuJ
Drop the wasm example's redundant header comment and default_visibility (nothing outside the package references its targets), and document why the SDK repository pairs a rules_cc toolchain with the Swift one: it drives the bundle's own clang, resolves only for the wasm target platform, and a consumer's root-module registration takes precedence over it.
cfb60f4 to
20a2dff
Compare
Contributor
Author
|
Rebased onto main (post-#1819) and addressed the remaining comments — the example BUILD nits are applied, and the wasm cc-toolchain registration is kept with the rationale documented inline (wasm-platform-only resolution; root-module registrations take precedence for anyone bringing their own). |
keith
approved these changes
Jul 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WebAssembly support, part of the #1809 split, on top of the now-merged foundation
PRs #1820 (
swift_binary(linkshared)) and #1821 (Swift-SDK framework). A siblingof the Android PR (#1818).
What this adds
swift.wasm_sdk: downloads the swift.org WebAssembly Swift SDK bundle matching aswift.toolchainand, using the shared framework (#1821), defines Swift + C/C++toolchains targeting
wasm32-unknown-wasip1.swift_binary(linkshared = True)gains the WebAssembly reactor output here (
-mexec-model=reactor, nomain,exported functions) — the wasm-specific bit that keith asked to keep out of the
generic
swift_binary.examples/cross_compilationbuilds a reactor and abrowser web app that drives it from JS.
Open questions
-swift.file_prefix_mapis disabled for the wasm toolchain. With it on, theworker's developer-dir remap hard-requires
DEVELOPER_DIRon Apple hosts. Theclean fix is to gate that remap on
swift._supports_developer_dir(theanalysis-time config already is); it touches the shared Apple worker path, so I
wanted your read first.