WebAssembly + SwiftPM

Okay, I started setting it up and managed to get a heavily stripped‐down package to build. Foundation and Dispatch didn’t work, but that wasn’t much of a surprise at this early stage.

Two issues that did surprise me were:

  1. The Linux toolchain doesn’t seem to work. (macOS did.)

    $ swift build --triple wasm32-unknown-wasi
    /usr/bin/swift-build: error while loading shared libraries: libFoundation.so: cannot open shared object file: No such file or directory
    

    (Full context here.)

    The error occurs while it is trying to lead the manifest, so I think it is the host’s Foundation that is expected but missing. I tried installing a standard toolchain at /, (and then using the WASI toolchain installed elsewhere) but it didn’t help. I imagine it only works on macOS because Foundation is part of the operating system. There might be problems ahead if at some point the toolchain expects a bundled version newer than the system has.

  2. It crashed when I attempted to use an imported C function.

    $ .build/SDG/Swift/usr/bin/swift build --triple wasm32-unknown-wasi
    [1/6] Compiling WSCrossPlatformC CrossPlatform.c
    <unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
    <unknown>:0: note: Functions with 'no-prototype' attribute must take varargs: helloC
    

    (Full context and stack trace here.)

But I must say, this is vastly simpler to install and use than the comparable Android and Windows toolchains. Apparently I had it backwards when I decided to start easy and try the others first. Well done!