Skip to content

Commit b8f8a6c

Browse files
authored
Support custom build commands for Swift static Linux/Wasm SDK builds (#149)
* Support custom build commands for Swift static Linux/Wasm SDK builds * Update script URL to this PR branch for testing * Revert "Update script URL to this PR branch for testing" This reverts commit f956c65.
1 parent 77f315f commit b8f8a6c

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ INSTALL_WASM=false
2323
BUILD_EMBEDDED_WASM=false
2424
SWIFT_VERSION_INPUT=""
2525
SWIFT_BUILD_FLAGS=""
26+
SWIFT_BUILD_COMMAND="swift build"
2627

2728
while [[ $# -gt 0 ]]; do
2829
case $1 in
@@ -43,6 +44,10 @@ while [[ $# -gt 0 ]]; do
4344
SWIFT_BUILD_FLAGS="${1#*=}"
4445
shift
4546
;;
47+
--build-command=*)
48+
SWIFT_BUILD_COMMAND="${1#*=}"
49+
shift
50+
;;
4651
-*)
4752
fatal "Unknown option: $1"
4853
;;
@@ -59,7 +64,7 @@ done
5964

6065
# Validate arguments
6166
if [[ -z "$SWIFT_VERSION_INPUT" ]]; then
62-
fatal "Usage: $0 [--static] [--wasm] [--flags=\"<build-flags>\"] <swift-version>"
67+
fatal "Usage: $0 [--static] [--wasm] [--flags=\"<build-flags>\"] [--build-command=\"<build-command>\"] <swift-version>"
6368
fi
6469

6570
if [[ "$INSTALL_STATIC_LINUX" == false && "$INSTALL_WASM" == false ]]; then
@@ -525,11 +530,15 @@ install_sdks() {
525530
}
526531

527532
build() {
533+
# Enable alias expansion to use a 'swift' alias for the executable path
534+
shopt -s expand_aliases
535+
528536
if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
529537
log "Running Swift build with Static Linux Swift SDK"
530538

531539
local sdk_name="${STATIC_LINUX_SDK_TAG}_static-linux-0.0.1"
532-
local build_command="$SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK build --swift-sdk $sdk_name"
540+
alias swift='$SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK'
541+
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk $sdk_name"
533542
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
534543
build_command="$build_command $SWIFT_BUILD_FLAGS"
535544
fi
@@ -552,7 +561,8 @@ build() {
552561
local sdk_name="${WASM_SDK_TAG}_wasm"
553562
fi
554563

555-
local build_command="$SWIFT_EXECUTABLE_FOR_WASM_SDK build --swift-sdk $sdk_name"
564+
alias swift='$SWIFT_EXECUTABLE_FOR_WASM_SDK'
565+
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk $sdk_name"
556566
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
557567
build_command="$build_command $SWIFT_BUILD_FLAGS"
558568
fi

.github/workflows/swift_package_test.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ on:
7979
type: string
8080
description: "Linux command to build and test the package"
8181
default: "swift test"
82+
linux_static_sdk_build_command:
83+
type: string
84+
description: "Command to use when building the package with the Static Linux Swift SDK"
85+
default: "swift build"
86+
wasm_sdk_build_command:
87+
type: string
88+
description: "Command to use when building the package with the Swift SDK for Wasm"
89+
default: "swift build"
8290
windows_pre_build_command:
8391
type: string
8492
description: "Windows Command Prompt command to execute before building the Swift package"
@@ -235,7 +243,7 @@ jobs:
235243
${{ inputs.linux_static_sdk_pre_build_command }}
236244
which curl || (apt -q update && apt -yq install curl)
237245
curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | \
238-
bash -s -- --static --flags="$BUILD_FLAGS" ${{ matrix.swift_version }}
246+
bash -s -- --static --flags="$BUILD_FLAGS" --build-command="${{ inputs.linux_static_sdk_build_command }}" ${{ matrix.swift_version }}
239247
240248
wasm-sdk-build:
241249
name: Wasm SDK Build (${{ matrix.swift_version }} - ${{ matrix.os_version }})
@@ -273,7 +281,7 @@ jobs:
273281
${{ inputs.wasm_sdk_pre_build_command }}
274282
which curl || (apt -q update && apt -yq install curl)
275283
curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | \
276-
bash -s -- --wasm --flags="$BUILD_FLAGS" ${{ matrix.swift_version }}
284+
bash -s -- --wasm --flags="$BUILD_FLAGS" --build-command="${{ inputs.wasm_sdk_build_command }}" ${{ matrix.swift_version }}
277285
278286
windows-build:
279287
name: Windows (${{ matrix.swift_version }} - windows-2022)

0 commit comments

Comments
 (0)