Skip to content

Commit 9fec130

Browse files
committed
Fix CI by forcing the toolchain version we have to use
1 parent 89cb093 commit 9fec130

6 files changed

Lines changed: 85 additions & 51 deletions

File tree

.github/workflows/wasm.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,45 @@ name: wasm
22

33
on:
44
push:
5-
pull_request:
5+
6+
env:
7+
# Required Swift toolchain version for WASM builds
8+
# Must match REQUIRED_TOOLCHAIN_VERSION in scripts/build-and-test-wasm.sh
9+
SWIFT_TOOLCHAIN_VERSION: "DEVELOPMENT-SNAPSHOT-2025-11-03-a"
10+
# Checksum for the WASM SDK (from SwiftWasm release page)
11+
SWIFT_WASM_SDK_CHECKSUM: "879c08f24c36e20e0b3d1fadc37f4c34c089c72caa018aec726d9e0bf84ea6ff"
612

713
jobs:
814
build:
9-
runs-on: macos-latest
10-
15+
runs-on: ubuntu-24.04
1116
steps:
1217
- uses: actions/checkout@v4
1318

14-
# Use Swift 6.0.3 to match the pinned SDK version in build-and-test-wasm.sh
15-
# The script will automatically install the 6.0.3-RELEASE WASM SDK
16-
- name: Install Swift
17-
uses: swift-actions/setup-swift@v2
18-
with:
19-
swift-version: "6.1"
19+
# Install the specific Swift development snapshot required for WASM builds
20+
# Toolchain comes from swift.org, SDK comes from SwiftWasm
21+
- name: Install Swift Toolchain
22+
run: |
23+
SWIFT_URL="https://download.swift.org/development/ubuntu2404/swift-${SWIFT_TOOLCHAIN_VERSION}/swift-${SWIFT_TOOLCHAIN_VERSION}-ubuntu24.04.tar.gz"
24+
echo "Downloading Swift toolchain from: $SWIFT_URL"
25+
mkdir -p /opt/swift
26+
curl -sL "$SWIFT_URL" | tar xz --strip-components=1 -C /opt/swift
27+
echo "/opt/swift/usr/bin" >> $GITHUB_PATH
28+
29+
- name: Verify Swift Installation
30+
run: swift --version
31+
32+
# Install the matching WASM SDK from SwiftWasm
33+
- name: Install WASM SDK
34+
run: |
35+
SDK_URL="https://github.com/swiftwasm/swift/releases/download/swift-wasm-${SWIFT_TOOLCHAIN_VERSION}/swift-wasm-${SWIFT_TOOLCHAIN_VERSION}-wasm32-unknown-wasip1-threads.artifactbundle.zip"
36+
echo "Installing WASM SDK from: $SDK_URL"
37+
swift sdk install "$SDK_URL" --checksum "$SWIFT_WASM_SDK_CHECKSUM"
38+
echo "Installed SDKs:"
39+
swift sdk list
40+
41+
# Set environment variable to signal the correct toolchain is installed
42+
- name: Set Toolchain Environment
43+
run: echo "SWIFT_WASM_TOOLCHAIN_VERIFIED=1" >> $GITHUB_ENV
2044

2145
# Wasmtime is required because `swift test` doesn't work for WebAssembly targets.
2246
# For WASM, we must build tests separately and run them with a WASM runtime.

Tests/PerformanceTests/ArithmeticPefTests.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#if !os(WASI)
21
import XCTest
3-
//@testable import Matft
4-
import Matft
2+
3+
@testable import Matft
54

65
final class ArithmeticPefTests: XCTestCase {
76

@@ -52,4 +51,3 @@ final class ArithmeticPefTests: XCTestCase {
5251
}
5352
}
5453
}
55-
#endif

Tests/PerformanceTests/BoolPefTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
//
77

88
// Performance tests for boolean operations disabled for WASM temporally
9-
#if !os(WASI)
109
import XCTest
1110

1211
@testable import Matft
@@ -69,5 +68,3 @@ final class BoolPefTests: XCTestCase {
6968
}
7069
}
7170
}
72-
73-
#endif

Tests/PerformanceTests/IndexingPefTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// Performance tests for boolean operations disabled for WASM temporally
2-
#if !os(WASI)
32
import XCTest
43

54
@testable import Matft
@@ -20,4 +19,3 @@ final class IndexingPefTests: XCTestCase {
2019
}
2120
}
2221
}
23-
#endif

Tests/PerformanceTests/MathPefTests.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// Performance tests for boolean operations disabled for WASM temporally
2-
#if !os(WASI)
31
//
42
// MathPefTests.swift
53
//
@@ -69,5 +67,3 @@ final class MathPefTests: XCTestCase {
6967
}
7068
}
7169
}
72-
#endif
73-

scripts/build-and-test-wasm.sh

Lines changed: 50 additions & 29 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,41 +39,53 @@ SWIFT_VERSION=""
3539
# Setup Swift command and detect version
3640
setup_swift() {
3741
echo "📦 Setting up Swift..."
42+
echo " Required toolchain: $REQUIRED_TOOLCHAIN_VERSION"
43+
44+
# In CI, the workflow installs the exact toolchain and sets this env var
45+
if [ "${SWIFT_WASM_TOOLCHAIN_VERIFIED:-}" = "1" ] && command -v swift &> /dev/null; then
46+
SWIFT_CMD="swift"
47+
SWIFT_VERSION="dev"
48+
local VERSION_OUTPUT=$(swift --version 2>/dev/null | head -1)
49+
echo "✅ Using CI-installed toolchain"
50+
echo " Version: $VERSION_OUTPUT"
51+
echo ""
52+
return 0
53+
fi
3854

39-
# Check for local SwiftWasm toolchain first (macOS development with newer SDK)
55+
# Check for local SwiftWasm toolchain (macOS development with newer SDK)
4056
TOOLCHAIN_DIR="$HOME/Library/Developer/Toolchains"
4157
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)
58+
# Look for the specific required toolchain version
59+
local WASM_TOOLCHAIN="swift-${REQUIRED_TOOLCHAIN_VERSION}.xctoolchain"
4460

45-
if [ -n "$WASM_TOOLCHAIN" ]; then
61+
if [ -d "$TOOLCHAIN_DIR/$WASM_TOOLCHAIN" ]; then
4662
local TOOLCHAIN_SWIFT="$TOOLCHAIN_DIR/$WASM_TOOLCHAIN/usr/bin/swift"
4763
if [ -x "$TOOLCHAIN_SWIFT" ]; then
4864
SWIFT_CMD="$TOOLCHAIN_SWIFT"
49-
echo "✅ Using local development toolchain: $WASM_TOOLCHAIN"
65+
echo "✅ Using required toolchain: $WASM_TOOLCHAIN"
5066
local VERSION_OUTPUT=$($SWIFT_CMD --version 2>/dev/null | head -1)
5167
echo " Version: $VERSION_OUTPUT"
5268
# Dev toolchain - will use dev SDK
5369
SWIFT_VERSION="dev"
5470
echo ""
5571
return 0
72+
else
73+
echo "❌ Toolchain found but swift binary not executable: $TOOLCHAIN_SWIFT"
74+
exit 1
5675
fi
5776
fi
5877
fi
5978

60-
# Use system Swift (CI environment)
79+
# No matching toolchain found
80+
echo "❌ Required Swift toolchain not found: $REQUIRED_TOOLCHAIN_VERSION"
81+
echo ""
82+
echo " For macOS: Install the toolchain to ~/Library/Developer/Toolchains/"
83+
echo " For Linux/CI: Install from https://download.swift.org/development/"
84+
echo ""
6185
if command -v swift &> /dev/null; then
62-
SWIFT_CMD="swift"
63-
local VERSION_OUTPUT=$($SWIFT_CMD --version 2>/dev/null)
64-
# Extract version number (e.g., "6.1.3" from "Swift version 6.1.3")
65-
SWIFT_VERSION=$(echo "$VERSION_OUTPUT" | grep -oE "Swift version [0-9]+\.[0-9]+(\.[0-9]+)?" | head -1 | sed 's/Swift version //')
66-
echo "✅ Using system Swift"
67-
echo " Version: $SWIFT_VERSION"
68-
echo ""
69-
return 0
86+
echo " Current Swift in PATH:"
87+
swift --version 2>/dev/null | head -1 | sed 's/^/ /'
7088
fi
71-
72-
echo "❌ No Swift installation found"
7389
exit 1
7490
}
7591

@@ -79,27 +95,32 @@ setup_wasm_sdk() {
7995

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

82-
# For development toolchain, try to find matching development SDK first
98+
# For development toolchain, find SDK matching the required toolchain version
8399
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
100+
echo " Required SDK version: $REQUIRED_TOOLCHAIN_VERSION"
101+
102+
# Look for SDK matching the exact required toolchain version (prefer threads variant)
103+
SWIFT_SDK_NAME=$(echo "$INSTALLED_SDKS" | grep "$REQUIRED_TOOLCHAIN_VERSION" | grep "wasm32-unknown-wasip1-threads$" | grep -v "embedded" | head -1)
104+
if [ -n "$SWIFT_SDK_NAME" ]; then
105+
echo "✅ Found matching SDK (threads): $SWIFT_SDK_NAME"
106+
echo ""
107+
return 0
92108
fi
93109

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)
110+
# Try non-threads variant
111+
SWIFT_SDK_NAME=$(echo "$INSTALLED_SDKS" | grep "$REQUIRED_TOOLCHAIN_VERSION" | grep -E "wasm32-unknown-wasi$" | grep -v "embedded" | head -1)
96112
if [ -n "$SWIFT_SDK_NAME" ]; then
97-
echo "✅ Found development SDK: $SWIFT_SDK_NAME"
113+
echo "✅ Found matching SDK: $SWIFT_SDK_NAME"
98114
echo ""
99115
return 0
100116
fi
101117

102-
echo "❌ No development SDK found for development toolchain"
118+
echo "❌ No SDK found matching required version: $REQUIRED_TOOLCHAIN_VERSION"
119+
echo " Available SDKs:"
120+
echo "$INSTALLED_SDKS" | sed 's/^/ - /'
121+
echo ""
122+
echo " Please install the required SDK:"
123+
echo " swift sdk install <sdk-url-for-$REQUIRED_TOOLCHAIN_VERSION>"
103124
exit 1
104125
fi
105126

0 commit comments

Comments
 (0)