Skip to content

Commit c1e26de

Browse files
committed
Support custom build commands for Swift static Linux/Wasm SDK builds
1 parent 1dac9d5 commit c1e26de

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
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
@@ -22,6 +22,7 @@ INSTALL_STATIC=false
2222
INSTALL_WASM=false
2323
SWIFT_VERSION_INPUT=""
2424
SWIFT_BUILD_FLAGS=""
25+
SWIFT_BUILD_COMMAND="swift build"
2526

2627
while [[ $# -gt 0 ]]; do
2728
case $1 in
@@ -37,6 +38,10 @@ while [[ $# -gt 0 ]]; do
3738
SWIFT_BUILD_FLAGS="${1#*=}"
3839
shift
3940
;;
41+
--build-command=*)
42+
SWIFT_BUILD_COMMAND="${1#*=}"
43+
shift
44+
;;
4045
-*)
4146
fatal "Unknown option: $1"
4247
;;
@@ -53,7 +58,7 @@ done
5358

5459
# Validate arguments
5560
if [[ -z "$SWIFT_VERSION_INPUT" ]]; then
56-
fatal "Usage: $0 [--static] [--wasm] [--flags=\"<build-flags>\"] <swift-version>"
61+
fatal "Usage: $0 [--static] [--wasm] [--flags=\"<build-flags>\"] [--build-command=\"<build-command>\"] <swift-version>"
5762
fi
5863

5964
if [[ "$INSTALL_STATIC" == false && "$INSTALL_WASM" == false ]]; then
@@ -484,11 +489,15 @@ install_sdks() {
484489
}
485490

486491
build() {
492+
# Enable alias expansion to use a 'swift' alias for the executable path
493+
shopt -s expand_aliases
494+
487495
if [[ "$INSTALL_STATIC" == true ]]; then
488496
log "Running Swift build with static SDK"
489497

490498
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"
499+
alias swift="$SWIFT_EXECUTABLE_FOR_STATIC_SDK"
500+
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk $sdk_name"
492501
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
493502
build_command="$build_command $SWIFT_BUILD_FLAGS"
494503
fi
@@ -506,7 +515,8 @@ build() {
506515
log "Running Swift build with Wasm SDK"
507516

508517
local sdk_name="${WASM_SDK_TAG}_wasm"
509-
local build_command="$SWIFT_EXECUTABLE_FOR_WASM_SDK build --swift-sdk $sdk_name"
518+
alias swift="$SWIFT_EXECUTABLE_FOR_WASM_SDK"
519+
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk $sdk_name"
510520
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
511521
build_command="$build_command $SWIFT_BUILD_FLAGS"
512522
fi

.github/workflows/swift_package_test.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ on:
6161
default: ""
6262
linux_static_sdk_pre_build_command:
6363
type: string
64-
description: "Linux command to execute before building the Swift package with the static SDK"
64+
description: "Command to execute before building the Swift package with the static Linux SDK"
6565
default: ""
6666
wasm_sdk_pre_build_command:
6767
type: string
68-
description: "Linux command to execute before building the Swift package with the Wasm SDK"
68+
description: "Command to execute before building the Swift package with the Wasm SDK"
6969
default: ""
7070
macos_pre_build_command:
7171
type: string
@@ -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 Swift package with the static Linux SDK"
85+
default: "swift build"
86+
wasm_sdk_build_command:
87+
type: string
88+
description: "Command to use when building the Swift package with the Wasm SDK"
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)