Web App with Embedded Swift - POC demo

Another newsletter from your friendly neighborhood swift tinkerer:

I managed to migrate to the 6.2 swift.org WebAssembly SDKs essentially without any issues.

Building embedded wasm files now works with plain old SwiftPM - no custom linking scripts or other tricks outside of the official SDK needed!

As an example, here is the command for the Swiftle demo (using JavaScriptKit's js plugin for wasm-opt and packaging)

# build.sh - 6.2-snapshot-2025-08-21
swift package \
--swift-sdk "$(swiftc -print-target-info | jq -r '.swiftCompilerTag')_wasm-embedded" \
--enable-experimental-prebuilts \
--allow-writing-to-package-directory \
js -c release --output $OUTDIR --use-cdn

I think this is fantastic progress!

In general, the WebAssembly/JS-interop part has never given me any issues (that I know of).

Now, the embedded part still has a few sharp edges in store for you. I stubbed my toe on at least these issues:

And, more generally, every now and then you accidentally use some API that requires unicode handling - but nobody tells you where. All you get is a "where is my _swift_stdlib_getNormData symbol?" linker error, but to my knowledge, there is no way to get a diagnostic on the line in question for this.

In other news, I refactored the reconciler part a tiny bit (ie: complete overhaul) with the goal of making it fit for transitions and animations. It came out as a completely generic node tree, which should be great for runtime performance (no double dispatch, almost no indirections, reduced allocations) - but I fear the code size consequences, we will see.

I thought I was being very clever making rendered nodes generic over a ~Copyable protocol, but associated types are not yet able to suppress Copyable. Also, noncopyable tuples don't work, and enum and collection handling of noncopyables is still rough anyway, so I guess we'll have to call that idea a "future direction" for now - sure would be cool.

In conclusion, I believe there is not much keeping us from having a viable solution for low-fuss real-life client-side web apps written in Swift. In my mind the only real "blocker" is missing first-class handling of JSON data that works in Embedded Swift. But once the much desired future of serialization & deserialization APIs enters the chat, we should be good on that front.

Other nice-to-haves would include Observation for Embedded (maybe more support for KeyPaths in general) and the dust settling around _Concurrency/@MainActor/Swift 6 language mode in Embedded Wasm.

wdyt?

6 Likes