-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (122 loc) · 4.04 KB
/
_rust-binary.yml
File metadata and controls
133 lines (122 loc) · 4.04 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
name: Rust Binary Release
on:
workflow_call:
inputs:
bin_name:
description: 'Binary name (e.g., image-resize)'
required: true
type: string
manifest_path:
description: 'Path to Cargo.toml (e.g., image-resize/Cargo.toml)'
required: true
type: string
tag_name:
description: 'Git tag for the GitHub Release (e.g., image-resize/v1.0.0)'
required: true
type: string
is_prerelease:
description: 'Mark as pre-release'
required: false
type: boolean
default: false
skip_create_release:
description: 'Skip GH release creation (assumes release already exists for the tag)'
required: false
type: boolean
default: false
dry_run:
description: 'Build binaries without uploading or creating releases'
required: false
type: boolean
default: false
env:
CARGO_TERM_COLOR: always
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
jobs:
pre-build:
name: Pre-build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
if: inputs.skip_create_release != true && inputs.dry_run != true
- name: Create GitHub Release
if: inputs.skip_create_release != true && inputs.dry_run != true
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.tag_name }}
name: ${{ inputs.bin_name }} ${{ inputs.tag_name }}
draft: false
prerelease: ${{ inputs.is_prerelease }}
generate_release_notes: true
build:
name: Build ${{ matrix.target }}
needs: [pre-build]
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-apple-darwin
os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: i686-pc-windows-msvc
os: windows-latest
- target: aarch64-pc-windows-msvc
os: windows-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-22.04
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-22.04
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Rewrite SSH to HTTPS for public deps
run: git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"
- name: Install cross-compilation tools
if: runner.os == 'Linux'
env:
BUILD_TARGET: ${{ matrix.target }}
run: |
sudo apt-get update
case "$BUILD_TARGET" in
x86_64-unknown-linux-musl)
sudo apt-get install -y musl-tools
;;
aarch64-unknown-linux-gnu)
sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross
;;
armv7-unknown-linux-gnueabihf)
sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross
;;
esac
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache cargo registry & build
uses: Swatinem/rust-cache@v2
with:
key: ${{ inputs.bin_name }}-${{ matrix.target }}
- name: Build and upload binary
uses: taiki-e/upload-rust-binary-action@v1
with:
bin: ${{ inputs.bin_name }}
target: ${{ matrix.target }}
ref: refs/tags/${{ inputs.tag_name }}
tar: unix
zip: windows
checksum: sha256
manifest-path: ${{ inputs.manifest_path }}
token: ${{ github.token }}
dry-run: ${{ inputs.dry_run }}