Skip to content

Commit 7999cc3

Browse files
CI: Add build check for WebAssembly SDK
1 parent 1d72f49 commit 7999cc3

File tree

6 files changed

+96
-20
lines changed

6 files changed

+96
-20
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ jobs:
6060
# Workaround https://github.com/nektos/act/issues/1875
6161
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main
6262

63+
wasm-sdk:
64+
name: WebAssembly SDK
65+
# Workaround https://github.com/nektos/act/issues/1875
66+
uses: apple/swift-nio/.github/workflows/wasm_sdk.yml@main
67+
6368
macos-tests:
6469
name: macOS tests
6570
# Workaround https://github.com/nektos/act/issues/1875

.github/workflows/pull_request.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,8 @@ jobs:
8989
name: Static SDK
9090
# Workaround https://github.com/nektos/act/issues/1875
9191
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main
92+
93+
wasm-sdk:
94+
name: WebAssembly SDK
95+
# Workaround https://github.com/nektos/act/issues/1875
96+
uses: apple/swift-nio/.github/workflows/wasm_sdk.yml@main

.github/workflows/static_sdk.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
"platform":"Linux",
2020
"runner":"ubuntu-latest",
2121
"image":"ubuntu:jammy",
22-
"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",
22+
"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",
2323
"command":"swift build",
2424
"command_arguments":"--swift-sdk x86_64-swift-linux-musl"
2525
},
@@ -29,7 +29,7 @@ jobs:
2929
"platform":"Linux",
3030
"runner":"ubuntu-latest",
3131
"image":"ubuntu:jammy",
32-
"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",
32+
"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",
3333
"command":"swift build",
3434
"command_arguments":"--swift-sdk x86_64-swift-linux-musl"
3535
}

.github/workflows/wasm_sdk.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: WebAssembly SDK
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
wasm-sdk:
8+
name: WebAssembly SDK
9+
# Workaround https://github.com/nektos/act/issues/1875
10+
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@main
11+
with:
12+
name: "WebAssembly SDK"
13+
matrix_string: >-
14+
{
15+
"config":[
16+
{
17+
"name":"main Jammy",
18+
"swift_version":"main",
19+
"platform":"Linux",
20+
"runner":"ubuntu-latest",
21+
"image":"ubuntu:jammy",
22+
"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",
23+
"command":"curl -s --retry 3 https://raw.githubusercontent.com/kateinoigakukun/swift-nio/katei/add-wasm-ci/scripts/install_swift_prerequisites.sh | bash",
24+
"command_arguments":""
25+
}
26+
]
27+
}

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 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"

scripts/swift-build-with-wasm-sdk.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 SDK found. Please ensure you have the WebAssembly SDK installed."
22+
exit 1
23+
fi
24+
swift build --swift-sdk "$SWIFT_SDK" "${@}"

0 commit comments

Comments
 (0)