-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (147 loc) · 5.4 KB
/
build-binaries.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
name: "Build binaries"
on:
workflow_call:
inputs:
plan: # https://opensource.axo.dev/cargo-dist/book/ci/customizing.html
required: true
type: string
pull_request:
paths:
- .github/workflows/build-binaries.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
APP_NAME: tee-rs
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTFLAGS: "-D warnings -W unreachable-pub"
RUSTUP_MAX_RETRIES: 10
FETCH_DEPTH: 0 # pull in the tags for the version string
MACOSX_DEPLOYMENT_TARGET: 13.0
defaults:
run:
shell: bash -eux -o pipefail {0}
jobs:
dist:
strategy:
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
# https://blog.rust-lang.org/2022/08/01/Increasing-glibc-kernel-requirements.html
glib_version: 2.17
- os: ubuntu-20.04
target: aarch64-unknown-linux-gnu
glib_version: 2.17
- os: ubuntu-20.04
target: x86_64-unknown-linux-musl
- os: ubuntu-20.04
target: aarch64-unknown-linux-musl
- os: macos-13
target: x86_64-apple-darwin
- os: macos-13
target: aarch64-apple-darwin
name: dist (${{ matrix.target }})
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Prepare for common
run: |
CARGO_HOME="${{ runner.temp }}/.cargo"
echo CARGO_HOME="${CARGO_HOME}" >> "$GITHUB_ENV"
echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH"
- name: Prepare for Linux
if: ${{ contains(matrix.target, 'linux') }}
run: |
XDG_BIN_HOME="${{ runner.temp }}/.local/bin"
{
echo XDG_CONFIG_HOME="${{ runner.temp }}/.config"
echo XDG_CACHE_HOME="${{ runner.temp }}/.cache"
echo XDG_DATA_HOME="${{ runner.temp }}/.local/share"
echo XDG_BIN_HOME="${XDG_BIN_HOME}"
echo PYTHONUSERBASE="${{ runner.temp }}/.local"
} >> "$GITHUB_ENV"
{
echo "${XDG_BIN_HOME}"
} >> "$GITHUB_PATH"
- name: Prepare for MacOS
if: ${{ contains(matrix.target, 'darwin') }}
run: |
PYTHONUSERBASE="${{ runner.temp }}/.local"
echo PYTHONUSERBASE="$PYTHONUSERBASE/.local" >> "$GITHUB_ENV"
echo "$PYTHONUSERBASE/.local/bin" >> "$GITHUB_PATH"
- name: Prepare for Windows
if: ${{ contains(matrix.target, 'windows') }}
run: |
export PYTHONUSERBASE="${{ runner.temp }}/.local"
echo PYTHONUSERBASE="$PYTHONUSERBASE" >> "$GITHUB_ENV"
# Get 'Scripts' path
py_content=$(
cat <<'__PY_CONTENT_EOF__'
import site
from pathlib import Path
user_site_pkgs_path = Path(site.getusersitepackages())
print(user_site_pkgs_path.parent / "Scripts")
__PY_CONTENT_EOF__
)
py_scripts_path=$(python -c "$py_content")
if [[ -z "$py_scripts_path" ]]; then
echo "Failed to get 'Scripts' path" >&2
exit 1
fi
echo "$py_scripts_path" >> "$GITHUB_PATH"
# - name: Install Rust
# run: |
# curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" \
# | sh -s -- --profile minimal --default-toolchain none -y
# echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
- name: Update pip
run: python -m pip install --user -U pip
- name: Install cargo-zigbuild (and ziglang)
run: python -m pip install --user cargo-zigbuild
- name: Install Rust toolchain
run: |
rustup update --no-self-update stable
rustup target add ${{ matrix.target }}
rustup component add rust-src
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
- name: Dist
run: |
target="${{ matrix.target }}"
if [[ -n "${{ matrix.glib_version }}" ]]; then
target="${target}.${{ matrix.glib_version }}"
fi
cargo zigbuild --target="${target}" --release
- name: Archive binary for Unix-like systems
if: ${{ !contains(matrix.target, 'windows-msvc') }}
run: |
ARCHIVE_NAME="${{ env.APP_NAME }}-${{ matrix.target }}"
ARCHIVE_FILE="$ARCHIVE_NAME.tar.gz"
mkdir -p "$ARCHIVE_NAME"
cp "target/${{ matrix.target }}/release/${{ env.APP_NAME }}" "$ARCHIVE_NAME/${{ env.APP_NAME }}"
tar czvf "$ARCHIVE_FILE" "$ARCHIVE_NAME"
shasum -a 256 "$ARCHIVE_FILE" > "$ARCHIVE_FILE.sha256"
- name: Archive binary for Windows
if: ${{ contains(matrix.target, 'windows-msvc') }}
run: |
ARCHIVE_NAME="${{ env.APP_NAME }}-${{ matrix.target }}"
ARCHIVE_FILE="$ARCHIVE_NAME.zip"
7z a "$ARCHIVE_FILE" ./target/${{ matrix.target }}/release/${{ env.APP_NAME }}.exe
sha256sum $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.target }}
retention-days: 1
path: |
*.tar.gz
*.zip
*.sha256