Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/static_sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
}
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/wasm_sdk.yml
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
51 changes: 33 additions & 18 deletions scripts/install_static_sdk.sh → scripts/install_swift_sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -95,16 +110,16 @@ 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"

log "Checking swift"
swift --version

log "Installing Static SDK"
swift sdk install "$static_sdk_path"
log "Installing Swift SDK"
swift sdk install "$sdk_path"
26 changes: 26 additions & 0 deletions scripts/swift-build-with-wasm-sdk.sh
Original file line number Diff line number Diff line change
@@ -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" "${@}"