-
-
Notifications
You must be signed in to change notification settings - Fork 45
465 lines (424 loc) · 16.2 KB
/
latest-build.yml
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
name: Latest Build
on:
workflow_dispatch:
inputs:
deps_rev_override:
description: 'Deps Revision Override'
type: string
default: ''
required: false
push:
branches:
- master
paths:
- '**'
- '!.github/**'
- '!**.md'
- '!.gitattributes'
- '!examples/**.cy'
- '!examples/**/*.cy'
# Cancel previous job if it's running.
concurrency:
group: latest
cancel-in-progress: true
jobs:
build:
name: host=${{ matrix.config.host }} cmd=${{ matrix.config.cmd }} target=${{ matrix.config.target }} mode=${{ matrix.config.mode }}
runs-on: ${{ matrix.config.host }}
strategy:
fail-fast: false
matrix:
config:
- host: ubuntu-22.04
target: x86_64-linux-gnu
mode: release
cmd: cli
- host: ubuntu-22.04
target: x86_64-selinux-gnu
mode: release
cmd: cli
- host: macos-12
target: x86_64-macos-none
mode: release
cmd: cli
- host: macos-14
target: aarch64-macos-none
mode: release
cmd: cli
- host: windows-2022
target: x86_64-windows-gnu
mode: release
cmd: cli
- host: windows-2022
target: x86_64-windows-gnu
mode: release
cmd: lib
- host: windows-2022
target: x86_64-windows-msvc
mode: release
cmd: lib
- host: ubuntu-22.04
target: wasm32-freestanding
mode: release
cmd: web-lib
- host: ubuntu-22.04
target: wasm32-wasi
mode: release
cmd: cli
- host: ubuntu-22.04
target: x86_64-linux-gnu
mode: release
cmd: lib
- host: macos-12
target: x86_64-macos-none
mode: release
cmd: lib
- host: macos-14
target: aarch64-macos-none
mode: release
cmd: lib
env:
BIN_ZIP: >-
${{ fromJson('{
"x86_64-windows-gnu": "cyber-windows-x64.zip",
"x86_64-linux-gnu": "cyber-linux-x64.tar.gz",
"x86_64-selinux-gnu": "cyber-selinux-x64.tar.gz",
"x86_64-macos-none": "cyber-macos-x64.tar.gz",
"aarch64-macos-none": "cyber-macos-arm64.tar.gz",
"wasm32-freestanding": "cyber-web.wasm",
"wasm32-wasi": "cyber-wasi.wasm",
}')[matrix.config.target] }}
ZIG_TARGET_FLAG: >-
${{ fromJson('{
"x86_64-windows-gnu": "-Dtarget=x86_64-windows-gnu -Dcpu=baseline",
"x86_64-windows-msvc": "-Dtarget=x86_64-windows-msvc -Dcpu=baseline",
"x86_64-linux-gnu": "-Dtarget=x86_64-linux-gnu -Dcpu=baseline",
"x86_64-selinux-gnu": "-Dtarget=x86_64-linux-gnu -Dcpu=baseline -Dselinux",
"x86_64-macos-none": "-Dtarget=x86_64-macos-none -Dcpu=baseline",
"aarch64-macos-none": "-Dtarget=aarch64-macos-none -Dcpu=baseline",
"wasm32-freestanding": "-Dtarget=wasm32-freestanding",
"wasm32-wasi": "-Dtarget=wasm32-wasi",
}')[matrix.config.target] }}
BUILD_HOST: ${{ matrix.config.host }}
BUILD_TARGET: ${{ matrix.config.target }}
BUILD_MODE: ${{ matrix.config.mode }}
BUILD_CMD: ${{ matrix.config.cmd }}
BIN_NAME: cyber
BIN_EXT: ${{ contains(matrix.config.target, 'windows') && '.exe' || '' }}
ZIG_MODE_FLAG: ${{ (matrix.config.mode == 'release' && '-Doptimize=ReleaseFast') || '' }}
DEV_FLAG: ${{ startsWith(github.ref, 'refs/tags/') && '-Ddev=false' || '' }}
ZIG_VERSION: 0.12.0
steps:
- name: Install Linux deps.
if: env.BUILD_HOST == 'ubuntu-22.04' && env.BUILD_TARGET == 'x86_64-linux-gnu'
run: |
sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse"
sudo apt-get update -y -qq
sudo apt-get install xz-utils
- name: Clone repo.
uses: actions/checkout@v2
with:
# Fetch all so commit count can be computed from tag.
fetch-depth: 0
#submodules: recursive
- name: Install zig.
if: env.BUILD_HOST == 'ubuntu-22.04'
run: |
wget -c https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin
- name: Install wasm3.
if: env.BUILD_HOST == 'ubuntu-22.04' && (env.BUILD_TARGET == 'wasm32-freestanding' || env.BUILD_TARGET == 'wasm32-wasi')
run: |
git clone --depth=1 https://github.com/wasm3/wasm3.git
cd wasm3
mkdir build
cd build
cmake ..
make
- name: Install zig.
if: env.BUILD_HOST == 'macos-12'
run: |
wget -c https://ziglang.org/builds/zig-macos-x86_64-${{ env.ZIG_VERSION }}.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin
xcode-select --print-path
- name: Install zig.
if: env.BUILD_HOST == 'macos-14'
run: |
wget -c https://ziglang.org/builds/zig-macos-aarch64-${{ env.ZIG_VERSION }}.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin
xcode-select --print-path
- name: Install zig.
if: env.BUILD_HOST == 'windows-2022'
run: |
Invoke-WebRequest -Uri 'https://ziglang.org/builds/zig-windows-x86_64-${{ env.ZIG_VERSION }}.zip' -OutFile 'C:\zig.zip'
cd C:\
7z x zig.zip
Add-Content $env:GITHUB_PATH 'C:\zig-windows-x86_64-${{ env.ZIG_VERSION }}\'
- name: Setup script.
uses: actions/github-script@v5
with:
script: |
async function execCmd(name, args) {
const opts = {};
let out = '';
let err = '';
opts.listeners = {
stdout: (data) => {
out += data.toString();
},
stderr: (data) => {
process.stderr.write(data.toString());
}
};
// opt.cwd = './lib';
await exec.exec(name, args, opts);
return out;
}
const version = await execCmd('zig', ['build', 'version']);
const parts = version.split('.')
const last_version = parts[0] + '.' + (parseInt(parts[1])-1)
core.exportVariable('SHORT_VERSION', version);
await execCmd('git', ['fetch', '--all', '--tags']);
const build = await execCmd('git', ['rev-list', '--count', `${last_version}..${context.sha}`])
core.exportVariable('BUILD', build.trim());
core.exportVariable('COMMIT', context.sha.substring(0, 7));
- name: Cache.
#if: env.BUILD_TARGET != 'x86_64-windows-gnu'
uses: actions/cache@v2
with:
path: |-
~/.cache/zig
zig-cache
~/AppData/Local/zig
key:
build-${{ env.BUILD_TARGET }}-${{ env.BUILD_MODE }}-1
restore-keys:
build-${{ env.BUILD_TARGET }}-${{ env.BUILD_MODE }}-1
- name: Run tests. (debug)
if: env.BUILD_TARGET != 'wasm32-wasi' && (env.BUILD_CMD == 'cli' || (env.BUILD_CMD == 'lib' && env.BUILD_TARGET != 'x86_64-windows-msvc'))
run: |
zig build test ${{ env.ZIG_TARGET_FLAG }} ${{ env.DEV_FLAG }}
# Optimize with ReleaseSafe since there are issues with Zig 0.11.0 and building tests for ReleaseFast.
- name: Run tests. (release)
if: env.BUILD_TARGET != 'wasm32-wasi' && (env.BUILD_CMD == 'cli' || (env.BUILD_CMD == 'lib' && env.BUILD_TARGET != 'x86_64-windows-msvc'))
run: |
zig build test ${{ env.ZIG_TARGET_FLAG }} ${{ env.DEV_FLAG}} -Doptimize=ReleaseFast
- name: Run tests.
if: env.BUILD_TARGET == 'wasm32-freestanding' || env.BUILD_TARGET == 'wasm32-wasi'
run: |
zig build build-test -Dtarget=wasm32-wasi ${{ env.ZIG_MODE_FLAG }} ${{ env.DEV_FLAG }}
wasm3/build/wasm3 zig-out/bin/unit_test.wasm
wasm3/build/wasm3 zig-out/bin/test.wasm
wasm3/build/wasm3 zig-out/bin/trace_test.wasm
- name: Build.
run: zig build ${{ env.BUILD_CMD }} ${{ env.ZIG_MODE_FLAG }} ${{ env.ZIG_TARGET_FLAG }} ${{ env.DEV_FLAG }}
# Remove when zig strip is fixed.
- name: Strip (Linux)
if: env.BUILD_TARGET == 'x86_64-linux-gnu' && env.BUILD_MODE == 'release' && env.BUILD_CMD == 'cli'
run: |
strip zig-out/bin/cyber
# # Don't strip aarch64 since it was already code signed.
# # TODO: Look for way to make zig strip before doing the codesign.
# - name: Strip (macOS)
# if: env.BUILD_TARGET == 'x86_64-macos-none' && env.BUILD_MODE == 'release'
# run: |
# strip zig-out/${{ env.BUILD_TARGET }}/main/main
# # Currently just ad hoc signing.
# # aarch64 build is automatically signed by zig.
# - name: Codesign (macOS)
# if: env.BUILD_TARGET == 'x86_64-macos-none' && env.BUILD_MODE == 'release'
# run: |
# codesign --force --deep -s - zig-out/${{ env.BUILD_TARGET }}/main/main
# - name: Copy binary.
# run: cp
# zig-out/${{ env.BUILD_TARGET }}/main/main${{ env.BIN_EXT }}
# zig-out/${{ env.BUILD_TARGET }}/main/cosmic${{ env.BIN_EXT }}
- name: Zip. (linux/macos)
if: (env.BUILD_HOST == 'ubuntu-22.04' || env.BUILD_HOST == 'macos-12' || env.BUILD_HOST == 'macos-14') && env.BUILD_TARGET != 'wasm32-wasi' && env.BUILD_CMD == 'cli'
run: |
tar -C zig-out/bin -czvf ${{ env.BIN_ZIP }} cyber
- name: Zip. (windows)
if: env.BUILD_TARGET == 'x86_64-windows-gnu' && env.BUILD_CMD == 'cli'
shell: bash
run: |
cd zig-out/bin && 7z a ../../${{env.BIN_ZIP}} cyber.exe
- name: Move. (windows lib)
if: env.BUILD_TARGET == 'x86_64-windows-gnu' && env.BUILD_CMD == 'lib'
run: |
mv zig-out/lib/cyber.lib libcyber-windows-gnu-x64.lib
- name: Move. (windows lib)
if: env.BUILD_TARGET == 'x86_64-windows-msvc' && env.BUILD_CMD == 'lib'
run: |
mv zig-out/lib/cyber.lib libcyber-windows-msvc-x64.lib
- name: Move. (linux lib)
if: env.BUILD_TARGET == 'x86_64-linux-gnu' && env.BUILD_CMD == 'lib'
run: |
mv zig-out/lib/libcyber.a libcyber-linux-x64.a
- name: Move. (macos lib)
if: env.BUILD_TARGET == 'x86_64-macos-none' && env.BUILD_CMD == 'lib'
run: |
mv zig-out/lib/libcyber.a libcyber-macos-x64.a
- name: Move. (macos lib)
if: env.BUILD_TARGET == 'aarch64-macos-none' && env.BUILD_CMD == 'lib'
run: |
mv zig-out/lib/libcyber.a libcyber-macos-arm64.a
- name: Move. (wasm)
if: env.BUILD_TARGET == 'wasm32-freestanding'
run: |
mv zig-out/bin/cyber-web.wasm ${{ env.BIN_ZIP }}
- name: Move. (wasi)
if: env.BUILD_TARGET == 'wasm32-wasi'
run: |
mv zig-out/bin/cyber.wasm ${{ env.BIN_ZIP }}
- name: Save artifact.
if: env.BUILD_CMD == 'cli' || env.BUILD_CMD == 'web-lib'
uses: actions/upload-artifact@v2
with:
name: bin
path: |
${{ env.BIN_ZIP }}
- name: Save artifact.
if: env.BUILD_CMD == 'lib'
uses: actions/upload-artifact@v2
with:
name: bin
path: |
libcyber-windows-gnu-x64.lib
libcyber-windows-msvc-x64.lib
libcyber-linux-x64.a
libcyber-macos-x64.a
libcyber-macos-arm64.a
cyber-web.wasm
outputs:
short_version: ${{ env.SHORT_VERSION }}
# version: ${{ env.BUILD_VERSION }}
docs:
runs-on: ubuntu-22.04
env:
ZIG_VERSION: 0.12.0
steps:
- name: Clone repo.
uses: actions/checkout@v3
with:
submodules: false
fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod
- name: Install zig.
run: |
wget -c https://ziglang.org/builds/zig-linux-x86_64-${{ env.ZIG_VERSION }}.tar.xz -O - | tar -xJ --strip-components=1 -C /usr/local/bin
- name: Build md4c.
run: |
git clone --depth=1 https://github.com/mity/md4c.git
cd md4c
mkdir build
cd build
cmake ..
make
- name: Setup script.
uses: actions/github-script@v5
with:
script: |
async function execCmd(name, args) {
const opts = {};
let out = '';
let err = '';
opts.listeners = {
stdout: (data) => {
out += data.toString();
},
stderr: (data) => {
process.stderr.write(data.toString());
}
};
// opt.cwd = './lib';
await exec.exec(name, args, opts);
return out;
}
const version = await execCmd('zig', ['build', 'version']);
const parts = version.split('.')
const last_version = parts[0] + '.' + (parseInt(parts[1])-1)
core.exportVariable('SHORT_VERSION', version);
await execCmd('git', ['fetch', '--all', '--tags']);
const build = await execCmd('git', ['rev-list', '--count', `${last_version}..${context.sha}`])
core.exportVariable('BUILD', build.trim());
core.exportVariable('COMMIT', context.sha.substring(0, 7));
- name: Cache.
uses: actions/cache@v2
with:
path: |-
~/.cache/zig
zig-cache
key:
build-1
restore-keys:
build-1
- name: Build Cyber.
run: zig build cli
- name: Generate docs. (Release)
if: startsWith(github.ref, 'refs/tags/')
run: |
LD_LIBRARY_PATH=`pwd`/md4c/build/src zig-out/bin/cyber docs/gen-docs.cy -version v${{ env.SHORT_VERSION }}
mv docs/docs-modules.md docs.md
mv docs/docs.html docs.html
- name: Generate docs. (Dev)
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
run: |
LD_LIBRARY_PATH=`pwd`/md4c/build/src zig-out/bin/cyber docs/gen-docs.cy -version "${{ format('v{0}-DEV {1}-{2}', env.SHORT_VERSION, env.BUILD, env.COMMIT) }}"
mv docs/docs-modules.md docs.md
mv docs/docs.html docs.html
- name: Save artifact.
uses: actions/upload-artifact@v2
with:
name: bin
path: |
docs.html
docs.md
release:
needs: [build, docs]
name: Release
runs-on: ubuntu-22.04
steps:
- uses: actions/download-artifact@v2
with:
name: bin
# Manual dispatch.
- name: Github Latest Release.
uses: marvinpinto/action-automatic-releases@latest
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
automatic_release_tag: latest
prerelease: false
title: v${{ needs.build.outputs.short_version }}-DEV
files: |
cyber-linux-x64.tar.gz
cyber-selinux-x64.tar.gz
cyber-macos-x64.tar.gz
cyber-macos-arm64.tar.gz
cyber-windows-x64.zip
libcyber-windows-gnu-x64.lib
libcyber-windows-msvc-x64.lib
libcyber-linux-x64.a
libcyber-macos-x64.a
libcyber-macos-arm64.a
cyber-web.wasm
cyber-wasi.wasm
docs.html
docs.md
# Auto dispatch.
- name: Github Release.
uses: softprops/action-gh-release@v1
# Releases for tags only.
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
cyber-linux-x64.tar.gz
cyber-selinux-x64.tar.gz
cyber-macos-x64.tar.gz
cyber-macos-arm64.tar.gz
cyber-windows-x64.zip
libcyber-windows-gnu-x64.lib
libcyber-windows-msvc-x64.lib
libcyber-linux-x64.a
libcyber-macos-x64.a
libcyber-macos-arm64.a
cyber-web.wasm
cyber-wasi.wasm
docs.html
docs.md