Skip to content

Commit e70d8f8

Browse files
committed
Fix pre-build command and support Swift build flags
1 parent a96f534 commit e70d8f8

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

.github/workflows/pull_request.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ jobs:
1010
uses: ./.github/workflows/swift_package_test.yml
1111
with:
1212
# Linux
13-
linux_pre_build_command: |
13+
linux_build_command: |
14+
mkdir MyPackage
15+
cd MyPackage
16+
swift package init --type library
17+
swift build
18+
linux_static_sdk_pre_build_command: |
1419
mkdir MyPackage
1520
cd MyPackage
1621
swift package init --type library
17-
linux_build_command: "swift build"
1822
enable_linux_static_sdk_build: true
1923
# Windows
2024
windows_build_command: |

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

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fatal() { error "$@"; exit 1; }
2121
INSTALL_STATIC=false
2222
INSTALL_WASM=false
2323
SWIFT_VERSION_INPUT=""
24+
SWIFT_BUILD_FLAGS=""
2425

2526
while [[ $# -gt 0 ]]; do
2627
case $1 in
@@ -32,6 +33,14 @@ while [[ $# -gt 0 ]]; do
3233
INSTALL_WASM=true
3334
shift
3435
;;
36+
--flags)
37+
if [[ -n "$2" && "$2" != --* ]]; then
38+
SWIFT_BUILD_FLAGS="$2"
39+
shift 2
40+
else
41+
fatal "--flags requires an argument"
42+
fi
43+
;;
3544
-*)
3645
fatal "Unknown option: $1"
3746
;;
@@ -48,7 +57,7 @@ done
4857

4958
# Validate arguments
5059
if [[ -z "$SWIFT_VERSION_INPUT" ]]; then
51-
fatal "Usage: $0 [--static] [--wasm] <swift-version>"
60+
fatal "Usage: $0 [--static] [--wasm] [--flags \"<build-flags>\"] <swift-version>"
5261
fi
5362

5463
if [[ "$INSTALL_STATIC" == false && "$INSTALL_WASM" == false ]]; then
@@ -57,7 +66,10 @@ fi
5766

5867
log "Requested Swift version: $SWIFT_VERSION_INPUT"
5968
log "Install static SDK: $INSTALL_STATIC"
60-
log "Install WASM SDK: $INSTALL_WASM"
69+
log "Install wasm SDK: $INSTALL_WASM"
70+
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
71+
log "Additional build flags: $SWIFT_BUILD_FLAGS"
72+
fi
6173

6274
# Install dependencies
6375
command -v curl >/dev/null || (apt update -q && apt install -yq curl)
@@ -474,23 +486,35 @@ install_sdks() {
474486

475487
build() {
476488
if [[ "$INSTALL_STATIC" == true ]]; then
477-
local sdk_name="${STATIC_SDK_TAG}_static-linux-0.0.1"
478489
log "Running Swift build with static SDK"
479-
log "Command: ${SWIFT_EXECUTABLE_FOR_STATIC_SDK} build --swift-sdk ${sdk_name}"
480490

481-
if "$SWIFT_EXECUTABLE_FOR_STATIC_SDK" build --swift-sdk "$sdk_name"; then
491+
local sdk_name="${STATIC_SDK_TAG}_static-linux-0.0.1"
492+
local build_command="$SWIFT_EXECUTABLE_FOR_STATIC_SDK build --swift-sdk $sdk_name"
493+
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
494+
build_command="$build_command $SWIFT_BUILD_FLAGS"
495+
fi
496+
497+
log "Running: $build_command"
498+
499+
if eval "$build_command"; then
482500
log "✅ Swift build with static SDK completed successfully"
483501
else
484502
fatal "Swift build with static SDK failed"
485503
fi
486504
fi
487505

488506
if [[ "$INSTALL_WASM" == true ]]; then
489-
local sdk_name="${WASM_SDK_TAG}_wasm"
490507
log "Running Swift build with wasm SDK"
491-
log "Command: ${SWIFT_EXECUTABLE_FOR_WASM_SDK} build --swift-sdk ${sdk_name}"
492508

493-
if "$SWIFT_EXECUTABLE_FOR_WASM_SDK" build --swift-sdk "$sdk_name"; then
509+
local sdk_name="${WASM_SDK_TAG}_wasm"
510+
local build_command="$SWIFT_EXECUTABLE_FOR_WASM_SDK build --swift-sdk $sdk_name"
511+
if [[ -n "$SWIFT_BUILD_FLAGS" ]]; then
512+
build_command="$build_command $SWIFT_BUILD_FLAGS"
513+
fi
514+
515+
log "Running: $build_command"
516+
517+
if eval "$build_command"; then
494518
log "✅ Swift build with wasm SDK completed successfully"
495519
else
496520
fatal "Swift build with wasm SDK failed"

.github/workflows/swift_package_test.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ on:
5555
type: string
5656
description: "Linux command to execute before building the Swift package"
5757
default: ""
58+
linux_static_sdk_pre_build_command:
59+
type: string
60+
description: "Linux command to execute before building the Swift package with the static SDK"
61+
default: ""
5862
macos_pre_build_command:
5963
type: string
6064
description: "macOS command to execute before building the Swift package"
@@ -213,9 +217,13 @@ jobs:
213217
- name: Pre-build
214218
run: ${{ inputs.linux_pre_build_command }}
215219
- name: Install static SDK and build
220+
env:
221+
BUILD_FLAGS: ${{ (contains(matrix.swift_version, 'nightly') && inputs.swift_nightly_flags) || inputs.swift_flags }}
216222
run: |
223+
${{ inputs.linux_static_sdk_pre_build_command }}
217224
which curl || (apt -q update && apt -yq install curl)
218-
curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | bash -s -- --static
225+
curl -s --retry 3 https://raw.githubusercontent.com/swiftlang/github-workflows/refs/heads/main/.github/workflows/scripts/install-and-build-with-sdk.sh | \
226+
bash -s -- --static --flags "$BUILD_FLAGS" ${{ matrix.swift_version }}
219227
220228
windows-build:
221229
name: Windows (${{ matrix.swift_version }} - windows-2022)

0 commit comments

Comments
 (0)