Skip to content

Commit a3dd967

Browse files
committed
build: move build complexity to justfile
Keep build and test logic as agnostic as possible to whatever CI task runner is used (today that is Github Actions). Let the CI job focus on performance, like caching artifacts and keep the build and test logic in the forefront easy for developers to use. With that goal in mind, the CI job has been refactored to a handful of jobs which each call a `just` recipe. Consistent caching has been added to each job which shows a nice improvement in speed for the workflow, running in less than a minute. The justfile has been refactored with the logic that previously lived in the CI yaml. This makes it easier to maintain as well as run locally when developing. A few un-used recipes have been cleaned up. Lockfile complexity has been relegated to the _test-msrv recipe. This recipe checks that there is at least one set of dependencies which satisfy the msrv requirements. The check no longer depends on the checked in lockfile which doesn't matter much since consumers create their own. A rust-toolchain.toml file was added as a gently nudge for contributers to stay on a recent version of "stable", that way we can use some of the newer features like the v3 resolver and see less of "works on my machine". CI will most likely not use the file however, since it usually needs to test more complex things like MSRV.
1 parent 64a88ab commit a3dd967

File tree

10 files changed

+130
-106
lines changed

10 files changed

+130
-106
lines changed

.github/workflows/ci.yml

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,70 @@
1-
name: Build & Test
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+
6+
name: CI
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+
# Build and test the code across platforms.
33+
test:
34+
strategy:
35+
matrix:
36+
platform: [ubuntu-latest, macos-latest, windows-latest]
1537
runs-on: ${{ matrix.platform }}
1638
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).
39+
- uses: actions/checkout@v4
40+
- uses: extractions/setup-just@v3
41+
- uses: actions-rust-lang/setup-rust-toolchain@v1
42+
- run: just test unit
43+
features:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
- uses: extractions/setup-just@v3
48+
- uses: actions-rust-lang/setup-rust-toolchain@v1
49+
- run: just test features
3750
msrv:
3851
runs-on: ubuntu-latest
3952
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
58-
signet:
53+
- uses: actions/checkout@v4
54+
- uses: extractions/setup-just@v3
55+
- uses: actions-rust-lang/setup-rust-toolchain@v1
56+
- run: just test msrv
57+
sync:
5958
runs-on: ubuntu-latest
6059
steps:
61-
- uses: actions/checkout@v3
62-
- name: Sync signet
63-
run: cargo test --verbose signet_syncs
64-
bitcoind:
60+
- uses: actions/checkout@v4
61+
- uses: extractions/setup-just@v3
62+
- uses: actions-rust-lang/setup-rust-toolchain@v1
63+
- run: just test sync
64+
integration:
6565
runs-on: ubuntu-latest
6666
steps:
67-
- uses: actions/checkout@v3
68-
- name: Integration test
69-
run: cargo test -- --test-threads 1 --skip signet_syncs --nocapture
67+
- uses: actions/checkout@v4
68+
- uses: extractions/setup-just@v3
69+
- uses: actions-rust-lang/setup-rust-toolchain@v1
70+
- run: just test integration

Cargo.lock

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

Cargo.toml

Lines changed: 3 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]
@@ -69,3 +67,6 @@ path = "example/rescan.rs"
6967
name = "managed"
7068
path = "example/managed.rs"
7169
required-features = ["filter-control"]
70+
71+
[lints.rust]
72+
warnings = "deny"

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<p>
88
<a href="https://crates.io/crates/kyoto-cbf"><img alt="Crate Info" src="https://img.shields.io/crates/v/kyoto-cbf.svg"/></a>
99
<a href="https://github.com/rustaceanrob/kyoto/blob/master/LICENSE"><img alt="MIT or Apache-2.0 Licensed" src="https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg"/></a>
10-
<a href="https://github.com/rustaceanrob/kyoto/actions?query=workflow%3A%22Build+%26+Test%22"><img alt="CI Status" src="https://github.com/rustaceanrob/kyoto/workflows/Build%20%26%20Test/badge.svg"></a>
10+
<a href="https://github.com/rustaceanrob/kyoto/actions?query=workflow%3A%22Build+%26+Test%22"><img alt="CI Status" src="https://github.com/rustaceanrob/kyoto/workflows/CI/badge.svg"></a>
1111
<a href="https://docs.rs/kyoto-cbf"><img alt="API Docs" src="https://img.shields.io/badge/docs.rs-kyoto_cbf-green"/></a>
1212
<a href="https://blog.rust-lang.org/2022/08/11/Rust-1.63.0.html"><img alt="Rustc Version 1.63.0+" src="https://img.shields.io/badge/rustc-1.63.0%2B-lightgrey.svg"/></a>
1313
</p>
@@ -114,7 +114,7 @@ just test
114114
To sync with a live Signet node:
115115

116116
```
117-
just sync
117+
just test sync
118118
```
119119

120120
And to run scenarios against your `bitcoind` instance, set a `BITCOIND_EXE` environment variable to the path to `bitcoind`:
@@ -128,10 +128,10 @@ You may want to add this to your bash or zsh profile.
128128
To run the `bitcoind` tests:
129129

130130
```
131-
just integrate
131+
just test integration`
132132
```
133133

134-
If you do not have `bitcoind` installed, you may simply run `just integrate` and it will be installed for you in the `build` folder.
134+
If you do not have `bitcoind` installed, you may simply run `just test integration` and it will be installed for you in the `build` folder.
135135

136136
## Contributing
137137

justfile

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,53 @@
1-
default:
2-
just --list
3-
4-
build:
5-
cargo build
6-
1+
set ignore-comments
2+
3+
# Hidden default lists all available recipies.
4+
_default:
5+
@just --list --list-heading $'KYOTO\n'
6+
7+
# Quick check of the code including lints and formatting.
78
check:
8-
cargo fmt
9-
cargo clippy --all-targets
9+
cargo fmt -- --check
10+
# Turn warnings into errors.
11+
cargo clippy --all-targets -- -D warnings
12+
cargo check --all-features
13+
14+
# Run a test suite: unit, integration, features, msrv, or sync.
15+
test suite="unit":
16+
just _test-{{suite}}
1017

11-
test:
18+
# Unit test suite.
19+
_test-unit:
1220
cargo test --lib
1321
cargo test --doc
22+
cargo test --examples
1423

15-
sync:
16-
cargo test signet_syncs -- --nocapture
17-
18-
integrate:
19-
cargo test -- --test-threads 1 --nocapture --skip signet_syncs
24+
# Run integration tests, excluding the network sync.
25+
_test-integration:
26+
cargo test --tests -- --test-threads 1 --nocapture --skip signet_syncs
2027

21-
example:
22-
cargo run --example signet --release
23-
24-
signet:
25-
cargo run --example signet --release
26-
27-
testnet:
28-
cargo run --example testnet --release
28+
# Run the network sync integration test.
29+
_test-sync:
30+
cargo test signet_syncs -- --nocapture
2931

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
32+
# Test feature flag matrix compatability.
33+
_test-features:
34+
# Build and test with all features, no features, and some combinations.
35+
cargo test --lib --all-features
36+
cargo test --lib --no-default-features
37+
cargo test --lib --no-default-features --features database,filter-control
38+
39+
# Check code with MSRV compiler.
40+
_test-msrv:
41+
# Generate a lockfile which "fallsback" to the highest dependency
42+
# versions which also work for the MSRV. If none fit the MSRV, then
43+
# the constraints take priority, the MSRV might implicitly be
44+
# raised. So we check the build to see if it introduces any
45+
# code which cannot be compiled with the MSRV.
46+
CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=fallback cargo update --verbose;
47+
# Handles creating sandboxed environments to ensure no newer binaries sneak in.
48+
cargo install cargo-msrv@0.18.4
49+
cargo msrv verify
50+
51+
# Run the example: signet or testnet.
52+
example name="signet":
53+
cargo run --example {{name}} --release

rust-toolchain.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[toolchain]
2+
# >1.84 for stabalized MSRV resolving.
3+
channel = "1.85.0"
4+
profile = "default"

src/chain/chain.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ impl<H: HeaderStore> Chain<H> {
697697
if self.is_filters_synced() {
698698
return Ok(None);
699699
}
700+
#[allow(unused_mut)] // Some trickiness with the filter-control feature
700701
let mut filter = Filter::new(filter_message.filter, filter_message.block_hash);
701702
let expected_filter_hash = self.cf_header_chain.hash_at(&filter_message.block_hash);
702703
// Disallow any filter that we do not have a block hash for

src/db/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[allow(unused_imports)] // Required for some features.
12
use std::fmt::Debug;
23

34
/// Errors when initializing a SQL-based backend.

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)