diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ebec19db3..96c3345dc5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -56,10 +56,15 @@ jobs: matrix_string: '${{ needs.construct-integration-test-matrix.outputs.integration-test-matrix }}' static-sdk: - name: Static SDK + name: Static Linux Swift SDK # Workaround https://github.com/nektos/act/issues/1875 uses: apple/swift-nio/.github/workflows/static_sdk.yml@main + wasm-sdk: + name: WebAssembly Swift SDK + # Workaround https://github.com/nektos/act/issues/1875 + uses: apple/swift-nio/.github/workflows/wasm_sdk.yml@main + macos-tests: name: macOS tests # Workaround https://github.com/nektos/act/issues/1875 diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index ae7827ba84..b62a3c53c1 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -89,3 +89,8 @@ jobs: name: Static SDK # Workaround https://github.com/nektos/act/issues/1875 uses: apple/swift-nio/.github/workflows/static_sdk.yml@main + + wasm-sdk: + name: WebAssembly Swift SDK + # Workaround https://github.com/nektos/act/issues/1875 + uses: apple/swift-nio/.github/workflows/wasm_sdk.yml@main diff --git a/.github/workflows/static_sdk.yml b/.github/workflows/static_sdk.yml index b00477abe9..ee70e69a9e 100644 --- a/.github/workflows/static_sdk.yml +++ b/.github/workflows/static_sdk.yml @@ -19,7 +19,7 @@ jobs: "platform":"Linux", "runner":"ubuntu-latest", "image":"ubuntu:jammy", - "setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_static_sdk.sh | INSTALL_SWIFT_STATIC_SDK_VERSION=latest INSTALL_SWIFT_STATIC_SDK_ARCH=x86_64 bash && hash -r", + "setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_sdk.sh | INSTALL_SWIFT_VERSION=latest INSTALL_SWIFT_ARCH=x86_64 INSTALL_SWIFT_SDK=static-sdk bash && hash -r", "command":"swift build", "command_arguments":"--swift-sdk x86_64-swift-linux-musl" }, @@ -29,7 +29,7 @@ jobs: "platform":"Linux", "runner":"ubuntu-latest", "image":"ubuntu:jammy", - "setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_static_sdk.sh | INSTALL_SWIFT_STATIC_SDK_BRANCH=main INSTALL_SWIFT_STATIC_SDK_ARCH=x86_64 bash && hash -r", + "setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_sdk.sh | INSTALL_SWIFT_BRANCH=main INSTALL_SWIFT_ARCH=x86_64 INSTALL_SWIFT_SDK=static-sdk bash && hash -r", "command":"swift build", "command_arguments":"--swift-sdk x86_64-swift-linux-musl" } diff --git a/.github/workflows/wasm_sdk.yml b/.github/workflows/wasm_sdk.yml new file mode 100644 index 0000000000..eae7822f27 --- /dev/null +++ b/.github/workflows/wasm_sdk.yml @@ -0,0 +1,27 @@ +name: WebAssembly SDK + +on: + workflow_call: + +jobs: + wasm-sdk: + name: WebAssembly Swift SDK + # Workaround https://github.com/nektos/act/issues/1875 + uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main + with: + name: "WebAssembly Swift SDK" + matrix_string: >- + { + "config":[ + { + "name":"main Jammy", + "swift_version":"main", + "platform":"Linux", + "runner":"ubuntu-latest", + "image":"ubuntu:jammy", + "setup_command":"apt update -q && apt install -y -q curl jq tar && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_prerequisites.sh | bash && curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/install_swift_sdk.sh | INSTALL_SWIFT_BRANCH=main INSTALL_SWIFT_ARCH=x86_64 INSTALL_SWIFT_SDK=wasm-sdk bash && hash -r", + "command":"curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/swift-build-with-wasm-sdk.sh | bash -s --", + "command_arguments":"--target NIOCore" + } + ] + } diff --git a/scripts/install_static_sdk.sh b/scripts/install_swift_sdk.sh similarity index 75% rename from scripts/install_static_sdk.sh rename to scripts/install_swift_sdk.sh index c6a2127ac8..af26da75f2 100755 --- a/scripts/install_static_sdk.sh +++ b/scripts/install_swift_sdk.sh @@ -20,10 +20,11 @@ error() { printf -- "** ERROR: %s\n" "$*" >&2; } fatal() { error "$@"; exit 1; } # Parameter environment variables -branch="${INSTALL_SWIFT_STATIC_SDK_BRANCH:=""}" -version="${INSTALL_SWIFT_STATIC_SDK_VERSION:=""}" -arch="${INSTALL_SWIFT_STATIC_SDK_ARCH:="aarch64"}" -os_image="${INSTALL_SWIFT_STATIC_SDK_OS_IMAGE:="ubuntu22.04"}" +branch="${INSTALL_SWIFT_BRANCH:=""}" +version="${INSTALL_SWIFT_VERSION:=""}" +arch="${INSTALL_SWIFT_ARCH:="aarch64"}" +os_image="${INSTALL_SWIFT_OS_IMAGE:="ubuntu22.04"}" +sdk="${INSTALL_SWIFT_SDK:="static-sdk"}" if [[ ! ( -n "$branch" && -z "$version" ) && ! ( -z "$branch" && -n "$version") ]]; then fatal "Exactly one of build or version must be defined." @@ -43,6 +44,20 @@ case "$arch" in fatal "Unexpected architecture: $arch" ;; esac +case "$sdk" in + "static-sdk") + sdk_dir="static-sdk" + sdk_suffix="_static-linux-0.0.1" + ;; + "wasm-sdk") + sdk_dir="wasm-sdk" + sdk_suffix="_wasm" + ;; + *) + fatal "Unexpected Swift SDK: $sdk" + ;; +esac + os_image_sanitized="${os_image//./}" if [[ -n "$branch" ]]; then @@ -54,24 +69,24 @@ if [[ -n "$branch" ]]; then for snapshot in $snapshots; do snapshot_url="https://download.swift.org/development/${os_image_sanitized}${arch_suffix}/${snapshot}/${snapshot}-${os_image}${arch_suffix}.tar.gz" - static_sdk_url="https://download.swift.org/development/static-sdk/${snapshot}/${snapshot}_static-linux-0.0.1.artifactbundle.tar.gz" - + sdk_url="https://download.swift.org/development/${sdk_dir}/${snapshot}/${snapshot}${sdk_suffix}.artifactbundle.tar.gz" + # check that the files exist "$CURL_BIN" -sILXGET --fail "$snapshot_url" > /dev/null; snapshot_return_code=$? - "$CURL_BIN" -sILXGET --fail "$static_sdk_url" > /dev/null; static_sdk_return_code=$? - - if [[ ("$snapshot_return_code" -eq 0) && ("$static_sdk_return_code" -eq 0) ]]; then + "$CURL_BIN" -sILXGET --fail "$sdk_url" > /dev/null; sdk_return_code=$? + + if [[ ("$snapshot_return_code" -eq 0) && ("$sdk_return_code" -eq 0) ]]; then log "Discovered branch snapshot: $snapshot" break else - log "Snapshot unavailable: $snapshot (Snapshot return code: $snapshot_return_code, Static SDK return code: $static_sdk_return_code)" + log "Snapshot unavailable: $snapshot (Snapshot return code: $snapshot_return_code, Swift SDK return code: $sdk_return_code)" snapshot="" fi done if [[ -z "$snapshot" ]]; then fatal "Failed to discover usable Swift snapshot" fi - + elif [[ -n "$version" ]]; then if [[ "$version" == "latest" ]]; then log "Discovering latest version" @@ -83,7 +98,7 @@ elif [[ -n "$version" ]]; then fi snapshot_url="https://download.swift.org/swift-${version}-release/${os_image_sanitized}${arch_suffix}/swift-${version}-RELEASE/swift-${version}-RELEASE-${os_image}${arch_suffix}.tar.gz" - static_sdk_url="https://download.swift.org/swift-${version}-release/static-sdk/swift-${version}-RELEASE/swift-${version}-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz" + sdk_url="https://download.swift.org/swift-${version}-release/${sdk_dir}/swift-${version}-RELEASE/swift-${version}-RELEASE${sdk_suffix}.artifactbundle.tar.gz" fi log "Obtaining Swift toolchain" @@ -95,10 +110,10 @@ log "Installing Swift toolchain" mkdir -p /tmp/snapshot "$TAR_BIN" xfz "$snapshot_path" --strip-components 1 -C / -log "Obtaining Static SDK" -log "Static SDK URL: $static_sdk_url" -static_sdk_path="/tmp/$(basename "$static_sdk_url")" -"$CURL_BIN" -sfL "$static_sdk_url" -o "$static_sdk_path" || fatal "Failed to download Static SDK" +log "Obtaining Swift SDK" +log "Swift SDK URL: $sdk_url" +sdk_path="/tmp/$(basename "$sdk_url")" +"$CURL_BIN" -sfL "$sdk_url" -o "$sdk_path" || fatal "Failed to download Swift SDK" log "Looking for swift" which swift || fatal "Failed to locate installed Swift" @@ -106,5 +121,5 @@ which swift || fatal "Failed to locate installed Swift" log "Checking swift" swift --version -log "Installing Static SDK" -swift sdk install "$static_sdk_path" +log "Installing Swift SDK" +swift sdk install "$sdk_path" diff --git a/scripts/swift-build-with-wasm-sdk.sh b/scripts/swift-build-with-wasm-sdk.sh new file mode 100755 index 0000000000..f3ea75cebb --- /dev/null +++ b/scripts/swift-build-with-wasm-sdk.sh @@ -0,0 +1,26 @@ +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftNIO open source project +## +## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.txt for the list of SwiftNIO project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +set -uo pipefail + +# Select the Swift SDK for WebAssembly, not the Embedded one +SWIFT_SDK="$(swift sdk list | grep _wasm | grep -v -embedded | head -n1)" +if [[ -z "$SWIFT_SDK" ]]; then + echo "No WebAssembly Swift SDK found. Please ensure you have the WebAssembly Swift SDK installed following https://www.swift.org/documentation/articles/wasm-getting-started.html." + exit 1 +fi + +echo "Using Swift SDK: $SWIFT_SDK" +swift build --swift-sdk "$SWIFT_SDK" "${@}"