POC: Embedded Swift consumers of dispatch on wasm32-unknown-wasip1 - #7
Draft
scottmarchant wants to merge 4 commits into
Draft
POC: Embedded Swift consumers of dispatch on wasm32-unknown-wasip1#7scottmarchant wants to merge 4 commits into
scottmarchant wants to merge 4 commits into
Conversation
Two gated changes make all nine overlay files compile with -enable-experimental-feature Embedded, with no API removed and no signature moved: - Import _DispatchOverlayShims plainly under #if hasFeature(Embedded). Embedded Swift compiles public functions into the client, so an @_implementationOnly import is unusable from them (56 errors). - Constrain DispatchSourceProtocol through a conditional typealias that is AnyObject under Embedded and Any elsewhere. Embedded Swift only supports class-bound existentials, and the make*Source factories return them (14 errors). The only conformer is the DispatchSource class, so the bound is factual. Non-embedded arms are unchanged: the cooperative WASI suite still passes 52 of 52 with these edits. Co-authored-by: Krzysztof Rodak <krodak.konta@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
cmake ... -DDISPATCH_WASI_EMBEDDED=ON -DENABLE_SWIFT=YES builds libdispatch.a, libBlocksRuntime.a, and libswiftDispatch.a in Embedded Swift mode. The knob appends -enable-experimental-feature Embedded, selects usr/lib/swift as the Swift resource dir (the embedded stdlib modules live there), forces CMAKE_Swift_COMPILATION_MODE=wholemodule and propagates it through try_compile (or the compiler check runs incrementally and reports the compiler as broken), and defines __EMBEDDED_SWIFT__ on the C side to match the SDK's embedded toolset. The C library produced with the knob is the cooperative port, unchanged. The regular configuration is unaffected: the cooperative suite still passes 52 of 52 after a reconfigure. Co-authored-by: Krzysztof Rodak <krodak.konta@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add tests/wasm/embedded-dispatch-smoke.swift, an Embedded Swift
consumer of the overlay built in embedded mode. Under wasmtime v24
LTS and current wasmtime v47 it prints:
PASS: async=8/8 sync=1 group=1 timer=1 source=1 data=4
Coverage: eager async on the cooperative backend, serial sync,
DispatchGroup wait, a dispatch_after timer firing while a semaphore
wait pumps, a timer DispatchSource through the class-bound existential
path, and DispatchData append/iterate through the shims funnel. The
same source builds to 572 KB embedded vs 7.8 MB with the regular
static-stdlib SDK.
Co-authored-by: Krzysztof Rodak <krodak.konta@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add tests/wasm/EMBEDDED-RESEARCH.md: the official swift.org embedded wasm SDK shares the wasm32-unknown-wasip1 triple and sysroot with the regular SDK and differs only in toolset flags, so the C library and the cooperative event backend need zero changes. Record the toolchain facts that cost time: the host toolchain lacks wasm compiler-rt builtins (override the clang resource dir), Embedded Swift emits no autolink metadata (consumers must name every archive), whole-module mode is mandatory, and wasi-libc clockid macros do not import. Co-authored-by: Krzysztof Rodak <krodak.konta@gmail.com> Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fork-only proof of concept. This PR is a draft on purpose and is not meant to merge. It shows the Embedded Swift research on top of #3 (the combined WASI port). The full findings live in
tests/wasm/EMBEDDED-RESEARCH.mdon this branch. The series tracker is #3.Summary
An Embedded Swift program can import Dispatch and use it today, with the official swift.org
swift-6.3.3-RELEASE_wasm-embeddedSDK. The smoke test dispatches work, waits on semaphores and groups, arms a timer source, and walks aDispatchData. It passes under both wasmtime v24 LTS and current wasmtime v47 (the output is a plain wasip1 module, so there is no runtime constraint):Binary size is the headline: the same consumer builds to 572 KB embedded vs 7.8 MB with the regular static-stdlib SDK, about 13.6x smaller. The cooperative suite still passes 52 of 52 with these edits.
What this dictates for #3 and #5
@_implementationOnly) shims import under#if hasFeature(Embedded), and a class bound onDispatchSourceProtocolthrough a conditional typealias (AnyObjectunder Embedded,Anyelsewhere). The typealias is the one cross-platform-visible addition; an upstream reviewer may prefer a different spelling.Discoveries specific to embedded
linkdirectives in the module maps are ignored, so consumers must name every archive on the link line. The regular SDK autolinks them.CMAKE_Swift_COMPILATION_MODE=wholemodule, and it must be propagated intotry_compileor the Swift compiler check fails.-Xclang-linker -resource-dir ...).CLOCK_MONOTONICis a pointer macro to an incomplete struct and does not import into Embedded Swift. The overlay is unaffected (it funnels through the C shims); consumer code that uses raw libc clocks will notice.DISPATCH_WASI_EMBEDDED=ONbuilds libdispatch.a, libBlocksRuntime.a, and libswiftDispatch.a in embedded mode.BUILD_TESTINGstays OFF: an embedded ctest lane is future work.Commits
Four conventional commits: the two overlay edits, the CMake knob, the smoke test, and the research notes.