Skip to content

Commit 8bba0c9

Browse files
committed
Try to simplify down the build scripts a little
1 parent 305819c commit 8bba0c9

File tree

6 files changed

+176
-155
lines changed

6 files changed

+176
-155
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ jobs:
7777
.build/release/swift-dependency-audit
7878
retention-days: 7
7979

80-
test-docker-builds:
81-
name: Test Docker Builds
82-
uses: ./.github/workflows/docker.yml
80+
test-linux-builds:
81+
name: Test Linux Builds
82+
uses: ./.github/workflows/linux.yml
8383
with:
8484
upload_artifacts: true
8585
artifact_retention_days: 7
@@ -128,7 +128,7 @@ jobs:
128128
validate-functionality:
129129
name: Validate Build Functionality
130130
runs-on: macos-15
131-
needs: [test, test-docker-builds]
131+
needs: [test, test-linux-builds]
132132
steps:
133133
- name: Checkout code
134134
uses: actions/checkout@v4

.github/workflows/docker.yml

Lines changed: 0 additions & 136 deletions
This file was deleted.

.github/workflows/linux.yml

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Linux Build
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
ref:
7+
description: "Git ref to checkout"
8+
required: false
9+
default: ${{ github.ref }}
10+
type: string
11+
upload_artifacts:
12+
description: "Whether to upload artifacts"
13+
required: false
14+
default: false
15+
type: boolean
16+
artifact_retention_days:
17+
description: "How long to retain artifacts"
18+
required: false
19+
default: 7
20+
type: number
21+
outputs:
22+
artifact_name_x86_64:
23+
description: "Name of the x86_64 Linux artifact"
24+
value: ${{ jobs.build-linux.outputs.artifact_name_x86_64 }}
25+
artifact_name_aarch64:
26+
description: "Name of the aarch64 Linux artifact"
27+
value: ${{ jobs.build-linux.outputs.artifact_name_aarch64 }}
28+
29+
jobs:
30+
build-linux:
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include:
35+
- arch: x86_64
36+
runner: ubuntu-latest
37+
triple: x86_64-unknown-linux-gnu
38+
- arch: aarch64
39+
runner: ubuntu-24.04-arm
40+
triple: aarch64-unknown-linux-gnu
41+
runs-on: ${{ matrix.runner }}
42+
outputs:
43+
artifact_name_x86_64: linux-x86_64-binary
44+
artifact_name_aarch64: linux-aarch64-binary
45+
steps:
46+
- name: Checkout code
47+
uses: actions/checkout@v4
48+
with:
49+
ref: ${{ inputs.ref }}
50+
51+
- name: Install Swift
52+
run: |
53+
# Check if Swift is already available
54+
if command -v swift >/dev/null 2>&1; then
55+
echo "Swift is already available:"
56+
swift --version
57+
else
58+
echo "Installing Swift using Swiftly..."
59+
60+
# Install Swiftly
61+
curl -L https://swift-server.github.io/swiftly/swiftly-install.sh | bash
62+
63+
# Add Swiftly to PATH for current session
64+
export PATH="$HOME/.local/bin:$PATH"
65+
echo "$HOME/.local/bin" >> $GITHUB_PATH
66+
67+
# Install latest Swift toolchain
68+
swiftly install latest
69+
swiftly use latest
70+
71+
echo "Swift installation completed:"
72+
swift --version
73+
fi
74+
75+
- name: Cache Swift Package Manager
76+
uses: actions/cache@v4
77+
with:
78+
path: |
79+
.build
80+
~/.cache/org.swift.swiftpm
81+
key: ${{ runner.os }}-${{ matrix.arch }}-spm-${{ hashFiles('Package.swift', 'Package.resolved') }}
82+
restore-keys: |
83+
${{ runner.os }}-${{ matrix.arch }}-spm-
84+
${{ runner.os }}-spm-
85+
86+
- name: Build native binary
87+
run: |
88+
echo "Building natively for ${{ matrix.arch }} on ${{ matrix.runner }}..."
89+
swift --version
90+
91+
echo 'Resolving dependencies...'
92+
swift package resolve
93+
94+
echo 'Building release binary with static linking...'
95+
swift build -c release --triple ${{ matrix.triple }} -Xswiftc -Osize --static-swift-stdlib
96+
97+
echo 'Stripping binary for size optimization...'
98+
strip .build/${{ matrix.triple }}/release/swift-dependency-audit
99+
100+
echo "✅ Native build completed successfully for ${{ matrix.arch }}"
101+
102+
- name: Verify binary was created and get info
103+
run: |
104+
echo "Binary information for ${{ matrix.arch }}:"
105+
ls -la .build/${{ matrix.triple }}/release/swift-dependency-audit
106+
file .build/${{ matrix.triple }}/release/swift-dependency-audit
107+
du -h .build/${{ matrix.triple }}/release/swift-dependency-audit
108+
109+
- name: Test binary functionality
110+
run: |
111+
echo "Testing static binary functionality for ${{ matrix.arch }}..."
112+
113+
# Since we're running natively, we can test functionality on both architectures
114+
.build/${{ matrix.triple }}/release/swift-dependency-audit --version
115+
.build/${{ matrix.triple }}/release/swift-dependency-audit --help
116+
117+
# Verify static linking (should have no dynamic Swift dependencies)
118+
echo "Verifying static linking..."
119+
ldd .build/${{ matrix.triple }}/release/swift-dependency-audit || echo "✅ Static binary - no dynamic dependencies"
120+
121+
echo "✅ Binary functionality tests passed for ${{ matrix.arch }}"
122+
123+
124+
- name: Upload binary artifacts
125+
if: inputs.upload_artifacts
126+
uses: actions/upload-artifact@v4
127+
with:
128+
name: linux-${{ matrix.arch }}-binary
129+
path: .build/${{ matrix.triple }}/release/swift-dependency-audit
130+
retention-days: ${{ inputs.artifact_retention_days }}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ jobs:
9393

9494
build-linux:
9595
name: Build Linux Binaries
96-
uses: ./.github/workflows/docker.yml
96+
uses: ./.github/workflows/linux.yml
9797
with:
9898
upload_artifacts: true
9999
artifact_retention_days: 30

CHANGELOG.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Universal macOS binary supporting ARM64 and x86_64 architectures
1414
- Linux binaries for x86_64 and ARM64 architectures
1515
- Automated GitHub Actions release workflow for multi-platform builds
16-
- Docker-based cross-compilation for Linux platforms
1716
- SHA256 checksum verification for binary integrity
1817
- Artifact bundle generation script for automated distribution
1918
- Hybrid binary/source build tool plugin execution following SwiftLint's proven pattern
@@ -98,7 +97,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9897
- Added `Scripts/spm-artifact-bundle.sh` for automated artifact bundle generation
9998
- Created `Scripts/spm-artifact-bundle-info.template` for Swift Package Manager manifest generation
10099
- Implemented GitHub Actions workflow with matrix strategy for cross-platform builds
101-
- Docker-based Linux compilation using `swift:6.1` image with platform-specific builds
102100
- Binary optimization with `strip` for size reduction and `-Xswiftc -Osize` for performance
103101
- Artifact bundle structure following SPM schema version 1.0 with multi-platform variants
104102
- Automated checksum calculation with SHA256 for security verification

0 commit comments

Comments
 (0)