From 0c40e941adaa222de34340fe33641b185ac35ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Go=CC=81mez?= Date: Fri, 16 Jan 2026 16:11:01 +0100 Subject: [PATCH] Fix iOS CI, update WASM CI for testing we will need later and provide some documentation + scripts --- .github/workflows/swift.yml | 10 +- .github/workflows/wasm.yml | 27 ++++-- Package.resolved | 33 ++++--- Package.swift | 17 ++-- README.md | 40 ++++++++ scripts/build-and-test-ios.sh | 22 +++++ scripts/build-and-test-wasm.sh | 164 +++++++++++++++++++++++++++++++++ 7 files changed, 275 insertions(+), 38 deletions(-) create mode 100755 scripts/build-and-test-ios.sh create mode 100755 scripts/build-and-test-wasm.sh diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 11da17e..8e08548 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -12,10 +12,8 @@ jobs: steps: - uses: actions/checkout@v4 - - uses: swift-actions/setup-swift@v1 + - uses: swift-actions/setup-swift@v2 with: - swift-version: "5.9.2" - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v + swift-version: "6.0.3" + - name: Build and Test + run: ./scripts/build-and-test-ios.sh diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index b7e358e..ae879c7 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -6,14 +6,23 @@ on: jobs: build: - name: Build on WebAssembly - runs-on: ubuntu-latest - container: - image: swift:6.0.2-focal + name: Build and Test on WebAssembly + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - - 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 - - name: Build - run: swift build --swift-sdk wasm32-unknown-wasi - - name: Test - run: swift test --swift-sdk wasm32-unknown-wasi \ No newline at end of file + + - name: Install Swift + uses: swift-actions/setup-swift@v2 + with: + swift-version: "6.0.3" + + # Wasmtime is required because `swift test` doesn't work for WebAssembly targets. + # For WASM, we must build tests separately and run them with a WASM runtime. + # See: https://book.swiftwasm.org/getting-started/testing.html + - name: Install Wasmtime + run: | + curl https://wasmtime.dev/install.sh -sSf | bash + echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH + + - name: Build and Test + run: ./scripts/build-and-test-wasm.sh diff --git a/Package.resolved b/Package.resolved index 6d120da..becf2b5 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,16 +1,23 @@ { - "object": { - "pins": [ - { - "package": "swift-collections", - "repositoryURL": "https://github.com/apple/swift-collections", - "state": { - "branch": null, - "revision": "48254824bb4248676bf7ce56014ff57b142b77eb", - "version": "1.0.2" - } + "pins" : [ + { + "identity" : "clapack", + "kind" : "remoteSourceControl", + "location" : "https://github.com/GoodNotes/CLAPACK", + "state" : { + "branch" : "eigen-support", + "revision" : "a9c8a67890a31af54ed55536b5dd606d6de609a9" } - ] - }, - "version": 1 + }, + { + "identity" : "swift-collections", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-collections", + "state" : { + "revision" : "48254824bb4248676bf7ce56014ff57b142b77eb", + "version" : "1.0.2" + } + } + ], + "version" : 2 } diff --git a/Package.swift b/Package.swift index 4d44471..4d260b5 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.9 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -6,27 +6,25 @@ import PackageDescription let package = Package( name: "Matft", products: [ - // Products define the executables and libraries produced by a package, and make them visible to other packages. .library( name: "Matft", targets: ["Matft"]), - //.library(name: "ReleaseTest", targets: ["Matft "]) ], dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), .package(url: "https://github.com/apple/swift-collections", from: "1.0.0"), - + .package(url: "https://github.com/GoodNotes/CLAPACK", branch: "eigen-support"), ], targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "pocketFFT" ), .target( name: "Matft", - dependencies: ["Collections", "pocketFFT"]), + dependencies: [ + .product(name: "Collections", package: "swift-collections"), + "pocketFFT", + .product(name: "CLAPACK", package: "CLAPACK", condition: .when(platforms: [.wasi])), + ]), .testTarget( name: "MatftTests", dependencies: ["Matft"]), @@ -34,5 +32,4 @@ let package = Package( name: "PerformanceTests", dependencies: ["Matft"]), ] - //cxxLanguageStandard: .gnucxx1z ) diff --git a/README.md b/README.md index ce382f2..cadde3b 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,9 @@ INFO: Support Complex!! + [SwiftPM](#swiftpm) + [Carthage](#carthage) + [CocoaPods](#cocoapods) + * [Build Scripts](#-build-scripts) + + [iOS/macOS Build & Test](#-iosmacos-build--test) + + [WebAssembly Build & Test](#-webassembly-build--test) * [Contact](#contact) @@ -858,6 +861,43 @@ So, a pull request is very welcome!! pod install ``` +## ๐Ÿ› ๏ธ Build Scripts + +Matft provides convenient bash scripts for building and testing the project locally. + +### ๐ŸŽ iOS/macOS Build & Test + +To build and test Matft for iOS/macOS platforms: + +```bash +./scripts/build-and-test-ios.sh +``` + +This script will: +- Build the project using `swift build` +- Run all tests using `swift test` + +### ๐ŸŒ WebAssembly Build & Test + +To build and test Matft for WebAssembly: + +```bash +./scripts/build-and-test-wasm.sh +``` + +This script will: +- ๐Ÿ“ฆ Check and install the Swift WASM SDK if needed +- ๐Ÿ”ง Check and install wasmtime runtime if needed +- ๐Ÿ”จ Build the project for WebAssembly +- ๐Ÿงช Build and run tests using wasmtime + +**Note:** The WASM script automatically handles SDK and runtime installation, so you can run it on a fresh machine without any prior setup! + +### ๐Ÿ“‹ Requirements + +- **iOS/macOS:** Swift 6.0.3 or later +- **WebAssembly:** Swift 6.0.3 or later (SDK will be automatically installed) + ## Contact Feel free to ask this project or anything via diff --git a/scripts/build-and-test-ios.sh b/scripts/build-and-test-ios.sh new file mode 100755 index 0000000..5e17c6d --- /dev/null +++ b/scripts/build-and-test-ios.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +echo "๐ŸŽ ==========================================" +echo "๐ŸŽ Building and Testing Matft for iOS/macOS" +echo "๐ŸŽ ==========================================" +echo "" + +echo "๐Ÿ”จ Building project..." +swift build -v + +echo "" +echo "โœ… Build completed successfully!" +echo "" + +echo "๐Ÿงช Running tests..." +swift test -v + +echo "" +echo "๐ŸŽ‰ ==========================================" +echo "๐ŸŽ‰ All tests passed successfully!" +echo "๐ŸŽ‰ ==========================================" diff --git a/scripts/build-and-test-wasm.sh b/scripts/build-and-test-wasm.sh new file mode 100755 index 0000000..77734c4 --- /dev/null +++ b/scripts/build-and-test-wasm.sh @@ -0,0 +1,164 @@ +#!/bin/bash +set -e + +echo "๐ŸŒ ==========================================" +echo "๐ŸŒ Building and Testing Matft for WebAssembly" +echo "๐ŸŒ ==========================================" +echo "" + +# Configuration for CI (GitHub Actions) +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" +SWIFT_WASM_SDK_CHECKSUM="31d3585b06dd92de390bacc18527801480163188cd7473f492956b5e213a8618" +CI_SDK_NAME="wasm32-unknown-wasi" + +# Swift command to use (may be overridden if toolchain detected) +SWIFT_CMD="swift" + +# Detect development snapshot toolchain with WASM support +detect_toolchain() { + echo "๐Ÿ” Detecting Swift toolchain..." + + # Check for development snapshot toolchains in the standard location + TOOLCHAIN_DIR="$HOME/Library/Developer/Toolchains" + + if [ -d "$TOOLCHAIN_DIR" ]; then + # Find the most recent development snapshot toolchain + TOOLCHAIN=$(ls -1 "$TOOLCHAIN_DIR" 2>/dev/null | grep -E "swift-DEVELOPMENT-SNAPSHOT.*\.xctoolchain" | sort -r | head -1) + + if [ -n "$TOOLCHAIN" ]; then + TOOLCHAIN_SWIFT="$TOOLCHAIN_DIR/$TOOLCHAIN/usr/bin/swift" + if [ -x "$TOOLCHAIN_SWIFT" ]; then + SWIFT_CMD="$TOOLCHAIN_SWIFT" + echo "โœ… Found development toolchain: $TOOLCHAIN" + return 0 + fi + fi + fi + + echo "โ„น๏ธ Using system Swift" + return 0 +} + +# Detect available WASM SDK +detect_wasm_sdk() { + echo "๐Ÿ“ฆ Detecting WASM SDK..." + + # Get list of installed SDKs + INSTALLED_SDKS=$($SWIFT_CMD sdk list 2>/dev/null || echo "") + + # First, check if the CI SDK is available (for GitHub Actions) + if echo "$INSTALLED_SDKS" | grep -q "^${CI_SDK_NAME}$"; then + SWIFT_SDK_NAME="$CI_SDK_NAME" + echo "โœ… Found SDK: $SWIFT_SDK_NAME" + return 0 + fi + + # For local development with development toolchains, prefer matching SDKs + # Extract toolchain version if using a development toolchain + if echo "$SWIFT_CMD" | grep -q "DEVELOPMENT-SNAPSHOT"; then + TOOLCHAIN_VERSION=$(echo "$SWIFT_CMD" | grep -oE "DEVELOPMENT-SNAPSHOT-[0-9]{4}-[0-9]{2}-[0-9]{2}-a") + if [ -n "$TOOLCHAIN_VERSION" ]; then + SDK_MATCH=$(echo "$INSTALLED_SDKS" | grep "$TOOLCHAIN_VERSION" | grep -v "embedded" | head -1) + if [ -n "$SDK_MATCH" ]; then + SWIFT_SDK_NAME="$SDK_MATCH" + echo "โœ… Found matching SDK: $SWIFT_SDK_NAME" + return 0 + fi + fi + fi + + # Try to find any WASM SDK (prefer development snapshots with threads for local dev) + for pattern in "DEVELOPMENT-SNAPSHOT.*wasm32-unknown-wasip1-threads$" "swift-.*-RELEASE_wasm$" "wasm32-unknown-wasi" "wasm"; do + SDK_MATCH=$(echo "$INSTALLED_SDKS" | grep -E "$pattern" | grep -v "embedded" | head -1) + if [ -n "$SDK_MATCH" ]; then + SWIFT_SDK_NAME="$SDK_MATCH" + echo "โœ… Found SDK: $SWIFT_SDK_NAME" + return 0 + fi + done + + return 1 +} + +# Install Swift WASM SDK if not found +install_swift_wasm_sdk() { + if detect_wasm_sdk; then + echo "" + return 0 + fi + + echo "โฌ‡๏ธ No WASM SDK found. Installing Swift WASM SDK..." + $SWIFT_CMD sdk install "$SWIFT_WASM_SDK_URL" --checksum "$SWIFT_WASM_SDK_CHECKSUM" + SWIFT_SDK_NAME="$CI_SDK_NAME" + echo "โœ… Swift WASM SDK installed successfully" + echo "" +} + +# Check if wasmtime is installed +install_wasmtime() { + echo "๐Ÿ”ง Checking wasmtime..." + if command -v wasmtime &> /dev/null; then + echo "โœ… wasmtime already installed: $(wasmtime --version)" + else + echo "โฌ‡๏ธ Installing wasmtime..." + curl https://wasmtime.dev/install.sh -sSf | bash + export PATH="$HOME/.wasmtime/bin:$PATH" + echo "โœ… wasmtime installed successfully" + fi + echo "" +} + +# Build the project +build_project() { + echo "๐Ÿ”จ Building project for WebAssembly..." + echo " Swift: $SWIFT_CMD" + echo " SDK: $SWIFT_SDK_NAME" + $SWIFT_CMD build --swift-sdk "$SWIFT_SDK_NAME" + echo "โœ… Build completed successfully!" + echo "" +} + +# Build and run tests +run_tests() { + echo "๐Ÿงช Building tests for WebAssembly..." + $SWIFT_CMD build --build-tests --swift-sdk "$SWIFT_SDK_NAME" + echo "โœ… Test build completed!" + echo "" + + echo "๐Ÿš€ Running tests with wasmtime..." + # Note: We use wasmtime instead of 'swift test' because swift test doesn't + # work directly for WebAssembly targets. For WASM, we must build tests + # separately and run them with a WASM runtime. + # See: https://book.swiftwasm.org/getting-started/testing.html + + # Find the test binary in any wasm build directory + TEST_BINARY=$(find .build -path "*/debug/MatftPackageTests.wasm" -o -path "*/debug/MatftPackageTests.xctest" 2>/dev/null | grep -E "wasm|wasi" | head -1) + + if [ -z "$TEST_BINARY" ]; then + echo "โŒ Error: Could not find test binary" + echo " Searched in .build/*/debug/ for MatftPackageTests.wasm or .xctest" + exit 1 + fi + + echo "๐Ÿ“ Test binary: $TEST_BINARY" + + # Determine wasmtime flags based on SDK type + WASMTIME_FLAGS="--dir ." + if echo "$SWIFT_SDK_NAME" | grep -q "threads"; then + WASMTIME_FLAGS="$WASMTIME_FLAGS --wasm threads=y --wasi threads=y" + fi + + wasmtime run $WASMTIME_FLAGS "$TEST_BINARY" + echo "" +} + +# Main execution +detect_toolchain +install_swift_wasm_sdk +install_wasmtime +build_project +run_tests + +echo "๐ŸŽ‰ ==========================================" +echo "๐ŸŽ‰ All WASM tests passed successfully!" +echo "๐ŸŽ‰ =========================================="