-
Notifications
You must be signed in to change notification settings - Fork 652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A re-usable static SDK compilation workflow #3019
Open
rnro
wants to merge
1
commit into
main
Choose a base branch
from
static_sdk_workflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Static SDK | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
static-sdk: | ||
name: Static SDK | ||
# Workaround https://github.com/nektos/act/issues/1875 | ||
uses: apple/swift-nio/.github/workflows/swift_test_matrix.yml@static_sdk_workflow # TODO: change to @main | ||
with: | ||
name: "Static SDK" | ||
matrix_string: >- | ||
{ | ||
"swift":[ | ||
{ | ||
"name":"latest-release Jammy", | ||
"swift_version":"6.0.2", | ||
"platform":"Linux", | ||
"runner":"ubuntu-latest", | ||
"image":"ubuntu:jammy", | ||
"setup_command":"INSTALL_SWIFT_STATIC_SDK_VERSION=latest INSTALL_SWIFT_STATIC_SDK_ARCH=x86_64 ./scripts/install_static_sdk.sh", | ||
"command":"swift build", | ||
"command_arguments":"--swift-sdk x86_64-swift-linux-musl" | ||
}, | ||
{ | ||
"name":"main Jammy", | ||
"swift_version":"main", | ||
"platform":"Linux", | ||
"runner":"ubuntu-latest", | ||
"image":"ubuntu:jammy", | ||
"setup_command":"INSTALL_SWIFT_STATIC_SDK_BRANCH=main INSTALL_SWIFT_STATIC_SDK_ARCH=x86_64 ./scripts/install_static_sdk.sh", | ||
"command":"swift build", | ||
"command_arguments":"--swift-sdk x86_64-swift-linux-musl" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/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 | ||
|
||
log() { printf -- "** %s\n" "$*" >&2; } | ||
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"}" | ||
|
||
if [[ ! ( -n "$branch" && -z "$version" ) && ! ( -z "$branch" && -n "$version") ]]; then | ||
fatal "Exactly one of build or version must be defined." | ||
fi | ||
|
||
log "Installing tools for this script" | ||
if command -v apt-get >/dev/null; then | ||
package_manager="apt-get" | ||
apt-get update > /dev/null | ||
elif command -v yum >/dev/null; then | ||
package_manager="yum" | ||
else | ||
fatal "Cannot find either 'apt' or 'yum'" | ||
fi | ||
|
||
"$package_manager" install -y curl rsync jq tar > /dev/null | ||
case "$arch" in | ||
"aarch64") | ||
arch_suffix="-$arch" ;; | ||
"x86_64") | ||
arch_suffix="" ;; | ||
*) | ||
fatal "Unexpected architecture: $arch" ;; | ||
esac | ||
|
||
os_image_sanitized="${os_image//./}" | ||
|
||
if [[ -n "$branch" ]]; then | ||
# Some snapshots may not have all the artefacts we require | ||
log "Discovering branch snapshot for branch $branch" | ||
snapshots="$(curl -s "https://www.swift.org/api/v1/install/dev/main/${os_image_sanitized}.json" | jq -r --arg arch "$arch" '.[$arch] | unique | reverse | .[].dir')" | ||
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" | ||
|
||
# check that the files exist | ||
curl -sILXGET --fail "$snapshot_url" > /dev/null; snapshot_return_code=$? | ||
curl -sILXGET --fail "$static_sdk_url" > /dev/null; static_sdk_return_code=$? | ||
|
||
if [[ ("$snapshot_return_code" -eq 0) && ("$static_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)" | ||
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" | ||
version=$(curl -s https://www.swift.org/api/v1/install/releases.json | jq -r '.[-1].tag' | sed -E 's/swift-([0-9]+\.[0-9]+\.[0-9]+)-RELEASE/\1/') | ||
if [[ -z "$version" ]]; then | ||
fatal "Failed to discover latest Swift version" | ||
fi | ||
log "Discovered latest Swift version: $version" | ||
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" | ||
fi | ||
|
||
log "Installing standard Swift pre-requisites" # pre-reqs list taken from swift.org | ||
DEBIAN_FRONTEND=noninteractive "$package_manager" install -y\ | ||
binutils\ | ||
git\ | ||
gnupg2\ | ||
libc6-dev\ | ||
libcurl4-openssl-dev\ | ||
libedit2\ | ||
libgcc-11-dev\ | ||
libpython3-dev\ | ||
libsqlite3-0\ | ||
libstdc++-11-dev\ | ||
libxml2-dev\ | ||
libz3-dev\ | ||
pkg-config\ | ||
python3-lldb-13\ | ||
tzdata\ | ||
unzip\ | ||
zlib1g-dev\ | ||
> /dev/null | ||
|
||
log "Obtaining Swift toolchain" | ||
log "Snapshot URL: $snapshot_url" | ||
snapshot_path="/tmp/$(basename "$snapshot_url")" | ||
curl -sL "$snapshot_url" -o "$snapshot_path" | ||
|
||
log "Installing Swift toolchain" | ||
mkdir -p /tmp/snapshot | ||
tar xfz "$snapshot_path" --strip-components 1 -C /tmp/snapshot | ||
rsync -a /tmp/snapshot/* / | ||
|
||
log "Obtaining Static SDK" | ||
log "Static SDK URL: $static_sdk_url" | ||
static_sdk_path="/tmp/$(basename "$static_sdk_url")" | ||
curl -sL "$static_sdk_url" -o "$static_sdk_path" | ||
|
||
log "Installing Static SDK" | ||
swift sdk install "$static_sdk_path" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this outdated as of today since 6.0.3 got released?