-
Notifications
You must be signed in to change notification settings - Fork 6
213 lines (185 loc) · 6.87 KB
/
Copy pathsubspace-build.yml
File metadata and controls
213 lines (185 loc) · 6.87 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Subspace Build
on:
workflow_dispatch:
push:
paths:
- 'subspace/**'
- '.github/workflows/subspace-build.yml'
env:
VCPKG_BINARY_SOURCES: 'clear;x-gha,readwrite'
jobs:
build:
name: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
include:
- platform: windows-x86_64
runner: windows-2022
triplet: x64-windows
msvc_arch: amd64
bin: subspace.exe
- platform: windows-aarch64
runner: windows-2022
triplet: arm64-windows
msvc_arch: amd64_arm64
bin: subspace.exe
- platform: linux-x86_64
runner: ubuntu-24.04
triplet: x64-linux
bin: subspace
- platform: linux-aarch64
runner: ubuntu-24.04
triplet: arm64-linux
cross_linux_aarch64: true
bin: subspace
- platform: macos-x86_64
runner: macos-26
triplet: x64-osx
osx_arch: x86_64
bin: subspace
- platform: macos-aarch64
runner: macos-26
triplet: arm64-osx
osx_arch: arm64
bin: subspace
runs-on: ${{ matrix.runner }}
defaults:
run:
working-directory: subspace
steps:
- uses: actions/checkout@v4
# Expose ACTIONS_CACHE_URL / ACTIONS_RUNTIME_TOKEN to subsequent steps so
# vcpkg's x-gha binary cache backend can authenticate against the runner's
# cache service. Without this step, vcpkg silently falls back to rebuilding
# every dependency from source on every run.
- name: Export GitHub Actions cache env for vcpkg
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Install CMake 4.2.x
uses: lukka/get-cmake@latest
with:
cmakeVersion: '~4.2.0'
- name: Install Linux build deps
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y ninja-build pkg-config
- name: Setup aarch64-linux cross toolchain
if: matrix.cross_linux_aarch64
run: |
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
mkdir -p "$RUNNER_TEMP/cmake"
cat > "$RUNNER_TEMP/cmake/aarch64-linux-toolchain.cmake" <<'EOF'
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
EOF
echo "VCPKG_CHAINLOAD_TOOLCHAIN_FILE=$RUNNER_TEMP/cmake/aarch64-linux-toolchain.cmake" >> "$GITHUB_ENV"
- name: Install macOS build deps
if: runner.os == 'macOS'
run: |
brew install ninja pkg-config || true
- name: Select Xcode 26 (macOS)
if: runner.os == 'macOS'
run: |
sudo xcode-select --switch /Applications/Xcode_26.0.app/Contents/Developer
echo "Selected: $(xcode-select -p)"
echo "SDK path: $(xcrun --show-sdk-path)"
- name: Setup MSVC environment
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: ${{ matrix.msvc_arch }}
- name: Configure
shell: bash
run: |
if [ -n "$VCPKG_INSTALLATION_ROOT" ]; then
export VCPKG_ROOT="$VCPKG_INSTALLATION_ROOT"
fi
echo "Using VCPKG_ROOT=$VCPKG_ROOT"
extra_args=()
if [ -n "${{ matrix.osx_arch }}" ]; then
extra_args+=("-DCMAKE_OSX_ARCHITECTURES=${{ matrix.osx_arch }}")
fi
if [ -n "$VCPKG_CHAINLOAD_TOOLCHAIN_FILE" ]; then
extra_args+=("-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=$VCPKG_CHAINLOAD_TOOLCHAIN_FILE")
fi
cmake -S . -B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" \
-DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }} \
"${extra_args[@]}"
- name: Build
run: cmake --build build --config Release
- name: Stage binary
shell: bash
run: |
mkdir -p _stage
cp "build/${{ matrix.bin }}" "_stage/${{ matrix.bin }}"
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: subspace-${{ matrix.platform }}
path: subspace/_stage/${{ matrix.bin }}
if-no-files-found: error
docker:
name: Docker build & push (Aliyun ACR)
needs: [build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download Linux artifacts
uses: actions/download-artifact@v4
with:
pattern: subspace-linux-*
path: _artifacts
- name: Stage binaries for docker build
run: |
mkdir -p subspace/bin/amd64 subspace/bin/arm64
cp _artifacts/subspace-linux-x86_64/subspace subspace/bin/amd64/subspace
cp _artifacts/subspace-linux-aarch64/subspace subspace/bin/arm64/subspace
chmod +x subspace/bin/amd64/subspace subspace/bin/arm64/subspace
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Aliyun ACR
run: |
docker login -u ${{ secrets.ACR_USERNAME }} -p ${{ secrets.ACR_PASSWORD }} ${{ secrets.ACR_REGISTRY }}
- name: Compute image tags
id: meta
run: |
IMAGE="${{ secrets.ACR_REGISTRY }}/${{ secrets.ACR_NAMESPACE }}/${{ secrets.ACR_REPOSITORY }}"
MOD_VERSION="$(grep -E '^mod_version=' gradle.properties | cut -d'=' -f2-)"
if [ -z "$MOD_VERSION" ]; then
echo "mod_version not found in gradle.properties" >&2
exit 1
fi
SAFE_MOD_VERSION="$(echo "$MOD_VERSION" | tr '+' '_')"
SHORT_SHA="$(git rev-parse --short HEAD)"
VERSION_TAG="${SAFE_MOD_VERSION}_${SHORT_SHA}"
TAGS="${IMAGE}:${VERSION_TAG},${IMAGE}:latest"
{
echo "tags=${TAGS}"
echo "primary=${VERSION_TAG}"
} >> "$GITHUB_OUTPUT"
echo "Will push: ${TAGS}"
- name: Build & push multi-arch image
uses: docker/build-push-action@v6
with:
context: ./subspace
file: ./subspace/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
provenance: false