diff --git a/scripts/check-wasm.sh b/scripts/check-wasm.sh index d353465..b566d60 100755 --- a/scripts/check-wasm.sh +++ b/scripts/check-wasm.sh @@ -19,6 +19,32 @@ if ! swift_command sdk list | grep -qx "$SDK_ID"; then exit 2 fi +# The open-source swift.org toolchain ships the WebAssembly codegen backend; the +# Xcode-bundled Apple toolchain does not. Cross-compiling to wasm through the Xcode +# toolchain therefore aborts deep inside LLVM ("No available targets are compatible +# with triple wasm32-...") with a multi-megabyte stack dump that looks like a code +# bug but is purely a wrong-toolchain setup. When we are not going through swiftly, +# detect that case up front and fail with an actionable message instead. +# +# Discriminate by the compiler's self-reported build tag, not its path: both +# toolchains print "Apple Swift version X", but the Xcode/Apple build tags it +# "(swiftlang-...)" while a swift.org toolchain tags it "(swift-...-RELEASE/SNAPSHOT)". +# The self-report is authoritative however `swift` is symlinked or shimmed (a path +# check misses a /usr/local/bin/swift that links into Xcode). 'swift +# -print-target-info -target wasm32-...' is NOT a usable probe: it succeeds even +# without the backend, because the frontend knows the triple and only codegen is gone. +if ! command -v swiftly >/dev/null 2>&1; then + if swift --version 2>/dev/null | grep -q '(swiftlang-'; then + echo "wasm: the active Swift is the Xcode/Apple toolchain, which has no WebAssembly" >&2 + echo "wasm: codegen backend, so a wasm cross-compile cannot work here and would crash" >&2 + echo "wasm: inside LLVM rather than fail cleanly." >&2 + echo "wasm: install swiftly and the swift.org toolchain that matches '$SWIFT_SELECTOR'" >&2 + echo "wasm: (it ships the wasm backend), or put a swift.org toolchain first as 'swift'," >&2 + echo "wasm: then re-run. See https://www.swift.org/install/ and https://swiftwasm.org." >&2 + exit 2 + fi +fi + swift_command build --swift-sdk "$SDK_ID" swift_command build -c release --swift-sdk "$SDK_ID"