I’ve been experimenting with SwiftWASM recently as I’m gearing up for developing a web version of a macOS app I’ve worked on. So far I understand I should be able to reuse the Swift model layer from the Mac and I’m quite excited about that.
I’m rather new to using Swift on non-Darwin platforms and there's definitely a number a challenges I'm facing doing that, but I’ll start with what’s immediately blocking me right now.
Using Carton, I set up a simple website where Swift code is loading an HTML-embedded asset and renders several objects to the DOM via JavaScriptKit. I’d like to add HTML parsing so I’ve added the SwiftSoup package but I hit a snag because the package won’t compile for WASM.
Compiling (with swift build --triple wasm32-unknown-wasi
) returns about 70 errors, all about missing APIs in Foundation's FileHandle. If SwiftSoup made calls to API not yet implemented in swift-corelibs-foundation that would have made sense to me, but each call I sampled appears to have been ported.
For example, here's one such error:
SwiftSoup/Sources/StreamReader.swift:23:42: error: incorrect argument label in call (have 'forReadingAtPath:', expected 'fileDescriptor:')
guard let fileHandle = FileHandle(forReadingAtPath: path),
^~~~~~~~~~~~~~~~~
fileDescriptor
The compiler is basically pointing out that init(forReadingAtPath:)
does not exist on FileHandle but it does appear to exist.
I've also isolated the call out to a new package and got the same error.
Would anyone know what's the cause and how to work around it? Thanks!