Skip to content

Commit 4457fa3

Browse files
committed
build: move build complexity to justfile
Keep build logic as agnostic as possible to whatever CI task runner is used. Let the CI job focus on performance, like caching artifacts.
1 parent 64a88ab commit 4457fa3

File tree

6 files changed

+106
-93
lines changed

6 files changed

+106
-93
lines changed

.github/workflows/ci.yml

Lines changed: 39 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,62 @@
1+
# A few guiding principles.
2+
#
3+
# * Always use actions-rust-lang/setup-rust-toolchain for its built-in caching.
4+
# * Complexity lives in the justfile, this runner is as light as possible.
5+
16
name: Build & Test
27

8+
# Run on direct commits to master, including merges, and any pull requests against master.
39
on:
410
push:
511
branches:
612
- master
713
pull_request:
14+
branches:
15+
- master
816

917
jobs:
10-
build:
18+
# Quick canary of code as well as potential issues with upcoming toolchains.
19+
check:
1120
strategy:
1221
matrix:
13-
platform: [ubuntu-latest, macos-latest, windows-latest]
1422
toolchain: [stable, beta, nightly]
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: extractions/setup-just@v3
27+
- uses: actions-rust-lang/setup-rust-toolchain@v1
28+
with:
29+
toolchain: ${{ matrix.toolchain }}
30+
components: clippy,rustfmt
31+
- run: just check
32+
test:
33+
strategy:
34+
matrix:
35+
platform: [ubuntu-latest, macos-latest, windows-latest]
1536
runs-on: ${{ matrix.platform }}
1637
steps:
17-
- uses: actions/checkout@v3
18-
- name: Update Toolchain
19-
run: |
20-
rustup default ${{ matrix.toolchain }}
21-
rustup component add --toolchain ${{ matrix.toolchain }} rustfmt
22-
rustup component add --toolchain ${{ matrix.toolchain }} clippy
23-
rustup update ${{ matrix.toolchain }}
24-
- name: Lint all targets
25-
run: cargo clippy --all-targets
26-
- name: Format
27-
run: cargo fmt -- --check
28-
- name: Build with defeault features
29-
run: cargo build --verbose
30-
- name: Check release build on Rust ${{ matrix.toolchain }}
31-
run: cargo check --release --verbose --color always
32-
- name: Unit test
33-
run: cargo test --verbose --lib
34-
- name: Doc test
35-
run: cargo test --verbose --doc
36-
# Check that library code can be compiled with MSRV (1.63.0).
38+
- uses: actions/checkout@v4
39+
- uses: extractions/setup-just@v3
40+
- uses: actions-rust-lang/setup-rust-toolchain@v1
41+
- run: just test
3742
msrv:
3843
runs-on: ubuntu-latest
3944
steps:
40-
- uses: actions/checkout@v3
41-
# Modify build tools just for MSRV testing. This avoids us having
42-
# to bump our MSRV just for tooling. Tooling doesn't effect consumers so not a risk.
43-
- name: Prepare environment for MSRV toolchain
44-
run: |
45-
# Remove resolver = "3" line for MSRV compatibility. We use V3 to
46-
# generate an MSRV-compliant lockfile, but this isn't necessary to
47-
# check if library code is MSRV compliant. Any resolver can go
48-
# and grab the versions specified in the committed lockfile.
49-
#
50-
# The V3 resolver is standard in rust 1.85.
51-
sed -i '/resolver = "3"/d' Cargo.toml
52-
- name: Install MSRV toolchain
53-
run: |
54-
rustup toolchain install 1.63.0
55-
rustup default 1.63.0
56-
- name: Build with MSRV compiler
57-
run: cargo build --verbose
45+
- uses: actions/checkout@v4
46+
- uses: extractions/setup-just@v3
47+
- uses: actions-rust-lang/setup-rust-toolchain@v1
48+
- run: just test-msrv
5849
signet:
5950
runs-on: ubuntu-latest
6051
steps:
61-
- uses: actions/checkout@v3
62-
- name: Sync signet
63-
run: cargo test --verbose signet_syncs
52+
- uses: actions/checkout@v4
53+
- uses: extractions/setup-just@v3
54+
- uses: actions-rust-lang/setup-rust-toolchain@v1
55+
- run: just test-sync
6456
bitcoind:
6557
runs-on: ubuntu-latest
6658
steps:
67-
- uses: actions/checkout@v3
68-
- name: Integration test
69-
run: cargo test -- --test-threads 1 --skip signet_syncs --nocapture
59+
- uses: actions/checkout@v4
60+
- uses: extractions/setup-just@v3
61+
- uses: actions-rust-lang/setup-rust-toolchain@v1
62+
- run: just test-integrate

Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ repository = "https://github.com/rustaceanrob/kyoto"
99
readme = "README.md"
1010
keywords = ["bitcoin", "cryptography", "network", "peer-to-peer"]
1111
categories = ["cryptography::cryptocurrencies"]
12-
# MSRV-aware resolver which is the default in edition2024.
13-
resolver = "3"
1412
rust-version = "1.63.0"
1513

1614
[dependencies]

justfile

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,55 @@
1-
default:
2-
just --list
3-
4-
build:
5-
cargo build
6-
1+
set ignore-comments
2+
3+
nightly-toolchain := "nightly-2025-04-02"
4+
5+
# Hidden default lists all available recipies.
6+
_default:
7+
@just --list --list-heading $'KYOTO\n'
8+
9+
# Update Cargo.lock with strategy: msrv, min, or max.
10+
update-lockfile strategy="msrv":
11+
# "Fallback" MSRV resolving (v3) requires stable rust > 1.84. Older
12+
# versions have it behind an unstable flag on nightly.
13+
#
14+
# The minimal-versions feature for the min strategy
15+
# is still only on nightly.
16+
#
17+
# "Maximum" versions, the v2 default, is also available on stable > 1.84
18+
# with the --ignore-rust-version flag.
19+
@echo "Updating Cargo.lock using {{strategy}} strategy"
20+
@if [ "{{strategy}}" = "msrv" ]; then CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=fallback cargo update --verbose; \
21+
elif [ "{{strategy}}" = "min" ]; then cargo +{{nightly-toolchain}} update -Z direct-minimal-versions --verbose; \
22+
elif [ "{{strategy}}" = "max" ]; then cargo update --ignore-rust-version --verbose; \
23+
else echo "Error: Invalid strategy '{{strategy}}'" && exit 1; fi
24+
@echo "Lockfile update complete."
25+
26+
# Quick check of the code including lints and formatting.
727
check:
8-
cargo fmt
9-
cargo clippy --all-targets
28+
cargo fmt -- --check
29+
# Turn warnings into errors.
30+
cargo clippy --all-targets -- -D warnings
31+
cargo check
1032

33+
# Unit test suite.
1134
test:
1235
cargo test --lib
1336
cargo test --doc
37+
cargo test --examples
1438

15-
sync:
16-
cargo test signet_syncs -- --nocapture
17-
18-
integrate:
19-
cargo test -- --test-threads 1 --nocapture --skip signet_syncs
39+
# Check code with MSRV compiler.
40+
test-msrv:
41+
# Handles creating sandboxed environments to ensure no newer binaries sneak in.
42+
cargo install cargo-msrv@0.18.4
43+
cargo msrv verify
2044

21-
example:
22-
cargo run --example signet --release
23-
24-
signet:
25-
cargo run --example signet --release
45+
# Run the signet sync integration tests.
46+
test-sync:
47+
cargo test signet_syncs -- --nocapture
2648

27-
testnet:
28-
cargo run --example testnet --release
49+
# Run integration tests, except signet sync.
50+
test-integrate:
51+
cargo test --tests -- --test-threads 1 --nocapture --skip signet_syncs
2952

30-
all:
31-
cargo fmt
32-
cargo clippy --all-targets
33-
cargo test --lib
34-
cargo test --doc
35-
cargo test -- --test-threads 1 --nocapture --skip signet_syncs
36-
cargo run --example signet
53+
# Run the example: signet, testnet.
54+
example name="signet":
55+
cargo run --example {{name}} --release

rust-toolchain.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[toolchain]
2+
# >1.84 for stabalized MSRV resolving.
3+
channel = "1.85.0"
4+
# Default profile for CI, local installs probably also want to add the rust-analyzer component for IDE support.
5+
profile = "default"

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ pub type BlockReceiver = tokio::sync::oneshot::Receiver<Result<IndexedBlock, Fet
109109
use crate::error::FetchBlockError;
110110
#[cfg(feature = "filter-control")]
111111
use filters::Filter;
112-
#[cfg(feature = "filter-control")]
113-
use std::collections::HashSet;
114112

115113
use std::net::{IpAddr, SocketAddr};
116114

0 commit comments

Comments
 (0)