-
Notifications
You must be signed in to change notification settings - Fork 5
136 lines (120 loc) · 4.85 KB
/
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
name: Automated Builds
on:
push:
branches:
- '**'
tags:
# Run when pushing version tags, since otherwise it's impossible to
# restart a successful build after pushing a tag
- '*.*.*'
pull_request:
branches:
- master
defaults:
run:
# This otherwise gets run under dash which does not support brace expansion
shell: bash
jobs:
# This builds the binaries and uploads them to GitHub Actions. A second job
# builds a universal binary out of the macOS binaries.
package:
strategy:
matrix:
include:
- { name: ubuntu-22.04, os: ubuntu-22.04, cross-target: '' }
- { name: macos-12-x86_64, os: macos-12, cross-target: '' }
- { name: macos-12-aarch64, os: macos-12, cross-target: aarch64-apple-darwin }
- { name: windows, os: windows-latest, cross-target: '' }
name: Build binary
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Fetch all git history
run: git fetch --force --prune --tags --unshallow
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ matrix.name }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Set up Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
# The macOS AArch64 build is done from an x86_64 macOS CI runner, so
# it needs to be cross compiled
targets: ${{ matrix.cross-target }}
- name: Build the binary
if: '!matrix.cross-target'
run: |
export MACOSX_DEPLOYMENT_TARGET=10.13
cargo build --release
- name: Build the binary
if: matrix.cross-target
run: |
export MACOSX_DEPLOYMENT_TARGET=10.13
cargo build --release --target="${{ matrix.cross-target }}"
- name: Determine the build archive name
run: |
echo "ARCHIVE_NAME=clap-validator-$(git describe --always)-${{ matrix.name }}" >> "$GITHUB_ENV"
# GitHub _very helpfully_ strips out the executable bit. Thanks GitHub, very cool.
- name: Create tarball
if: startsWith(matrix.os, 'ubuntu') || (startsWith(matrix.os, 'macos') && !matrix.cross-target)
run: |
tar -C target/release -caf "$ARCHIVE_NAME.tar.gz" clap-validator
- name: Create tarball
if: startsWith(matrix.os, 'macos') && matrix.cross-target
run: |
tar -C target/${{ matrix.cross-target }}/release -caf "$ARCHIVE_NAME.tar.gz" clap-validator
- uses: actions/upload-artifact@v4
if: "!startsWith(matrix.os, 'windows')"
with:
name: ${{ env.ARCHIVE_NAME }}
path: ${{ env.ARCHIVE_NAME }}.tar.gz
# On Windows we can just upload the .exe file directly since Windows
# doesn't have an executable bit
- uses: actions/upload-artifact@v4
if: startsWith(matrix.os, 'windows')
with:
name: ${{ env.ARCHIVE_NAME }}
path: target/release/clap-validator.exe
universal-binary:
name: Build a universal macOS binary
runs-on: macos-12
needs: package
steps:
- uses: actions/checkout@v4
- name: Fetch all git history
run: git fetch --force --prune --tags --unshallow
- name: Determine the previously build archive names
run: |
echo "X86_64_ARCHIVE_NAME=clap-validator-$(git describe --always)-macos-12-x86_64" >> "$GITHUB_ENV"
echo "AARCH64_ARCHIVE_NAME=clap-validator-$(git describe --always)-macos-12-aarch64" >> "$GITHUB_ENV"
- name: Determine archive name for the universal binary
run: |
echo "ARCHIVE_NAME=clap-validator-$(git describe --always)-macos-universal" >> "$GITHUB_ENV"
- name: Download the previously built x86_64 binary
uses: actions/download-artifact@v4
with:
name: ${{ env.X86_64_ARCHIVE_NAME }}
path: binaries/x86_64
- name: Download the previously built AArch64 binary
uses: actions/download-artifact@v4
with:
name: ${{ env.AARCH64_ARCHIVE_NAME }}
path: binaries/aarch64
- name: Combine the binaries
run: |
# There's only a single file in the directory, so that makes it easier
tar -C binaries/x86_64 -xvf binaries/x86_64/*.tar.gz
rm binaries/x86_64/*.tar.gz
tar -C binaries/aarch64 -xvf binaries/aarch64/*.tar.gz
rm binaries/aarch64/*.tar.gz
lipo -create -output binaries/clap-validator binaries/x86_64/clap-validator binaries/aarch64/clap-validator
tar -caf "$ARCHIVE_NAME.tar.gz" binaries/clap-validator
- uses: actions/upload-artifact@v4
with:
name: ${{ env.ARCHIVE_NAME }}
path: ${{ env.ARCHIVE_NAME }}.tar.gz