Hi,
I'm trying to build my Swift project to WebAssembly without WASI (app will run in browser on client side). Building single file works great (took example from Some feedback from my short experience with SwiftWasm - #5 by Max_Desiatov):
swiftc -Osize -Xcc -fdeclspec -target wasm32-unknown-none-wasm -enable-experimental-feature Extern -enable-experimental-feature Embedded -wmo Sources/main.swift -c -o main.o
/opt/homebrew/opt/lld/bin/wasm-ld --no-entry main.o -o main.wasm
But when I'm trying to do it using swift build
:
swift build --triple wasm32-unknown-none-wasm --product app -c release -Xswiftc -enable-experimental-feature -Xswiftc Extern -Xswiftc -enable-experimental-feature -Xswiftc Embedded -Xswiftc -Xcc -Xswiftc -fdeclspec
with Package.swift:
import PackageDescription
let package = Package(
name: "app",
products: [
.executable(name: "app", targets: ["app"])
],
targets: [
.executableTarget(name: "app"),
]
)
it throws an error:
error: link command failed with exit code 1 (use -v to see invocation)
wasm-ld: error: cannot open crt1.o: No such file or directory
wasm-ld: error: unable to find library -lc
wasm-ld: error: cannot open /Users/user/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a.xctoolchain/usr/lib/clang/17/lib/wasm32-unknown-none-wasm/libclang_rt.builtins.a: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
So for some reason builder adds to the linker command this parameters:
crt1.o \
-lc /Users/user/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-06-12-a.xctoolchain/usr/lib/clang/17/lib/wasm32-unknown-none-wasm/libclang_rt.builtins.a \
They are not required for successful linking. Is it possible somehow to tell SwiftPM to remove it from linking process?