Swift Dev Snapshot WebAssembly and JavaScriptKit

· 345 words · 2 minute read

This is continuation to Attempt at Swift WebAssembly.

At first I did not pay attention at JavaScriptKit much. I’ve seen activity in the repo but it was not convincing. Readme does not cover whole story.

I think whole documentation at https://book.swiftwasm.org/ misslead me on wrong path and probably others feels the same way. I would recommend to stay away from it for now.

So, I went to explore JavaScriptKit. But before that I did something else.

Dumb idea 🔗

During the week, in the evenings, I was tinkering with the idea of using Emscripten SDK as a provider of missing functions, runtime and JavaScript glue for the communication. At the time, I used Swift 6.0.3 with a big list of flags.
I went into a spree researching how Emscripten’s build system works. I can’t say that I became an expert but learned a lot of details. After several hacks, I came to the conclusion that it would be a quite big effort to make it work at the scale where JS code is re-generated based on app needs.
The result is an ugly sample, where Swift package is linked to static libraries of the Emscripten SDK. Pushed my stuff to github in swift_package directory.

At this point, I had a Swift package producing an executable which can have dependencies and Emsdk JS glue to run it. My next move would be to try adding JavaScriptKit or, alternatively, use archer sample because it already has it. But Archer uses JS glue from Carton.

Actual Working Example 🔗

Started searching on GitHub for who else is using JavaScriptKit. Came across an elementary project and later a post on forums by Simon Leeb. Unfortunately, Swiftle example did not compile for me with the latest Swift 6.1 dev snapshot. Went back to JavaScriptKit to see examples. Holy moly, why are those not mentioned in the README? Fully functional examples. The link in the README is broken..

Update: updated readme has the correct link to the Examples.

Copied out to the separate repo. I want to build something with it.
Stay tunned.