Skip to content

Commit f40e237

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. With that goal in mind, the CI job has been refactored to a handful of jobs which each call a just recipe. Consistent caching have been added to each job which shows a nice improvement in speed for the job overall. 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 as well. A rust-toolchain.toml file was added to help developers stay on a more 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 f40e237

File tree

10 files changed

+123
-101
lines changed

10 files changed

+123
-101
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
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+
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
42+
features:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: extractions/setup-just@v3
47+
- uses: actions-rust-lang/setup-rust-toolchain@v1
48+
- run: just test-features
3749
msrv:
3850
runs-on: ubuntu-latest
3951
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:
52+
- uses: actions/checkout@v4
53+
- uses: extractions/setup-just@v3
54+
- uses: actions-rust-lang/setup-rust-toolchain@v1
55+
- run: just test-msrv
56+
sync:
5957
runs-on: ubuntu-latest
6058
steps:
61-
- uses: actions/checkout@v3
62-
- name: Sync signet
63-
run: cargo test --verbose signet_syncs
64-
bitcoind:
59+
- uses: actions/checkout@v4
60+
- uses: extractions/setup-just@v3
61+
- uses: actions-rust-lang/setup-rust-toolchain@v1
62+
- run: just test-sync
63+
integration:
6564
runs-on: ubuntu-latest
6665
steps:
67-
- uses: actions/checkout@v3
68-
- name: Integration test
69-
run: cargo test -- --test-threads 1 --skip signet_syncs --nocapture
66+
- uses: actions/checkout@v4
67+
- uses: extractions/setup-just@v3
68+
- uses: actions-rust-lang/setup-rust-toolchain@v1
69+
- run: just test-integration

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: 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: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,52 @@
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+
# Update Cargo.lock with strategy msrv enforcing policy.
8+
@update-lockfile:
9+
# "Fallback" MSRV resolving (v3) requires stable rust > 1.84. Older
10+
# versions have it behind an unstable flag on nightly. Matching the
11+
# stable version in rust-toolchain.toml. This recipe is necessary
12+
# as long as MSRV < 1.84.0 since setting package.resolver to 3 in
13+
# the manifest panics older rust versions.
14+
CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=fallback cargo +1.85.0 update --verbose;
15+
16+
# Quick check of the code including lints and formatting.
717
check:
8-
cargo fmt
9-
cargo clippy --all-targets
18+
cargo fmt -- --check
19+
# Turn warnings into errors.
20+
cargo clippy --all-targets -- -D warnings
21+
cargo check --all-features
1022

23+
# Unit test suite.
1124
test:
1225
cargo test --lib
1326
cargo test --doc
14-
15-
sync:
27+
cargo test --examples
28+
29+
# Test feature flag matrix compatability.
30+
test-features:
31+
# Build and test with all features, no features, and some combinations.
32+
cargo test --lib --all-features
33+
cargo test --lib --no-default-features
34+
cargo test --lib --no-default-features --features database,filter-control
35+
36+
# Check code with MSRV compiler.
37+
test-msrv:
38+
# Handles creating sandboxed environments to ensure no newer binaries sneak in.
39+
cargo install cargo-msrv@0.18.4
40+
cargo msrv verify
41+
42+
# Run the network sync integration test.
43+
test-sync:
1644
cargo test signet_syncs -- --nocapture
1745

18-
integrate:
19-
cargo test -- --test-threads 1 --nocapture --skip signet_syncs
20-
21-
example:
22-
cargo run --example signet --release
46+
# Run integration tests, excluding the network sync.
47+
test-integration:
48+
cargo test --tests -- --test-threads 1 --nocapture --skip signet_syncs
2349

24-
signet:
25-
cargo run --example signet --release
26-
27-
testnet:
28-
cargo run --example testnet --release
29-
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
50+
# Run the example: signet, testnet.
51+
example name="signet":
52+
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

src/messages.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ pub(crate) enum ClientMessage {
145145
/// Broadcast a [`crate::Transaction`] with a [`crate::TxBroadcastPolicy`].
146146
Broadcast(TxBroadcast),
147147
/// Add more Bitcoin [`ScriptBuf`] to look for.
148+
#[allow(dead_code)] // Some trickiness with the filter-control feature
148149
AddScript(ScriptBuf),
149150
/// Starting at the configured anchor checkpoint, look for block inclusions with newly added scripts.
150151
Rescan,

0 commit comments

Comments
 (0)