Skip to content

Commit d2b759d

Browse files
committed
Fix toolchain version
1 parent 89cb093 commit d2b759d

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

scripts/build-and-test-wasm.sh

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ echo "🌐 Building and Testing Matft for WebAssembly"
66
echo "🌐 =========================================="
77
echo ""
88

9+
# Required toolchain version for WASM builds
10+
# This ensures consistent builds across all environments
11+
REQUIRED_TOOLCHAIN_VERSION="DEVELOPMENT-SNAPSHOT-2025-11-03-a"
12+
913
# SDK info for different Swift versions (SDK must match Swift compiler version)
1014
get_sdk_info() {
1115
local SWIFT_VER="$1"
@@ -35,25 +39,33 @@ SWIFT_VERSION=""
3539
# Setup Swift command and detect version
3640
setup_swift() {
3741
echo "📦 Setting up Swift..."
42+
echo " Required toolchain: $REQUIRED_TOOLCHAIN_VERSION"
3843

3944
# Check for local SwiftWasm toolchain first (macOS development with newer SDK)
4045
TOOLCHAIN_DIR="$HOME/Library/Developer/Toolchains"
4146
if [ -d "$TOOLCHAIN_DIR" ]; then
42-
# Look for development snapshot toolchain (needed for newer macOS SDKs)
43-
local WASM_TOOLCHAIN=$(ls -1 "$TOOLCHAIN_DIR" 2>/dev/null | grep -E "swift-DEVELOPMENT-SNAPSHOT.*\.xctoolchain" | sort -r | head -1)
47+
# Look for the specific required toolchain version
48+
local WASM_TOOLCHAIN="swift-${REQUIRED_TOOLCHAIN_VERSION}.xctoolchain"
4449

45-
if [ -n "$WASM_TOOLCHAIN" ]; then
50+
if [ -d "$TOOLCHAIN_DIR/$WASM_TOOLCHAIN" ]; then
4651
local TOOLCHAIN_SWIFT="$TOOLCHAIN_DIR/$WASM_TOOLCHAIN/usr/bin/swift"
4752
if [ -x "$TOOLCHAIN_SWIFT" ]; then
4853
SWIFT_CMD="$TOOLCHAIN_SWIFT"
49-
echo "✅ Using local development toolchain: $WASM_TOOLCHAIN"
54+
echo "✅ Using required toolchain: $WASM_TOOLCHAIN"
5055
local VERSION_OUTPUT=$($SWIFT_CMD --version 2>/dev/null | head -1)
5156
echo " Version: $VERSION_OUTPUT"
5257
# Dev toolchain - will use dev SDK
5358
SWIFT_VERSION="dev"
5459
echo ""
5560
return 0
61+
else
62+
echo "❌ Toolchain found but swift binary not executable: $TOOLCHAIN_SWIFT"
63+
exit 1
5664
fi
65+
else
66+
echo "⚠️ Required toolchain not found locally: $WASM_TOOLCHAIN"
67+
echo " Checked: $TOOLCHAIN_DIR/$WASM_TOOLCHAIN"
68+
echo " Will try system Swift..."
5769
fi
5870
fi
5971

@@ -79,27 +91,32 @@ setup_wasm_sdk() {
7991

8092
local INSTALLED_SDKS=$($SWIFT_CMD sdk list 2>/dev/null || echo "")
8193

82-
# For development toolchain, try to find matching development SDK first
94+
# For development toolchain, find SDK matching the required toolchain version
8395
if [ "$SWIFT_VERSION" = "dev" ]; then
84-
local TOOLCHAIN_DATE=$(echo "$SWIFT_CMD" | grep -oE "[0-9]{4}-[0-9]{2}-[0-9]{2}")
85-
if [ -n "$TOOLCHAIN_DATE" ]; then
86-
SWIFT_SDK_NAME=$(echo "$INSTALLED_SDKS" | grep "DEVELOPMENT-SNAPSHOT-${TOOLCHAIN_DATE}" | grep -E "wasm32-unknown-wasi" | grep -v "embedded" | head -1)
87-
if [ -n "$SWIFT_SDK_NAME" ]; then
88-
echo "✅ Found matching development SDK: $SWIFT_SDK_NAME"
89-
echo ""
90-
return 0
91-
fi
96+
echo " Required SDK version: $REQUIRED_TOOLCHAIN_VERSION"
97+
98+
# Look for SDK matching the exact required toolchain version (prefer threads variant)
99+
SWIFT_SDK_NAME=$(echo "$INSTALLED_SDKS" | grep "$REQUIRED_TOOLCHAIN_VERSION" | grep "wasm32-unknown-wasip1-threads$" | grep -v "embedded" | head -1)
100+
if [ -n "$SWIFT_SDK_NAME" ]; then
101+
echo "✅ Found matching SDK (threads): $SWIFT_SDK_NAME"
102+
echo ""
103+
return 0
92104
fi
93105

94-
# Fallback to any development snapshot SDK
95-
SWIFT_SDK_NAME=$(echo "$INSTALLED_SDKS" | grep "DEVELOPMENT-SNAPSHOT" | grep "wasm32-unknown-wasip1-threads$" | grep -v "embedded" | sort -r | head -1)
106+
# Try non-threads variant
107+
SWIFT_SDK_NAME=$(echo "$INSTALLED_SDKS" | grep "$REQUIRED_TOOLCHAIN_VERSION" | grep -E "wasm32-unknown-wasi$" | grep -v "embedded" | head -1)
96108
if [ -n "$SWIFT_SDK_NAME" ]; then
97-
echo "✅ Found development SDK: $SWIFT_SDK_NAME"
109+
echo "✅ Found matching SDK: $SWIFT_SDK_NAME"
98110
echo ""
99111
return 0
100112
fi
101113

102-
echo "❌ No development SDK found for development toolchain"
114+
echo "❌ No SDK found matching required version: $REQUIRED_TOOLCHAIN_VERSION"
115+
echo " Available SDKs:"
116+
echo "$INSTALLED_SDKS" | sed 's/^/ - /'
117+
echo ""
118+
echo " Please install the required SDK:"
119+
echo " swift sdk install <sdk-url-for-$REQUIRED_TOOLCHAIN_VERSION>"
103120
exit 1
104121
fi
105122

0 commit comments

Comments
 (0)