Skip to content

Commit e46b29f

Browse files
rnrokateinoigakukunMaxDesiatov
authored
WASM SDK GitHub Actions workflows use NIO matrix (#3417)
WASM SDK GitHub Actions workflows use NIO matrix rather than the swiftlang one ### Motivation: Using the NIO one is more in line with the surrounding workflows and surfaces a simpler UI (possible jobs which aren't run don't appear in the UI) ### Modifications: Pull in changes from #3159 and add in the ability to specify environment variables and other build arguments in line with the static Linux SDK workflow. ### Result: More regularity, simpler checks UI. See this in action here: https://github.com/apple/swift-nio/actions/runs/18717131164/job/53379323803?pr=3417 --------- Co-authored-by: Yuta Saito <[email protected]> Co-authored-by: Max Desiatov <[email protected]>
1 parent 843c8cf commit e46b29f

File tree

7 files changed

+94
-27
lines changed

7 files changed

+94
-27
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ jobs:
6868
name: WebAssembly Swift SDK
6969
# Workaround https://github.com/nektos/act/issues/1875
7070
uses: apple/swift-nio/.github/workflows/wasm_sdk.yml@main
71+
with:
72+
additional_command_arguments: "--target NIOCore"
7173

7274
macos-tests:
7375
name: macOS tests

.github/workflows/pull_request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ jobs:
102102
name: WebAssembly Swift SDK
103103
# Workaround https://github.com/nektos/act/issues/1875
104104
uses: apple/swift-nio/.github/workflows/wasm_sdk.yml@main
105+
with:
106+
additional_command_arguments: "--target NIOCore"
105107

106108
release-builds:
107109
name: Release builds

.github/workflows/static_sdk.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
"platform":"Linux",
4848
"runner":"ubuntu-latest",
4949
"image":"ubuntu:jammy",
50-
"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",
50+
"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 bash && hash -r",
5151
"command":"swift build",
5252
"command_arguments":"${{ inputs.command_arguments }}",
5353
"env":'"$env_vars_json"'
@@ -58,7 +58,7 @@ jobs:
5858
"platform":"Linux",
5959
"runner":"ubuntu-latest",
6060
"image":"ubuntu:jammy",
61-
"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",
61+
"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 bash && hash -r",
6262
"command":"swift build",
6363
"command_arguments":"${{ inputs.command_arguments }}",
6464
"env":'"$env_vars_json"'

.github/workflows/wasm_sdk.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,36 @@ permissions:
55

66
on:
77
workflow_call:
8+
inputs:
9+
env_vars:
10+
type: string
11+
description: "Environment variables for jobs as JSON (e.g., '{\"DEBUG\":\"1\",\"LOG_LEVEL\":\"info\"}')."
12+
default: "{}"
13+
additional_command_arguments:
14+
type: string
15+
description: "Additional arguments passed to swift build (the WASM SDK will be specified). Defaults to empty."
16+
default: ""
817

918
jobs:
1019
wasm-sdk:
1120
name: WebAssembly Swift SDK
12-
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
21+
# Workaround https://github.com/nektos/act/issues/1875
22+
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
1323
with:
14-
enable_wasm_sdk_build: true
15-
enable_linux_checks: false
16-
enable_windows_checks: false
17-
swift_flags: --target NIOCore
18-
swift_nightly_flags: --target NIOCore
24+
name: "WebAssembly Swift SDK"
25+
matrix_string: >-
26+
{
27+
"config":[
28+
{
29+
"name":"main Jammy",
30+
"swift_version":"main",
31+
"platform":"Linux",
32+
"runner":"ubuntu-latest",
33+
"image":"ubuntu:jammy",
34+
"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",
35+
"command":"curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/swift-build-with-wasm-sdk.sh | bash -s --",
36+
"command_arguments":"${{ inputs.additional_command_arguments }}",
37+
"env":'"$env_vars_json"'
38+
}
39+
]
40+
}

scripts/install_swift_prerequisites.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ error() { printf -- "** ERROR: %s\n" "$*" >&2; }
2020
fatal() { error "$@"; exit 1; }
2121

2222
if command -v apt-get >/dev/null; then
23-
PACKAGE_MANAGER_BIN="apt"
23+
PACKAGE_MANAGER_BIN="apt-get"
2424
apt-get update > /dev/null
2525
elif command -v yum >/dev/null; then
2626
PACKAGE_MANAGER_BIN="yum"

scripts/install_static_sdk.sh renamed to scripts/install_swift_sdk.sh

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ error() { printf -- "** ERROR: %s\n" "$*" >&2; }
2020
fatal() { error "$@"; exit 1; }
2121

2222
# Parameter environment variables
23-
branch="${INSTALL_SWIFT_STATIC_SDK_BRANCH:=""}"
24-
version="${INSTALL_SWIFT_STATIC_SDK_VERSION:=""}"
25-
arch="${INSTALL_SWIFT_STATIC_SDK_ARCH:="aarch64"}"
26-
os_image="${INSTALL_SWIFT_STATIC_SDK_OS_IMAGE:="ubuntu22.04"}"
23+
branch="${INSTALL_SWIFT_BRANCH:=""}"
24+
version="${INSTALL_SWIFT_VERSION:=""}"
25+
arch="${INSTALL_SWIFT_ARCH:="aarch64"}"
26+
os_image="${INSTALL_SWIFT_OS_IMAGE:="ubuntu22.04"}"
27+
sdk="${INSTALL_SWIFT_SDK:="static-sdk"}"
2728

2829
if [[ ! ( -n "$branch" && -z "$version" ) && ! ( -z "$branch" && -n "$version") ]]; then
2930
fatal "Exactly one of build or version must be defined."
@@ -43,6 +44,20 @@ case "$arch" in
4344
fatal "Unexpected architecture: $arch" ;;
4445
esac
4546

47+
case "$sdk" in
48+
"static-sdk")
49+
sdk_dir="static-sdk"
50+
sdk_suffix="_static-linux-0.0.1"
51+
;;
52+
"wasm-sdk")
53+
sdk_dir="wasm-sdk"
54+
sdk_suffix="_wasm"
55+
;;
56+
*)
57+
fatal "Unexpected Swift SDK: $sdk"
58+
;;
59+
esac
60+
4661
os_image_sanitized="${os_image//./}"
4762

4863
if [[ -n "$branch" ]]; then
@@ -54,24 +69,24 @@ if [[ -n "$branch" ]]; then
5469

5570
for snapshot in $snapshots; do
5671
snapshot_url="https://download.swift.org/development/${os_image_sanitized}${arch_suffix}/${snapshot}/${snapshot}-${os_image}${arch_suffix}.tar.gz"
57-
static_sdk_url="https://download.swift.org/development/static-sdk/${snapshot}/${snapshot}_static-linux-0.0.1.artifactbundle.tar.gz"
58-
72+
sdk_url="https://download.swift.org/development/${sdk_dir}/${snapshot}/${snapshot}${sdk_suffix}.artifactbundle.tar.gz"
73+
5974
# check that the files exist
6075
"$CURL_BIN" -sILXGET --fail "$snapshot_url" > /dev/null; snapshot_return_code=$?
61-
"$CURL_BIN" -sILXGET --fail "$static_sdk_url" > /dev/null; static_sdk_return_code=$?
62-
63-
if [[ ("$snapshot_return_code" -eq 0) && ("$static_sdk_return_code" -eq 0) ]]; then
76+
"$CURL_BIN" -sILXGET --fail "$sdk_url" > /dev/null; sdk_return_code=$?
77+
78+
if [[ ("$snapshot_return_code" -eq 0) && ("$sdk_return_code" -eq 0) ]]; then
6479
log "Discovered branch snapshot: $snapshot"
6580
break
6681
else
67-
log "Snapshot unavailable: $snapshot (Snapshot return code: $snapshot_return_code, Static SDK return code: $static_sdk_return_code)"
82+
log "Snapshot unavailable: $snapshot (Snapshot return code: $snapshot_return_code, Swift SDK return code: $sdk_return_code)"
6883
snapshot=""
6984
fi
7085
done
7186
if [[ -z "$snapshot" ]]; then
7287
fatal "Failed to discover usable Swift snapshot"
7388
fi
74-
89+
7590
elif [[ -n "$version" ]]; then
7691
if [[ "$version" == "latest" ]]; then
7792
log "Discovering latest version"
@@ -83,7 +98,7 @@ elif [[ -n "$version" ]]; then
8398
fi
8499

85100
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"
86-
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"
101+
sdk_url="https://download.swift.org/swift-${version}-release/${sdk_dir}/swift-${version}-RELEASE/swift-${version}-RELEASE${sdk_suffix}.artifactbundle.tar.gz"
87102
fi
88103

89104
log "Obtaining Swift toolchain"
@@ -95,16 +110,16 @@ log "Installing Swift toolchain"
95110
mkdir -p /tmp/snapshot
96111
"$TAR_BIN" xfz "$snapshot_path" --strip-components 1 -C /
97112

98-
log "Obtaining Static SDK"
99-
log "Static SDK URL: $static_sdk_url"
100-
static_sdk_path="/tmp/$(basename "$static_sdk_url")"
101-
"$CURL_BIN" -sfL "$static_sdk_url" -o "$static_sdk_path" || fatal "Failed to download Static SDK"
113+
log "Obtaining Swift SDK"
114+
log "Swift SDK URL: $sdk_url"
115+
sdk_path="/tmp/$(basename "$sdk_url")"
116+
"$CURL_BIN" -sfL "$sdk_url" -o "$sdk_path" || fatal "Failed to download Swift SDK"
102117

103118
log "Looking for swift"
104119
which swift || fatal "Failed to locate installed Swift"
105120

106121
log "Checking swift"
107122
swift --version
108123

109-
log "Installing Static SDK"
110-
swift sdk install "$static_sdk_path"
124+
log "Installing Swift SDK"
125+
swift sdk install "$sdk_path"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
##===----------------------------------------------------------------------===##
3+
##
4+
## This source file is part of the SwiftNIO open source project
5+
##
6+
## Copyright (c) 2024 Apple Inc. and the SwiftNIO project authors
7+
## Licensed under Apache License v2.0
8+
##
9+
## See LICENSE.txt for license information
10+
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
11+
##
12+
## SPDX-License-Identifier: Apache-2.0
13+
##
14+
##===----------------------------------------------------------------------===##
15+
16+
set -uo pipefail
17+
18+
# Select the Swift SDK for WebAssembly, not the Embedded one
19+
SWIFT_SDK="$(swift sdk list | grep _wasm | grep -v -embedded | head -n1)"
20+
if [[ -z "$SWIFT_SDK" ]]; then
21+
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."
22+
exit 1
23+
fi
24+
25+
echo "Using Swift SDK: $SWIFT_SDK"
26+
swift build --swift-sdk "$SWIFT_SDK" "${@}"

0 commit comments

Comments
 (0)