-
Notifications
You must be signed in to change notification settings - Fork 0
158 lines (147 loc) · 5.74 KB
/
Copy pathbuild-binaries.yml
File metadata and controls
158 lines (147 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Build / Cross-Platform Binaries
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_call:
inputs:
version:
description: 'Version string to embed in artifact filenames (e.g. 1.0.1). If empty, derived from git.'
required: false
type: string
default: ''
outputs:
version:
description: 'Resolved version string used for the artifacts.'
value: ${{ jobs.resolve-version.outputs.version }}
env:
CARGO_TERM_COLOR: always
jobs:
resolve-version:
name: resolve version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: v
shell: bash
run: |
if [ -n "${{ inputs.version }}" ]; then
echo "version=${{ inputs.version }}" >> "$GITHUB_OUTPUT"
elif [ "${GITHUB_REF#refs/tags/}" != "${GITHUB_REF}" ]; then
echo "version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT"
else
echo "version=0.0.0-$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
fi
build:
name: build (${{ matrix.target }})
needs: resolve-version
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
runner: ubuntu-latest
archive: tar.gz
bin-suffix: ''
- target: aarch64-unknown-linux-gnu
runner: ubuntu-24.04-arm
archive: tar.gz
bin-suffix: ''
- target: universal2-apple-darwin
runner: macos-latest
archive: tar.gz
bin-suffix: ''
macos-targets: 'x86_64-apple-darwin aarch64-apple-darwin'
- target: x86_64-pc-windows-msvc
runner: windows-latest
archive: zip
bin-suffix: '.exe'
- target: aarch64-pc-windows-msvc
runner: windows-11-arm
archive: zip
bin-suffix: '.exe'
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.macos-targets || matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Build (single target)
if: matrix.target != 'universal2-apple-darwin'
shell: bash
run: |
cargo build --release --target ${{ matrix.target }} -p pcf-debug
cargo build --release --target ${{ matrix.target }} -p pcf-compact
cargo build --release --target ${{ matrix.target }} -p pfs-ms --bin pfs
- name: Build (macOS universal2)
if: matrix.target == 'universal2-apple-darwin'
shell: bash
run: |
for t in ${{ matrix.macos-targets }}; do
cargo build --release --target "$t" -p pcf-debug
cargo build --release --target "$t" -p pcf-compact
cargo build --release --target "$t" -p pfs-ms --bin pfs
done
mkdir -p target/universal2-apple-darwin/release
lipo -create -output target/universal2-apple-darwin/release/pcf-debug \
target/x86_64-apple-darwin/release/pcf-debug \
target/aarch64-apple-darwin/release/pcf-debug
lipo -create -output target/universal2-apple-darwin/release/pcf-compact \
target/x86_64-apple-darwin/release/pcf-compact \
target/aarch64-apple-darwin/release/pcf-compact
lipo -create -output target/universal2-apple-darwin/release/pfs \
target/x86_64-apple-darwin/release/pfs \
target/aarch64-apple-darwin/release/pfs
file target/universal2-apple-darwin/release/pcf-debug
file target/universal2-apple-darwin/release/pcf-compact
file target/universal2-apple-darwin/release/pfs
- name: Stage and archive (unix)
if: matrix.archive == 'tar.gz'
shell: bash
run: |
VERSION='${{ needs.resolve-version.outputs.version }}'
TARGET='${{ matrix.target }}'
mkdir -p staging
for bin in pcf-debug pcf-compact pfs; do
STAGE="staging/${bin}-${VERSION}-${TARGET}"
mkdir -p "$STAGE"
cp "target/${TARGET}/release/${bin}" "$STAGE/${bin}"
cp README.md "$STAGE/" 2>/dev/null || true
tar -czf "${STAGE}.tar.gz" -C staging "${bin}-${VERSION}-${TARGET}"
(cd staging && shasum -a 256 "${bin}-${VERSION}-${TARGET}.tar.gz" > "${bin}-${VERSION}-${TARGET}.tar.gz.sha256")
done
- name: Stage and archive (windows)
if: matrix.archive == 'zip'
shell: pwsh
run: |
$version = '${{ needs.resolve-version.outputs.version }}'
$target = '${{ matrix.target }}'
New-Item -ItemType Directory -Force staging | Out-Null
foreach ($bin in @('pcf-debug', 'pcf-compact', 'pfs')) {
$stage = "staging/$bin-$version-$target"
New-Item -ItemType Directory -Force $stage | Out-Null
Copy-Item "target/$target/release/$bin.exe" "$stage/$bin.exe"
if (Test-Path README.md) { Copy-Item README.md "$stage/" }
Compress-Archive -Path "$stage/*" -DestinationPath "$stage.zip" -Force
$hash = (Get-FileHash "$stage.zip" -Algorithm SHA256).Hash.ToLower()
"$hash $bin-$version-$target.zip" | Set-Content "$stage.zip.sha256"
}
- uses: actions/upload-artifact@v4
with:
name: binaries-${{ matrix.target }}
path: |
staging/*.tar.gz
staging/*.tar.gz.sha256
staging/*.zip
staging/*.zip.sha256
if-no-files-found: error
retention-days: 90