Skip to content

Commit 0aeabcc

Browse files
committed
Support custom build commands for Swift static Linux/Wasm SDK builds
1 parent 6065185 commit 0aeabcc

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
@@ -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
@@ -490,11 +495,15 @@ install_sdks() {
490495
}
491496

492497
build() {
498+
# Enable alias expansion to use a 'swift' alias for the executable path
499+
shopt -s expand_aliases
500+
493501
if [[ "$INSTALL_STATIC_LINUX" == true ]]; then
494502
log "Running Swift build with Static Linux Swift SDK"
495503

496504
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"
505+
alias swift="$SWIFT_EXECUTABLE_FOR_STATIC_LINUX_SDK"
506+
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk $sdk_name"
498507
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
499508
build_command="$build_command $SWIFT_BUILD_FLAGS"
500509
fi
@@ -517,7 +526,8 @@ build() {
517526
local sdk_name="${WASM_SDK_TAG}_wasm"
518527
fi
519528

520-
local build_command="$SWIFT_EXECUTABLE_FOR_WASM_SDK build --swift-sdk $sdk_name"
529+
alias swift="$SWIFT_EXECUTABLE_FOR_WASM_SDK"
530+
local build_command="$SWIFT_BUILD_COMMAND --swift-sdk $sdk_name"
521531
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
522532
build_command="$build_command $SWIFT_BUILD_FLAGS"
523533
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)