Skip to content

Commit 2c6b537

Browse files
authored
chore: use cargo-dist to build binaries (#170)
1 parent 9dc295e commit 2c6b537

File tree

4 files changed

+365
-0
lines changed

4 files changed

+365
-0
lines changed

.github/workflows/release.yml

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
# This file was autogenerated by dist: https://axodotdev.github.io/cargo-dist
2+
#
3+
# Copyright 2022-2024, axodotdev
4+
# SPDX-License-Identifier: MIT or Apache-2.0
5+
#
6+
# CI that:
7+
#
8+
# * checks for a Git Tag that looks like a release
9+
# * builds artifacts with dist (archives, installers, hashes)
10+
# * uploads those artifacts to temporary workflow zip
11+
# * on success, uploads the artifacts to a GitHub Release
12+
#
13+
# Note that the GitHub Release will be created with a generated
14+
# title/body based on your changelogs.
15+
16+
name: Release
17+
permissions:
18+
"contents": "write"
19+
20+
# This task will run whenever you push a git tag that looks like a version
21+
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
22+
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
23+
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
24+
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
25+
#
26+
# If PACKAGE_NAME is specified, then the announcement will be for that
27+
# package (erroring out if it doesn't have the given version or isn't dist-able).
28+
#
29+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
30+
# (dist-able) packages in the workspace with that version (this mode is
31+
# intended for workspaces with only one dist-able package, or with all dist-able
32+
# packages versioned/released in lockstep).
33+
#
34+
# If you push multiple tags at once, separate instances of this workflow will
35+
# spin up, creating an independent announcement for each one. However, GitHub
36+
# will hard limit this to 3 tags per commit, as it will assume more tags is a
37+
# mistake.
38+
#
39+
# If there's a prerelease-style suffix to the version, then the release(s)
40+
# will be marked as a prerelease.
41+
on:
42+
push:
43+
tags:
44+
- '**[0-9]+.[0-9]+.[0-9]+*'
45+
46+
jobs:
47+
# Run 'dist plan' (or host) to determine what tasks we need to do
48+
plan:
49+
runs-on: "ubuntu-22.04"
50+
outputs:
51+
val: ${{ steps.plan.outputs.manifest }}
52+
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
53+
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
54+
publishing: ${{ !github.event.pull_request }}
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
steps:
58+
- uses: actions/checkout@v4
59+
with:
60+
persist-credentials: false
61+
submodules: recursive
62+
- name: Install Rust
63+
run: rustup update "stable" --no-self-update && rustup default "stable"
64+
- name: Install dist
65+
# we specify bash to get pipefail; it guards against the `curl` command
66+
# failing. otherwise `sh` won't catch that `curl` returned non-0
67+
shell: bash
68+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.29.0/cargo-dist-installer.sh | sh"
69+
- name: Cache dist
70+
uses: actions/upload-artifact@v4
71+
with:
72+
name: cargo-dist-cache
73+
path: ~/.cargo/bin/dist
74+
# sure would be cool if github gave us proper conditionals...
75+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
76+
# functionality based on whether this is a pull_request, and whether it's from a fork.
77+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
78+
# but also really annoying to build CI around when it needs secrets to work right.)
79+
- id: plan
80+
run: |
81+
dist ${{ (!github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name)) || 'plan' }} --output-format=json > plan-dist-manifest.json
82+
echo "dist ran successfully"
83+
cat plan-dist-manifest.json
84+
echo "manifest=$(jq -c "." plan-dist-manifest.json)" >> "$GITHUB_OUTPUT"
85+
- name: "Upload dist-manifest.json"
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: artifacts-plan-dist-manifest
89+
path: plan-dist-manifest.json
90+
91+
# Build and packages all the platform-specific things
92+
build-local-artifacts:
93+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
94+
# Let the initial task tell us to not run (currently very blunt)
95+
needs:
96+
- plan
97+
if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
98+
strategy:
99+
fail-fast: false
100+
# Target platforms/runners are computed by dist in create-release.
101+
# Each member of the matrix has the following arguments:
102+
#
103+
# - runner: the github runner
104+
# - dist-args: cli flags to pass to dist
105+
# - install-dist: expression to run to install dist on the runner
106+
#
107+
# Typically there will be:
108+
# - 1 "global" task that builds universal installers
109+
# - N "local" tasks that build each platform's binaries and platform-specific installers
110+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
111+
runs-on: ${{ matrix.runner }}
112+
container: ${{ matrix.container && matrix.container.image || null }}
113+
env:
114+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
115+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
116+
steps:
117+
- name: enable windows longpaths
118+
run: |
119+
git config --global core.longpaths true
120+
- uses: actions/checkout@v4
121+
with:
122+
persist-credentials: false
123+
submodules: recursive
124+
- name: Install Rust non-interactively if not already installed
125+
if: ${{ matrix.container }}
126+
run: |
127+
if ! command -v cargo > /dev/null 2>&1; then
128+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
129+
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
130+
fi
131+
- name: Use rustup to set correct Rust version
132+
run: rustup update "stable" --no-self-update && rustup default "stable"
133+
- name: Install dist
134+
run: ${{ matrix.install_dist.run }}
135+
# Get the dist-manifest
136+
- name: Fetch local artifacts
137+
uses: actions/download-artifact@v4
138+
with:
139+
pattern: artifacts-*
140+
path: target/distrib/
141+
merge-multiple: true
142+
- name: Install dependencies
143+
run: |
144+
${{ matrix.packages_install }}
145+
- name: Build artifacts
146+
run: |
147+
# Actually do builds and make zips and whatnot
148+
dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
149+
echo "dist ran successfully"
150+
- id: cargo-dist
151+
name: Post-build
152+
# We force bash here just because github makes it really hard to get values up
153+
# to "real" actions without writing to env-vars, and writing to env-vars has
154+
# inconsistent syntax between shell and powershell.
155+
shell: bash
156+
run: |
157+
# Parse out what we just built and upload it to scratch storage
158+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
159+
dist print-upload-files-from-manifest --manifest dist-manifest.json >> "$GITHUB_OUTPUT"
160+
echo "EOF" >> "$GITHUB_OUTPUT"
161+
162+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
163+
- name: "Upload artifacts"
164+
uses: actions/upload-artifact@v4
165+
with:
166+
name: artifacts-build-local-${{ join(matrix.targets, '_') }}
167+
path: |
168+
${{ steps.cargo-dist.outputs.paths }}
169+
${{ env.BUILD_MANIFEST_NAME }}
170+
171+
# Build and package all the platform-agnostic(ish) things
172+
build-global-artifacts:
173+
needs:
174+
- plan
175+
- build-local-artifacts
176+
runs-on: "ubuntu-22.04"
177+
env:
178+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
179+
BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json
180+
steps:
181+
- uses: actions/checkout@v4
182+
with:
183+
persist-credentials: false
184+
submodules: recursive
185+
- name: Install Rust
186+
run: rustup update "stable" --no-self-update && rustup default "stable"
187+
- name: Install cached dist
188+
uses: actions/download-artifact@v4
189+
with:
190+
name: cargo-dist-cache
191+
path: ~/.cargo/bin/
192+
- run: chmod +x ~/.cargo/bin/dist
193+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
194+
- name: Fetch local artifacts
195+
uses: actions/download-artifact@v4
196+
with:
197+
pattern: artifacts-*
198+
path: target/distrib/
199+
merge-multiple: true
200+
- id: cargo-dist
201+
shell: bash
202+
run: |
203+
dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
204+
echo "dist ran successfully"
205+
206+
# Parse out what we just built and upload it to scratch storage
207+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
208+
jq --raw-output ".upload_files[]" dist-manifest.json >> "$GITHUB_OUTPUT"
209+
echo "EOF" >> "$GITHUB_OUTPUT"
210+
211+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
212+
- name: "Upload artifacts"
213+
uses: actions/upload-artifact@v4
214+
with:
215+
name: artifacts-build-global
216+
path: |
217+
${{ steps.cargo-dist.outputs.paths }}
218+
${{ env.BUILD_MANIFEST_NAME }}
219+
# Determines if we should publish/announce
220+
host:
221+
needs:
222+
- plan
223+
- build-local-artifacts
224+
- build-global-artifacts
225+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
226+
if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }}
227+
env:
228+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
229+
runs-on: "ubuntu-22.04"
230+
outputs:
231+
val: ${{ steps.host.outputs.manifest }}
232+
steps:
233+
- uses: actions/checkout@v4
234+
with:
235+
persist-credentials: false
236+
submodules: recursive
237+
- name: Install Rust
238+
run: rustup update "stable" --no-self-update && rustup default "stable"
239+
- name: Install cached dist
240+
uses: actions/download-artifact@v4
241+
with:
242+
name: cargo-dist-cache
243+
path: ~/.cargo/bin/
244+
- run: chmod +x ~/.cargo/bin/dist
245+
# Fetch artifacts from scratch-storage
246+
- name: Fetch artifacts
247+
uses: actions/download-artifact@v4
248+
with:
249+
pattern: artifacts-*
250+
path: target/distrib/
251+
merge-multiple: true
252+
# This is a harmless no-op for GitHub Releases, hosting for that happens in "announce"
253+
- id: host
254+
shell: bash
255+
run: |
256+
dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
257+
echo "artifacts uploaded and released successfully"
258+
cat dist-manifest.json
259+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
260+
- name: "Upload dist-manifest.json"
261+
uses: actions/upload-artifact@v4
262+
with:
263+
# Overwrite the previous copy
264+
name: artifacts-dist-manifest
265+
path: dist-manifest.json
266+
267+
# Create a GitHub Release while uploading all files to it
268+
announce:
269+
needs:
270+
- plan
271+
- host
272+
# use "always() && ..." to allow us to wait for all publish jobs while
273+
# still allowing individual publish jobs to skip themselves (for prereleases).
274+
# "host" however must run to completion, no skipping allowed!
275+
if: ${{ always() && needs.host.result == 'success' }}
276+
runs-on: "ubuntu-22.04"
277+
env:
278+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
279+
steps:
280+
- uses: actions/checkout@v4
281+
with:
282+
persist-credentials: false
283+
submodules: recursive
284+
# Create a GitHub Release while uploading all files to it
285+
- name: "Download GitHub Artifacts"
286+
uses: actions/download-artifact@v4
287+
with:
288+
pattern: artifacts-*
289+
path: artifacts
290+
merge-multiple: true
291+
- name: Cleanup
292+
run: |
293+
# Remove the granular manifests
294+
rm -f artifacts/*-dist-manifest.json
295+
- name: Create GitHub Release
296+
env:
297+
PRERELEASE_FLAG: "${{ fromJson(needs.host.outputs.val).announcement_is_prerelease && '--prerelease' || '' }}"
298+
ANNOUNCEMENT_TITLE: "${{ fromJson(needs.host.outputs.val).announcement_title }}"
299+
ANNOUNCEMENT_BODY: "${{ fromJson(needs.host.outputs.val).announcement_github_body }}"
300+
RELEASE_COMMIT: "${{ github.sha }}"
301+
run: |
302+
# Write and read notes from a file to avoid quoting breaking things
303+
echo "$ANNOUNCEMENT_BODY" > $RUNNER_TEMP/notes.txt
304+
305+
gh release create "${{ needs.plan.outputs.tag }}" --target "$RELEASE_COMMIT" $PRERELEASE_FLAG --title "$ANNOUNCEMENT_TITLE" --notes-file "$RUNNER_TEMP/notes.txt" artifacts/*

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,8 @@ lto = "fat"
5151
debug = 0
5252
strip = "debuginfo"
5353
codegen-units = 1
54+
55+
# The profile that 'dist' will build with
56+
[profile.dist]
57+
inherits = "release"
58+
lto = "thin"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ This crate provides a cross-platform support for managing Solidity compiler vers
88

99
## Install
1010

11+
With [cargo-binstall](https://github.com/cargo-bins/cargo-binstall):
12+
13+
```sh
14+
cargo binstall svm-rs
15+
```
16+
1117
From [crates.io](https://crates.io):
1218

1319
```sh

dist-workspace.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[workspace]
2+
members = ["cargo:."]
3+
4+
# Config for 'dist'
5+
[dist]
6+
# The preferred dist version to use in CI (Cargo.toml SemVer syntax)
7+
cargo-dist-version = "0.29.0"
8+
# CI backends to support
9+
ci = "github"
10+
# The installers to generate for each app
11+
installers = ["shell", "powershell"]
12+
# Whether to auto-include files like READMEs, LICENSEs, and CHANGELOGs (default true)
13+
auto-includes = false
14+
# The archive format to use for windows builds (defaults .zip)
15+
windows-archive = ".zip"
16+
# The archive format to use for non-windows builds (defaults .tar.xz)
17+
unix-archive = ".tar.gz"
18+
# Target platforms to build apps for (Rust target-triple syntax)
19+
targets = [
20+
"aarch64-apple-darwin",
21+
"aarch64-unknown-linux-gnu",
22+
"x86_64-apple-darwin",
23+
"x86_64-unknown-linux-gnu",
24+
"x86_64-unknown-linux-musl",
25+
"x86_64-pc-windows-msvc",
26+
]
27+
# Build only the required packages, and individually
28+
precise-builds = true
29+
# Features to pass to cargo build
30+
features = ["cli", "solc"]
31+
# Whether dist should create a Github Release or use an existing draft
32+
create-release = true
33+
# Which actions to run on pull requests
34+
pr-run-mode = "skip"
35+
# Whether CI should trigger releases with dispatches instead of tag pushes
36+
dispatch-releases = false
37+
# Which phase dist should use to create the GitHub release
38+
github-release = "announce"
39+
# Whether to install an updater program
40+
install-updater = false
41+
# Path that installers should place binaries in
42+
install-path = ["$XDG_BIN_HOME/", "$XDG_DATA_HOME/../bin", "~/.local/bin"]
43+
rust-toolchain-version = "stable"
44+
45+
[dist.dependencies.apt]
46+
gcc-aarch64-linux-gnu = { version = '*', targets = [
47+
"aarch64-unknown-linux-gnu",
48+
"aarch64-unknown-linux-musl",
49+
] }

0 commit comments

Comments
 (0)