Skip to content

Commit

Permalink
chore: tidy up CI, add release workflow (#6)
Browse files Browse the repository at this point in the history
- use ubuntu-latest; deduplicate apt installation
- rework CI matrix
- build for musl, not glibc
- add release workflow to create the binary package
- don't use mold (not supported by rust cross)
- enable LTO & strip on release builds
  • Loading branch information
crazyscot authored Oct 28, 2024
1 parent ce878b6 commit dedfe22
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[target.'cfg(target_os="linux")']
rustflags = ["-C", "link-arg=-fuse-ld=mold"]
# using mold breaks cargo cross on musl (the image is based on focal, which does not have a mold package)
#rustflags = ["-C", "link-arg=-fuse-ld=mold"]

[target.'cfg(target_os="windows")']
rustflags = ["-C", "link-arg=-fuse-ld=lld"]
Expand Down
32 changes: 20 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,45 @@ jobs:
build:
strategy:
matrix:
platform: [ubuntu-22.04]
runs-on: ${{ matrix.platform }}
include:
- build: x86_64-musl
host: ubuntu-latest
target: x86_64-unknown-linux-musl
rust: stable
runs-on: ${{ matrix.host }}
steps:
- uses: actions/checkout@v4
- name: Set minimal profile (Windows only)
if: matrix.platform == 'windows-latest'
run: rustup set profile minimal
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
#- name: Set minimal profile (Windows only)
# if: matrix.host == 'windows-latest'
# run: rustup set profile minimal
- uses: Swatinem/rust-cache@v2
with:
key: "${{matrix.platform}}"
key: "${{matrix.build}}"
- name: install packages (ubuntu)
if: matrix.platform == 'ubuntu-22.04'
run: sudo apt-get update && sudo apt-get -y --no-install-recommends install mold capnproto
if: startsWith(matrix.host, 'ubuntu')
run: scripts/install-ubuntu-packages
- name: Build
run: cargo build --locked

# We only need to run the checks on a single platform
checks:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
key: ubuntu-22.04
key: ubuntu-latest
- name: install packages
run: sudo apt-get update && sudo apt-get -y --no-install-recommends install mold capnproto
run: scripts/install-ubuntu-packages
# Checks begin here!
- run: cargo fmt --all -- --check
- run: cargo test --locked
- run: cargo clippy --locked --all-targets
# We care that the benchmarks build and run, not about their numeric output.
# To keep the CI a bit leaner, do this in the dev profile.
- run: cargo build --locked --all-targets
- run: cargo doc --document-private-items
- run: cargo doc --no-deps --locked
51 changes: 51 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: release

on:
release:
types: [published]
# useful for testing
#push:
# branches:
# - misc/ci-auto-release

permissions:
contents: write

jobs:
binary:
strategy:
matrix:
include:
- build: x86_64-musl
host: ubuntu-latest
target: x86_64-unknown-linux-musl
rust: stable
runs-on: ${{ matrix.host }}
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
with:
key: "${{matrix.build}}"
#- name: install packages (ubuntu)
# if: startsWith(matrix.host, 'ubuntu')
# run: scripts/install-ubuntu-packages
- uses: taiki-e/upload-rust-binary-action@v1
id: build
with:
bin: qcp
token: ${{ secrets.GITHUB_TOKEN }}
target: ${{ matrix.target }}
include: README.md,LICENSE,CHANGELOG.md
leading-dir: true
tar: unix
zip: windows
# dry_run: true # when testing the workflow
# Uploading the artifact is useful when testing the workflow in dry-run mode
- uses: actions/upload-artifact@v4
with:
name: binary-${{ matrix.target }}
path: ${{ steps.build.outputs.archive }}.tar.gz
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ homepage = "https://github.com/crazyscot/qcp/"
keywords = [ "networking", "file-transfer", "quic" ]
categories = [ "command-line-utilities" ]

[profile.release]
lto = "thin"
strip = "symbols"

[dependencies]
anstyle = "1.0.8"
anyhow = "1.0.89"
Expand Down Expand Up @@ -81,3 +85,6 @@ invalid_rust_codeblocks = "deny"
missing_crate_level_docs = "deny"
private_intra_doc_links = "deny"
unescaped_backticks = "deny"

[package.metadata.cross.target.x86_64-unknown-linux-musl]
pre-build = [ "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y --no-install-recommends install capnproto" ]
5 changes: 5 additions & 0 deletions scripts/install-ubuntu-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -e

export DEBIAN_FRONTEND=noninteractive
sudo apt-get update
sudo apt-get -y --no-install-recommends install capnproto musl-tools

0 comments on commit dedfe22

Please sign in to comment.