Skip to content

Commit 77f315f

Browse files
authored
Support RPM distros when building with Swift static Linux/Wasm SDKs (#148)
* Support RPM distros when building with Swift static Linux/Wasm SDKs * Add rhel-ubi9 to pull_request.yml * Update script URL to this PR branch for testing * Revert "Update script URL to this PR branch for testing" This reverts commit 2b72913.
1 parent 6065185 commit 77f315f

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ jobs:
1010
uses: ./.github/workflows/swift_package_test.yml
1111
with:
1212
# Linux
13+
linux_os_versions: '["jammy", "rhel-ubi9"]'
1314
linux_build_command: |
1415
mkdir MyPackage
1516
cd MyPackage

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,24 @@ if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
7373
log "Additional build flags: $SWIFT_BUILD_FLAGS"
7474
fi
7575

76+
# Detect package manager
77+
if command -v apt >/dev/null 2>&1; then
78+
INSTALL_PACKAGE_COMMAND="apt update -q && apt install -yq"
79+
elif command -v dnf >/dev/null 2>&1; then
80+
INSTALL_PACKAGE_COMMAND="dnf install -y"
81+
elif command -v yum >/dev/null 2>&1; then
82+
INSTALL_PACKAGE_COMMAND="yum install -y"
83+
else
84+
fatal "No supported package manager found"
85+
fi
86+
87+
install_package() {
88+
eval "$INSTALL_PACKAGE_COMMAND $1"
89+
}
90+
7691
# Install dependencies
77-
command -v curl >/dev/null || (apt update -q && apt install -yq curl)
78-
command -v jq >/dev/null || (apt update -q && apt install -yq jq)
92+
command -v curl >/dev/null || install_package curl
93+
command -v jq >/dev/null || install_package jq
7994

8095
SWIFT_API_INSTALL_ROOT="https://www.swift.org/api/v1/install"
8196

@@ -295,8 +310,18 @@ initialize_os_info() {
295310
fi
296311

297312
log "✅ Detected OS from /etc/os-release: ${os_id}${version_id}"
298-
OS_NAME="${os_id}${version_id}"
299-
OS_NAME_NO_DOT="${os_id}$(echo "$version_id" | tr -d '.')"
313+
if [[ "$os_id" == "rhel" && "$version_id" == 9* ]]; then
314+
OS_NAME="ubi9"
315+
OS_NAME_NO_DOT="ubi9"
316+
elif [[ "$os_id" == "amzn" && "$version_id" == "2" ]]; then
317+
OS_NAME="amazonlinux2"
318+
OS_NAME_NO_DOT="amazonlinux2"
319+
else
320+
# Ubuntu, Debian, Fedora
321+
OS_NAME="${os_id}${version_id}"
322+
OS_NAME_NO_DOT="${os_id}$(echo "$version_id" | tr -d '.')"
323+
fi
324+
log "Using OS name: $OS_NAME"
300325

301326
local arch
302327
arch=$(uname -m)
@@ -341,6 +366,8 @@ download_and_verify() {
341366
rm -rf "$GNUPGHOME" "$temp_sig"
342367
}
343368

369+
readonly EXIT_TOOLCHAIN_NOT_FOUND=44
370+
344371
# Downloads and extracts the Swift toolchain for the given snapshot tag
345372
#
346373
# $1 (string): A snapshot tag, e.g. "swift-6.2-DEVELOPMENT-SNAPSHOT-2025-07-29-a"
@@ -368,7 +395,7 @@ download_and_extract_toolchain() {
368395
log "Toolchain not found: ${toolchain_filename}"
369396
log "Exiting workflow..."
370397
# Don't fail the workflow if we can't find the right toolchain
371-
exit 0
398+
exit $EXIT_TOOLCHAIN_NOT_FOUND
372399
fi
373400

374401
# Create toolchain directory
@@ -418,6 +445,10 @@ if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
418445
log "Installing Swift toolchain to match Static Linux Swift SDK snapshot: $STATIC_LINUX_SDK_TAG"
419446
initialize_os_info
420447
SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK=$(download_and_extract_toolchain "$STATIC_LINUX_SDK_TAG")
448+
if [[ $? -eq $EXIT_TOOLCHAIN_NOT_FOUND ]]; then
449+
# Don't fail the workflow if we can't find the right toolchain
450+
exit 0
451+
fi
421452
fi
422453
fi
423454

@@ -429,6 +460,10 @@ if [[ "$INSTALL_WASM" == true ]]; then
429460
log "Installing Swift toolchain to match Wasm Swift SDK snapshot: $WASM_SDK_TAG"
430461
initialize_os_info
431462
SWIFT_EXECUTABLE_FOR_WASM_SDK=$(download_and_extract_toolchain "$WASM_SDK_TAG")
463+
if [[ $? -eq $EXIT_TOOLCHAIN_NOT_FOUND ]]; then
464+
# Don't fail the workflow if we can't find the right toolchain
465+
exit 0
466+
fi
432467
fi
433468
fi
434469

0 commit comments

Comments
 (0)