Skip to content

Commit ea70b85

Browse files
authored
Update install-and-build-with-sdk.sh
1 parent 35e2b55 commit ea70b85

1 file changed

Lines changed: 63 additions & 52 deletions

File tree

.github/workflows/scripts/install-and-build-with-sdk.sh

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,27 @@ error() { printf -- "** ERROR: %s\n" "$*" >&2; }
1818
fatal() { error "$@"; exit 1; }
1919

2020
# Parse command line options
21-
INSTALL_STATIC=false
21+
INSTALL_STATIC_LINUX=false
2222
INSTALL_WASM=false
23+
BUILD_EMBEDDED_WASM=false
2324
SWIFT_VERSION_INPUT=""
2425
SWIFT_BUILD_FLAGS=""
2526

2627
while [[ $# -gt 0 ]]; do
2728
case $1 in
2829
--static)
29-
INSTALL_STATIC=true
30+
INSTALL_STATIC_LINUX=true
3031
shift
3132
;;
3233
--wasm)
3334
INSTALL_WASM=true
3435
shift
3536
;;
37+
--embedded_wasm)
38+
INSTALL_WASM=true
39+
BUILD_EMBEDDED_WASM=true
40+
shift
41+
;;
3642
--flags=*)
3743
SWIFT_BUILD_FLAGS="${1#*=}"
3844
shift
@@ -56,13 +62,13 @@ if [[ -z "$SWIFT_VERSION_INPUT" ]]; then
5662
fatal "Usage: $0 [--static] [--wasm] [--flags=\"<build-flags>\"] <swift-version>"
5763
fi
5864

59-
if [[ "$INSTALL_STATIC" == false && "$INSTALL_WASM" == false ]]; then
65+
if [[ "$INSTALL_STATIC_LINUX" == false && "$INSTALL_WASM" == false ]]; then
6066
fatal "At least one of --static or --wasm must be specified"
6167
fi
6268

6369
log "Requested Swift version: $SWIFT_VERSION_INPUT"
64-
log "Install static SDK: $INSTALL_STATIC"
65-
log "Install Wasm SDK: $INSTALL_WASM"
70+
log "Install Static Linux Swift SDK: $INSTALL_STATIC_LINUX"
71+
log "Install Wasm Swift SDK: $INSTALL_WASM"
6672
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
6773
log "Additional build flags: $SWIFT_BUILD_FLAGS"
6874
fi
@@ -74,7 +80,7 @@ command -v jq >/dev/null || (apt update -q && apt install -yq jq)
7480
SWIFT_API_INSTALL_ROOT="https://www.swift.org/api/v1/install"
7581

7682
# Transforms a minor Swift release version into its latest patch version
77-
# and gets the checksum for the patch version's static and/or Wasm SDK.
83+
# and gets the checksum for the patch version's Static Linux and/or Wasm Swift SDK.
7884
#
7985
# $1 (string): A minor Swift version, e.g. "6.1"
8086
# Output: A string of the form "<patch-version>|<static-checksum>|<wasm-checksum>
@@ -103,7 +109,7 @@ find_latest_swift_version() {
103109
log "Found latest patch version: $latest_version"
104110

105111
local static_checksum=""
106-
if [[ "$INSTALL_STATIC" == true ]]; then
112+
if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
107113
static_checksum=$(echo "$releases_json" | jq -r --arg version "$latest_version" '
108114
.[]
109115
| select(.name == $version)
@@ -112,11 +118,11 @@ find_latest_swift_version() {
112118
| .checksum
113119
')
114120

115-
if [[ -z "$static_checksum" ]]; then
116-
fatal "No static SDK checksum found for Swift $latest_version"
121+
if [[ -z "$static_linux_checksum" ]]; then
122+
fatal "No Static Linux Swift SDK checksum found for Swift $latest_version"
117123
fi
118124

119-
log "Found static SDK checksum: ${STATIC_SDK_CHECKSUM:0:12}..."
125+
log "Found Static Linux Swift SDK checksum: ${STATIC_LINUX_SDK_CHECKSUM:0:12}..."
120126
fi
121127

122128
local wasm_checksum=""
@@ -130,16 +136,16 @@ find_latest_swift_version() {
130136
')
131137

132138
if [[ -z "$wasm_checksum" ]]; then
133-
fatal "No Wasm SDK checksum found for Swift $latest_version"
139+
fatal "No Swift SDK for Wasm checksum found for Swift $latest_version"
134140
fi
135141

136-
log "Found Wasm SDK checksum: ${wasm_checksum:0:12}..."
142+
log "Found Swift SDK for Wasm checksum: ${wasm_checksum:0:12}..."
137143
fi
138144

139145
echo "${latest_version}|${static_checksum}|${wasm_checksum}"
140146
}
141147

142-
# Finds the latest static or Wasm SDK development snapshot
148+
# Finds the latest Static Linux or Wasm Swift SDK development snapshot
143149
# for the inputted Swift version and its checksum.
144150
#
145151
# $1 (string): Nightly Swift version, e.g. "6.2" or "main"
@@ -180,8 +186,8 @@ find_latest_sdk_snapshot() {
180186
}
181187

182188
SWIFT_VERSION_BRANCH=""
183-
STATIC_SDK_TAG=""
184-
STATIC_SDK_CHECKSUM=""
189+
STATIC_LINUX_SDK_TAG=""
190+
STATIC_LINUX_SDK_CHECKSUM=""
185191
WASM_SDK_TAG=""
186192
WASM_SDK_CHECKSUM=""
187193

@@ -194,11 +200,11 @@ if [[ "$SWIFT_VERSION_INPUT" == nightly-* ]]; then
194200
SWIFT_VERSION_BRANCH="swift-${version}-branch"
195201
fi
196202

197-
if [[ "$INSTALL_STATIC" == true ]]; then
198-
static_sdk_info=$(find_latest_sdk_snapshot "$version" "static")
203+
if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
204+
static_linux_sdk_info=$(find_latest_sdk_snapshot "$version" "static")
199205

200-
STATIC_SDK_TAG=$(echo "$static_sdk_info" | cut -d'|' -f1)
201-
STATIC_SDK_CHECKSUM=$(echo "$static_sdk_info" | cut -d'|' -f2)
206+
STATIC_LINUX_SDK_TAG=$(echo "$static_linu_sdk_info" | cut -d'|' -f1)
207+
STATIC_LINUX_SDK_CHECKSUM=$(echo "$static_linux_sdk_info" | cut -d'|' -f2)
202208
fi
203209

204210
if [[ "$INSTALL_WASM" == true ]]; then
@@ -213,20 +219,20 @@ else
213219
latest_version=$(echo "$latest_version_info" | cut -d'|' -f1)
214220
SWIFT_VERSION_BRANCH="swift-${latest_version}-release"
215221

216-
STATIC_SDK_TAG="swift-${latest_version}-RELEASE"
217-
STATIC_SDK_CHECKSUM=$(echo "$latest_version_info" | cut -d'|' -f2)
222+
STATIC_LINUX_SDK_TAG="swift-${latest_version}-RELEASE"
223+
STATIC_LINUX_SDK_CHECKSUM=$(echo "$latest_version_info" | cut -d'|' -f2)
218224

219225
WASM_SDK_TAG="swift-${latest_version}-RELEASE"
220226
WASM_SDK_CHECKSUM=$(echo "$latest_version_info" | cut -d'|' -f3)
221227
fi
222228

223-
# Validate that required SDK tags are set
224-
if [[ "$INSTALL_STATIC" == true && -z "$STATIC_SDK_TAG" ]]; then
225-
fatal "STATIC_SDK_TAG is not set but static SDK installation was requested"
229+
# Validate that required Swift SDK tags are set
230+
if [[ "$INSTALL_STATIC_LINUX" == true && -z "$STATIC_LINUX_SDK_TAG" ]]; then
231+
fatal "STATIC_LINUX_SDK_TAG is not set but Static Linux Swift SDK installation was requested"
226232
fi
227233

228234
if [[ "$INSTALL_WASM" == true && -z "$WASM_SDK_TAG" ]]; then
229-
fatal "WASM_SDK_TAG is not set but Wasm SDK installation was requested"
235+
fatal "WASM_SDK_TAG is not set but Wasm Swift SDK installation was requested"
230236
fi
231237

232238
get_installed_swift_tag() {
@@ -251,7 +257,7 @@ get_installed_swift_tag() {
251257
local swift_tag
252258
swift_tag=$(swift --version 2>/dev/null | grep -o "(swift-.*-RELEASE)" | tr -d "()" | head -n1)
253259
if [[ -n "$swift_tag" ]]; then
254-
log "✅ Found Swift release tag via swift --version: $swift_tag"
260+
log "✅ Found Swift release tag via `swift --version`: $swift_tag"
255261
echo "$swift_tag"
256262
return 0
257263
fi
@@ -401,17 +407,17 @@ download_and_extract_toolchain() {
401407
}
402408

403409
INSTALLED_SWIFT_TAG=$(get_installed_swift_tag)
404-
SWIFT_EXECUTABLE_FOR_STATIC_SDK=""
410+
SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK=""
405411
SWIFT_EXECUTABLE_FOR_WASM_SDK=""
406412

407-
if [[ "$INSTALL_STATIC" == true ]]; then
408-
if [[ "$INSTALLED_SWIFT_TAG" == "$STATIC_SDK_TAG" ]]; then
409-
log "Current toolchain matches static SDK snapshot: $STATIC_SDK_TAG"
410-
SWIFT_EXECUTABLE_FOR_STATIC_SDK="swift"
413+
if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
414+
if [[ "$INSTALLED_SWIFT_TAG" == "$STATIC_LINUX_SDK_TAG" ]]; then
415+
log "Current toolchain matches Static Linux Swift SDK snapshot: $STATIC_LINUX_SDK_TAG"
416+
SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK="swift"
411417
else
412-
log "Installing Swift toolchain to match static SDK snapshot: $STATIC_SDK_TAG"
418+
log "Installing Swift toolchain to match static SDK snapshot: $STATIC_LINUX_SDK_TAG"
413419
initialize_os_info
414-
SWIFT_EXECUTABLE_FOR_STATIC_SDK=$(download_and_extract_toolchain "$STATIC_SDK_TAG")
420+
SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK=$(download_and_extract_toolchain "$STATIC_LINUX_SDK_TAG")
415421
fi
416422
fi
417423

@@ -426,24 +432,24 @@ if [[ "$INSTALL_WASM" == true ]]; then
426432
fi
427433
fi
428434

429-
STATIC_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/static-sdk"
435+
STATIC_LINUX_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/static-sdk"
430436
WASM_SDK_DOWNLOAD_ROOT="${SWIFT_DOWNLOAD_ROOT}/${SWIFT_VERSION_BRANCH}/wasm-sdk"
431437

432-
install_static_sdk() {
438+
install_static_linux_sdk() {
433439
# Check if the static SDK is already installed
434-
if "$SWIFT_EXECUTABLE_FOR_STATIC_SDK" sdk list 2>/dev/null | grep -q "^${STATIC_SDK_TAG}_static-linux-0.0.1"; then
435-
log "✅ Static SDK ${STATIC_SDK_TAG} is already installed, skipping installation"
440+
if "$SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK" sdk list 2>/dev/null | grep -q "^${STATIC_LINUX_SDK_TAG}_static-linux-0.0.1"; then
441+
log "✅ Static SDK ${STATIC_LINUX_SDK_TAG} is already installed, skipping installation"
436442
return 0
437443
fi
438444

439-
log "Installing Swift Static SDK: $STATIC_SDK_TAG"
445+
log "Installing Swift Static SDK: $STATIC_LINUX_SDK_TAG"
440446

441-
local static_sdk_filename="${STATIC_SDK_TAG}_static-linux-0.0.1.artifactbundle.tar.gz"
442-
local sdk_url="${STATIC_SDK_DOWNLOAD_ROOT}/${STATIC_SDK_TAG}/${static_sdk_filename}"
447+
local static_linux_sdk_filename="${STATIC_LINUX_SDK_TAG}_static-linux-0.0.1.artifactbundle.tar.gz"
448+
local sdk_url="${STATIC_LINUX_SDK_DOWNLOAD_ROOT}/${STATIC_LINUX_SDK_TAG}/${static_linux_sdk_filename}"
443449

444-
log "Running: ${SWIFT_EXECUTABLE_FOR_STATIC_SDK} sdk install ${sdk_url} --checksum ${STATIC_SDK_CHECKSUM}"
450+
log "Running: ${SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK} sdk install ${sdk_url} --checksum ${STATIC_LINUX_SDK_CHECKSUM}"
445451

446-
if "$SWIFT_EXECUTABLE_FOR_STATIC_SDK" sdk install "$sdk_url" --checksum "$STATIC_SDK_CHECKSUM"; then
452+
if "$SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK" sdk install "$sdk_url" --checksum "$STATIC_LINUX_SDK_CHECKSUM"; then
447453
log "✅ Static SDK installed successfully"
448454
else
449455
fatal "Failed to install static SDK"
@@ -472,23 +478,23 @@ install_wasm_sdk() {
472478
}
473479

474480
install_sdks() {
475-
if [[ "$INSTALL_STATIC" == true ]]; then
476-
log "Starting install of Swift ${SWIFT_VERSION_INPUT} static SDK"
477-
install_static_sdk
481+
if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
482+
log "Starting install of Swift ${SWIFT_VERSION_INPUT} Static Linux Swift SDK"
483+
install_static_linux_sdk
478484
fi
479485

480486
if [[ "$INSTALL_WASM" == true ]]; then
481-
log "Starting install of Swift ${SWIFT_VERSION_INPUT} Wasm SDK"
487+
log "Starting install of Swift ${SWIFT_VERSION_INPUT} Wasm Swift SDK"
482488
install_wasm_sdk
483489
fi
484490
}
485491

486492
build() {
487-
if [[ "$INSTALL_STATIC" == true ]]; then
493+
if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
488494
log "Running Swift build with static SDK"
489495

490-
local sdk_name="${STATIC_SDK_TAG}_static-linux-0.0.1"
491-
local build_command="$SWIFT_EXECUTABLE_FOR_STATIC_SDK build --swift-sdk $sdk_name"
496+
local sdk_name="${STATIC_LINUX_SDK_TAG}_static-linux-0.0.1"
497+
local build_command="$SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK build --swift-sdk $sdk_name"
492498
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
493499
build_command="$build_command $SWIFT_BUILD_FLAGS"
494500
fi
@@ -505,7 +511,12 @@ build() {
505511
if [[ "$INSTALL_WASM" == true ]]; then
506512
log "Running Swift build with Wasm SDK"
507513

508-
local sdk_name="${WASM_SDK_TAG}_wasm"
514+
if [[ "$BUILD_EMBEDDED_WASM" == true ]]; then
515+
local sdk_name="${WASM_SDK_TAG}_wasm-embedded"
516+
else
517+
local sdk_name="${WASM_SDK_TAG}_wasm"
518+
fi
519+
509520
local build_command="$SWIFT_EXECUTABLE_FOR_WASM_SDK build --swift-sdk $sdk_name"
510521
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
511522
build_command="$build_command $SWIFT_BUILD_FLAGS"
@@ -514,9 +525,9 @@ build() {
514525
log "Running: $build_command"
515526

516527
if eval "$build_command"; then
517-
log "✅ Swift build with Wasm SDK completed successfully"
528+
log "✅ Swift build with Swift SDK for Wasm completed successfully"
518529
else
519-
fatal "Swift build with Wasm SDK failed"
530+
fatal "Swift build with Swift SDK for Wasm failed"
520531
fi
521532
fi
522533
}

0 commit comments

Comments
 (0)