Skip to content

Commit 0c40e94

Browse files
committed
Fix iOS CI, update WASM CI for testing we will need later and provide some documentation + scripts
1 parent 8d1fa5d commit 0c40e94

7 files changed

Lines changed: 275 additions & 38 deletions

File tree

.github/workflows/swift.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v4
15-
- uses: swift-actions/setup-swift@v1
15+
- uses: swift-actions/setup-swift@v2
1616
with:
17-
swift-version: "5.9.2"
18-
- name: Build
19-
run: swift build -v
20-
- name: Run tests
21-
run: swift test -v
17+
swift-version: "6.0.3"
18+
- name: Build and Test
19+
run: ./scripts/build-and-test-ios.sh

.github/workflows/wasm.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ on:
66

77
jobs:
88
build:
9-
name: Build on WebAssembly
10-
runs-on: ubuntu-latest
11-
container:
12-
image: swift:6.0.2-focal
9+
name: Build and Test on WebAssembly
10+
runs-on: ubuntu-24.04
1311
steps:
1412
- uses: actions/checkout@v4
15-
- run: 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
16-
- name: Build
17-
run: swift build --swift-sdk wasm32-unknown-wasi
18-
- name: Test
19-
run: swift test --swift-sdk wasm32-unknown-wasi
13+
14+
- name: Install Swift
15+
uses: swift-actions/setup-swift@v2
16+
with:
17+
swift-version: "6.0.3"
18+
19+
# Wasmtime is required because `swift test` doesn't work for WebAssembly targets.
20+
# For WASM, we must build tests separately and run them with a WASM runtime.
21+
# See: https://book.swiftwasm.org/getting-started/testing.html
22+
- name: Install Wasmtime
23+
run: |
24+
curl https://wasmtime.dev/install.sh -sSf | bash
25+
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
26+
27+
- name: Build and Test
28+
run: ./scripts/build-and-test-wasm.sh

Package.resolved

Lines changed: 20 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,35 @@
1-
// swift-tools-version:5.1
1+
// swift-tools-version:5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
55

66
let package = Package(
77
name: "Matft",
88
products: [
9-
// Products define the executables and libraries produced by a package, and make them visible to other packages.
109
.library(
1110
name: "Matft",
1211
targets: ["Matft"]),
13-
//.library(name: "ReleaseTest", targets: ["Matft "])
1412
],
1513
dependencies: [
16-
// Dependencies declare other packages that this package depends on.
17-
// .package(url: /* package url */, from: "1.0.0"),
1814
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
19-
15+
.package(url: "https://github.com/GoodNotes/CLAPACK", branch: "eigen-support"),
2016
],
2117
targets: [
22-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
23-
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2418
.target(
2519
name: "pocketFFT"
2620
),
2721
.target(
2822
name: "Matft",
29-
dependencies: ["Collections", "pocketFFT"]),
23+
dependencies: [
24+
.product(name: "Collections", package: "swift-collections"),
25+
"pocketFFT",
26+
.product(name: "CLAPACK", package: "CLAPACK", condition: .when(platforms: [.wasi])),
27+
]),
3028
.testTarget(
3129
name: "MatftTests",
3230
dependencies: ["Matft"]),
3331
.testTarget(
3432
name: "PerformanceTests",
3533
dependencies: ["Matft"]),
3634
]
37-
//cxxLanguageStandard: .gnucxx1z
3835
)

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ INFO: Support Complex!!
2727
+ [SwiftPM](#swiftpm)
2828
+ [Carthage](#carthage)
2929
+ [CocoaPods](#cocoapods)
30+
* [Build Scripts](#-build-scripts)
31+
+ [iOS/macOS Build & Test](#-iosmacos-build--test)
32+
+ [WebAssembly Build & Test](#-webassembly-build--test)
3033
* [Contact](#contact)
3134

3235
<strike>
@@ -858,6 +861,43 @@ So, a pull request is very welcome!!
858861
pod install
859862
```
860863

864+
## 🛠️ Build Scripts
865+
866+
Matft provides convenient bash scripts for building and testing the project locally.
867+
868+
### 🍎 iOS/macOS Build & Test
869+
870+
To build and test Matft for iOS/macOS platforms:
871+
872+
```bash
873+
./scripts/build-and-test-ios.sh
874+
```
875+
876+
This script will:
877+
- Build the project using `swift build`
878+
- Run all tests using `swift test`
879+
880+
### 🌐 WebAssembly Build & Test
881+
882+
To build and test Matft for WebAssembly:
883+
884+
```bash
885+
./scripts/build-and-test-wasm.sh
886+
```
887+
888+
This script will:
889+
- 📦 Check and install the Swift WASM SDK if needed
890+
- 🔧 Check and install wasmtime runtime if needed
891+
- 🔨 Build the project for WebAssembly
892+
- 🧪 Build and run tests using wasmtime
893+
894+
**Note:** The WASM script automatically handles SDK and runtime installation, so you can run it on a fresh machine without any prior setup!
895+
896+
### 📋 Requirements
897+
898+
- **iOS/macOS:** Swift 6.0.3 or later
899+
- **WebAssembly:** Swift 6.0.3 or later (SDK will be automatically installed)
900+
861901
## Contact
862902

863903
Feel free to ask this project or anything via <junnosuke.kado.git@gmail.com>

scripts/build-and-test-ios.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "🍎 =========================================="
5+
echo "🍎 Building and Testing Matft for iOS/macOS"
6+
echo "🍎 =========================================="
7+
echo ""
8+
9+
echo "🔨 Building project..."
10+
swift build -v
11+
12+
echo ""
13+
echo "✅ Build completed successfully!"
14+
echo ""
15+
16+
echo "🧪 Running tests..."
17+
swift test -v
18+
19+
echo ""
20+
echo "🎉 =========================================="
21+
echo "🎉 All tests passed successfully!"
22+
echo "🎉 =========================================="

scripts/build-and-test-wasm.sh

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "🌐 =========================================="
5+
echo "🌐 Building and Testing Matft for WebAssembly"
6+
echo "🌐 =========================================="
7+
echo ""
8+
9+
# Configuration for CI (GitHub Actions)
10+
SWIFT_WASM_SDK_URL="https://github.com/swiftwasm/swift/releases/download/swift-wasm-6.0.3-RELEASE/swift-wasm-6.0.3-RELEASE-wasm32-unknown-wasi.artifactbundle.zip"
11+
SWIFT_WASM_SDK_CHECKSUM="31d3585b06dd92de390bacc18527801480163188cd7473f492956b5e213a8618"
12+
CI_SDK_NAME="wasm32-unknown-wasi"
13+
14+
# Swift command to use (may be overridden if toolchain detected)
15+
SWIFT_CMD="swift"
16+
17+
# Detect development snapshot toolchain with WASM support
18+
detect_toolchain() {
19+
echo "🔍 Detecting Swift toolchain..."
20+
21+
# Check for development snapshot toolchains in the standard location
22+
TOOLCHAIN_DIR="$HOME/Library/Developer/Toolchains"
23+
24+
if [ -d "$TOOLCHAIN_DIR" ]; then
25+
# Find the most recent development snapshot toolchain
26+
TOOLCHAIN=$(ls -1 "$TOOLCHAIN_DIR" 2>/dev/null | grep -E "swift-DEVELOPMENT-SNAPSHOT.*\.xctoolchain" | sort -r | head -1)
27+
28+
if [ -n "$TOOLCHAIN" ]; then
29+
TOOLCHAIN_SWIFT="$TOOLCHAIN_DIR/$TOOLCHAIN/usr/bin/swift"
30+
if [ -x "$TOOLCHAIN_SWIFT" ]; then
31+
SWIFT_CMD="$TOOLCHAIN_SWIFT"
32+
echo "✅ Found development toolchain: $TOOLCHAIN"
33+
return 0
34+
fi
35+
fi
36+
fi
37+
38+
echo "ℹ️ Using system Swift"
39+
return 0
40+
}
41+
42+
# Detect available WASM SDK
43+
detect_wasm_sdk() {
44+
echo "📦 Detecting WASM SDK..."
45+
46+
# Get list of installed SDKs
47+
INSTALLED_SDKS=$($SWIFT_CMD sdk list 2>/dev/null || echo "")
48+
49+
# First, check if the CI SDK is available (for GitHub Actions)
50+
if echo "$INSTALLED_SDKS" | grep -q "^${CI_SDK_NAME}$"; then
51+
SWIFT_SDK_NAME="$CI_SDK_NAME"
52+
echo "✅ Found SDK: $SWIFT_SDK_NAME"
53+
return 0
54+
fi
55+
56+
# For local development with development toolchains, prefer matching SDKs
57+
# Extract toolchain version if using a development toolchain
58+
if echo "$SWIFT_CMD" | grep -q "DEVELOPMENT-SNAPSHOT"; then
59+
TOOLCHAIN_VERSION=$(echo "$SWIFT_CMD" | grep -oE "DEVELOPMENT-SNAPSHOT-[0-9]{4}-[0-9]{2}-[0-9]{2}-a")
60+
if [ -n "$TOOLCHAIN_VERSION" ]; then
61+
SDK_MATCH=$(echo "$INSTALLED_SDKS" | grep "$TOOLCHAIN_VERSION" | grep -v "embedded" | head -1)
62+
if [ -n "$SDK_MATCH" ]; then
63+
SWIFT_SDK_NAME="$SDK_MATCH"
64+
echo "✅ Found matching SDK: $SWIFT_SDK_NAME"
65+
return 0
66+
fi
67+
fi
68+
fi
69+
70+
# Try to find any WASM SDK (prefer development snapshots with threads for local dev)
71+
for pattern in "DEVELOPMENT-SNAPSHOT.*wasm32-unknown-wasip1-threads$" "swift-.*-RELEASE_wasm$" "wasm32-unknown-wasi" "wasm"; do
72+
SDK_MATCH=$(echo "$INSTALLED_SDKS" | grep -E "$pattern" | grep -v "embedded" | head -1)
73+
if [ -n "$SDK_MATCH" ]; then
74+
SWIFT_SDK_NAME="$SDK_MATCH"
75+
echo "✅ Found SDK: $SWIFT_SDK_NAME"
76+
return 0
77+
fi
78+
done
79+
80+
return 1
81+
}
82+
83+
# Install Swift WASM SDK if not found
84+
install_swift_wasm_sdk() {
85+
if detect_wasm_sdk; then
86+
echo ""
87+
return 0
88+
fi
89+
90+
echo "⬇️ No WASM SDK found. Installing Swift WASM SDK..."
91+
$SWIFT_CMD sdk install "$SWIFT_WASM_SDK_URL" --checksum "$SWIFT_WASM_SDK_CHECKSUM"
92+
SWIFT_SDK_NAME="$CI_SDK_NAME"
93+
echo "✅ Swift WASM SDK installed successfully"
94+
echo ""
95+
}
96+
97+
# Check if wasmtime is installed
98+
install_wasmtime() {
99+
echo "🔧 Checking wasmtime..."
100+
if command -v wasmtime &> /dev/null; then
101+
echo "✅ wasmtime already installed: $(wasmtime --version)"
102+
else
103+
echo "⬇️ Installing wasmtime..."
104+
curl https://wasmtime.dev/install.sh -sSf | bash
105+
export PATH="$HOME/.wasmtime/bin:$PATH"
106+
echo "✅ wasmtime installed successfully"
107+
fi
108+
echo ""
109+
}
110+
111+
# Build the project
112+
build_project() {
113+
echo "🔨 Building project for WebAssembly..."
114+
echo " Swift: $SWIFT_CMD"
115+
echo " SDK: $SWIFT_SDK_NAME"
116+
$SWIFT_CMD build --swift-sdk "$SWIFT_SDK_NAME"
117+
echo "✅ Build completed successfully!"
118+
echo ""
119+
}
120+
121+
# Build and run tests
122+
run_tests() {
123+
echo "🧪 Building tests for WebAssembly..."
124+
$SWIFT_CMD build --build-tests --swift-sdk "$SWIFT_SDK_NAME"
125+
echo "✅ Test build completed!"
126+
echo ""
127+
128+
echo "🚀 Running tests with wasmtime..."
129+
# Note: We use wasmtime instead of 'swift test' because swift test doesn't
130+
# work directly for WebAssembly targets. For WASM, we must build tests
131+
# separately and run them with a WASM runtime.
132+
# See: https://book.swiftwasm.org/getting-started/testing.html
133+
134+
# Find the test binary in any wasm build directory
135+
TEST_BINARY=$(find .build -path "*/debug/MatftPackageTests.wasm" -o -path "*/debug/MatftPackageTests.xctest" 2>/dev/null | grep -E "wasm|wasi" | head -1)
136+
137+
if [ -z "$TEST_BINARY" ]; then
138+
echo "❌ Error: Could not find test binary"
139+
echo " Searched in .build/*/debug/ for MatftPackageTests.wasm or .xctest"
140+
exit 1
141+
fi
142+
143+
echo "📍 Test binary: $TEST_BINARY"
144+
145+
# Determine wasmtime flags based on SDK type
146+
WASMTIME_FLAGS="--dir ."
147+
if echo "$SWIFT_SDK_NAME" | grep -q "threads"; then
148+
WASMTIME_FLAGS="$WASMTIME_FLAGS --wasm threads=y --wasi threads=y"
149+
fi
150+
151+
wasmtime run $WASMTIME_FLAGS "$TEST_BINARY"
152+
echo ""
153+
}
154+
155+
# Main execution
156+
detect_toolchain
157+
install_swift_wasm_sdk
158+
install_wasmtime
159+
build_project
160+
run_tests
161+
162+
echo "🎉 =========================================="
163+
echo "🎉 All WASM tests passed successfully!"
164+
echo "🎉 =========================================="

0 commit comments

Comments
 (0)