Skip to content

Swift Wasm

Install

  1. Check Swift Version
shell
$ swift --version
swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: x86_64-apple-macosx14.0
  1. Find the compatible Swift SDK for cross-compilation
  2. Install the Swift SDK for WebAssembly
shell
$ swift sdk install https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.0.2-RELEASE/swift-wasm-6.0.2-RELEASE-wasm32-unknown-wasi.artifactbundle.zip --checksum 6ffedb055cb9956395d9f435d03d53ebe9f6a8d45106b979d1b7f53358e1dcb4
  1. Check the installed SDKs
shell
$ swift sdk list
6.0.2-RELEASE-wasm32-unknown-wasi
  1. Remove the SDK
    Once you don't need the SDK, you can remove it using the following command:
shell
$ swift sdk remove <Swift SDK id>

How to use the Swift SDK

  1. Create a new Swift package
shell
$ mkdir Example
$ cd Example
$ swift package init --type executable
  1. Build the package using the Swift SDK (failed...)
shell
$ swift build --swift-sdk wasm32-unknown-wasi
Building for debugging...
error: emit-module command failed due to signal 6 (use -v to see invocation)
error: compile command failed due to signal 6 (use -v to see invocation)
<unknown>:0: error: fatal error encountered during compilation; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
<unknown>:0: note: No available targets are compatible with triple "wasm32-unknown-wasi"
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	<eof> parser at end of file
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000106e2f968 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 40
1  swift-frontend           0x0000000106e2d739 llvm::sys::RunSignalHandlers() + 233
2  swift-frontend           0x0000000106e2ff26 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007ff810382fdd _sigtramp + 29
4  libsystem_platform.dylib 0x735f0c18ce3ff454 _sigtramp + 8313236034427536532
5  libsystem_c.dylib        0x00007ff810279a79 abort + 126
6  swift-frontend           0x000000010101101a swift::DiagnosticHelper::Implementation::diagnoseFatalError(char const*, bool) + 762
7  swift-frontend           0x0000000106d93752 llvm::report_fatal_error(llvm::Twine const&, bool) + 402
8  swift-frontend           0x0000000103db6174 (anonymous namespace)::PCHContainerGenerator::HandleTranslationUnit(clang::ASTContext&) + 2132
9  swift-frontend           0x00000001049de20c clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) + 44
10 swift-frontend           0x0000000104bc35e6 clang::ParseAST(clang::Sema&, bool, bool) + 550
11 swift-frontend           0x00000001049a7415 clang::FrontendAction::Execute() + 85
12 swift-frontend           0x00000001048ebaba clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1162
13 swift-frontend           0x00000001048f77bf void llvm::function_ref<void ()>::callback_fn<compileModuleImpl(clang::CompilerInstance&, clang::SourceLocation, llvm::StringRef, clang::FrontendInputFile, llvm::StringRef, llvm::StringRef, llvm::function_ref<void (clang::CompilerInstance&)>, llvm::function_ref<void (clang::CompilerInstance&)>)::$_1>(long) + 159
14 swift-frontend           0x0000000106d89866 RunSafelyOnThread_Dispatch(void*) + 38
15 swift-frontend           0x0000000106d8988f void* llvm::thread::ThreadProxy<std::__1::tuple<void (*)(void*), (anonymous namespace)::RunSafelyOnThreadInfo*>>(void*) + 15
16 libsystem_pthread.dylib  0x00007ff81035418b _pthread_start + 99
17 libsystem_pthread.dylib  0x00007ff81034fae3 thread_start + 15

References