Skip to content

Commit 4054d80

Browse files
authored
feat: Do not require capnp to be installed to compile hugr-model (#1907)
Now we do the same as with the schema and extensions definition; provide a `just` command to update it manually and check on CI that things are up-to-date. This lets us remove the `build.rs` from `hugr-model`, removing the need for users to have `capnproto` installed to compile our crates. Closes #1667
1 parent 2630e3d commit 4054d80

17 files changed

+4764
-52
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
**/snapshots/*.snap -diff
2+
3+
hugr-model/src/capnp/hugr_*.rs linguist-generated=true

.github/change-filters.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Filters used by [dorny/path-filters](https://github.com/dorny/paths-filter)
22
# to detect changes in each subproject, and only run the corresponding jobs.
33

4+
model: &model
5+
- "hugr-model/**"
6+
47
rust: &rust
58
- "hugr/**"
69
- "hugr-cli/**"
710
- "hugr-core/**"
811
- "hugr-passes/**"
9-
- "hugr-model/**"
12+
- *model
1013
- "Cargo.toml"
1114
- "specification/schema/**"
1215
- ".github/workflows/ci-rs.yml"
@@ -19,6 +22,5 @@ python:
1922
- "specification/schema/**"
2023
- ".github/workflows/ci-py.yml"
2124

22-
2325
llvm:
2426
- "hugr-llvm/**"

.github/workflows/ci-py.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ jobs:
8686
- uses: mozilla-actions/[email protected]
8787
- name: Install stable toolchain
8888
uses: dtolnay/rust-toolchain@stable
89-
- name: Install CapnProto
90-
run: sudo apt-get install -y capnproto
9189
- name: Build HUGR binary
9290
run: cargo build -p hugr-cli
9391
- name: Upload the binary to the artifacts

.github/workflows/ci-rs.yml

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
outputs:
4141
rust: ${{ steps.filter.outputs.rust == 'true' || steps.override.outputs.out == 'true' }}
4242
python: ${{ steps.filter.outputs.python == 'true' || steps.override.outputs.out == 'true' }}
43+
model: ${{ steps.filter.outputs.model == 'true' || steps.override.outputs.out == 'true' }}
4344
llvm: ${{ steps.filter.outputs.llvm == 'true' || steps.override.outputs.out == 'true' }}
4445
steps:
4546
- uses: actions/checkout@v4
@@ -73,8 +74,6 @@ jobs:
7374
uses: dtolnay/rust-toolchain@stable
7475
with:
7576
components: rustfmt, clippy
76-
- name: Install CapnProto
77-
run: sudo apt-get install -y capnproto
7877
- name: Check formatting
7978
run: cargo fmt -- --check
8079
- name: Install LLVM and Clang
@@ -98,8 +97,6 @@ jobs:
9897
- uses: mozilla-actions/[email protected]
9998
- name: Install stable toolchain
10099
uses: dtolnay/rust-toolchain@stable
101-
- name: Install CapnProto
102-
run: sudo apt-get install -y capnproto
103100
- name: Install LLVM and Clang
104101
uses: KyleMayes/install-llvm-action@v2
105102
with:
@@ -125,8 +122,6 @@ jobs:
125122
- name: Configure default rust toolchain
126123
run: rustup override set ${{steps.toolchain.outputs.name}}
127124

128-
- name: Install CapnProto
129-
run: sudo apt-get install -y capnproto
130125
- name: Install LLVM and Clang
131126
uses: KyleMayes/install-llvm-action@v2
132127
with:
@@ -153,8 +148,6 @@ jobs:
153148
- name: Configure default rust toolchain
154149
run: rustup override set ${{steps.toolchain.outputs.name}}
155150

156-
- name: Install CapnProto
157-
run: sudo apt-get install -y capnproto
158151
- name: Install LLVM and Clang
159152
uses: KyleMayes/install-llvm-action@v2
160153
with:
@@ -198,8 +191,6 @@ jobs:
198191
toolchain: ${{ matrix.rust }}
199192
- name: Configure default rust toolchain
200193
run: rustup override set ${{steps.toolchain.outputs.name}}
201-
- name: Install CapnProto
202-
run: sudo apt-get install -y capnproto
203194
- name: Install LLVM and Clang
204195
uses: KyleMayes/install-llvm-action@v2
205196
with:
@@ -239,6 +230,38 @@ jobs:
239230
exit 1
240231
fi
241232
233+
# Ensure that the generated capnp implementation in `hugr-model` is up to date
234+
model-capnp:
235+
needs: [changes]
236+
if: ${{ needs.changes.outputs.model == 'true' && github.event_name != 'merge_group' }}
237+
name: Keep hugr-model capnp schema updated
238+
runs-on: ubuntu-latest
239+
steps:
240+
- uses: actions/checkout@v4
241+
- uses: mozilla-actions/[email protected]
242+
- name: Install stable toolchain
243+
uses: dtolnay/rust-toolchain@stable
244+
- name: Install CapnProto
245+
run: sudo apt-get install -y capnproto
246+
- name: Get cargo binstall
247+
uses: cargo-bins/cargo-binstall@main
248+
- name: Install capnproto-rust plugin
249+
run: cargo binstall capnpc
250+
- name: Regenerate the capnp code
251+
run: |
252+
capnp compile \
253+
-orust:hugr-model/src \
254+
--src-prefix=hugr-model \
255+
hugr-model/capnp/hugr-v0.capnp
256+
- name: Check if the generated capnproto code is up to date
257+
run: |
258+
git diff --exit-code --name-only hugr-model/capnp/
259+
if [ $? -ne 0 ]; then
260+
echo "The capnp generated code is not up to date"
261+
echo "Please run 'just update-model-capnp' and commit the changes"
262+
exit 1
263+
fi
264+
242265
tests-nightly-coverage:
243266
needs: changes
244267
# Run only if there are changes in the relevant files
@@ -253,8 +276,6 @@ jobs:
253276
# Nightly is required to count doctests coverage
254277
toolchain: "nightly"
255278
components: llvm-tools-preview
256-
- name: Install CapnProto
257-
run: sudo apt-get install -y capnproto
258279
- name: Install LLVM and Clang
259280
uses: KyleMayes/install-llvm-action@v2
260281
with:

.github/workflows/release-plz.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ jobs:
2424

2525
# These are needed when doing a crate release, since `cargo release`
2626
# checks that the crate can be compiled before publishing it.
27-
- name: Install CapnProto
28-
run: sudo apt-get install -y capnproto
2927
- name: Install LLVM and Clang
3028
uses: KyleMayes/install-llvm-action@v2
3129
with:

.github/workflows/semver-checks.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,5 @@ jobs:
4343
needs: [changes]
4444
if: ${{ needs.changes.outputs.rust == 'true' }}
4545
uses: CQCL/hugrverse-actions/.github/workflows/rs-semver-checks.yml@main
46-
with:
47-
apt-dependencies: llvm-14 capnproto
4846
secrets:
4947
GITHUB_PAT: ${{ secrets.HUGRBOT_PAT }}

.github/workflows/unsoundness.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ jobs:
3434
- uses: Swatinem/rust-cache@v2
3535
with:
3636
prefix-key: v0-miri
37-
- name: Install CapnProto
38-
run: sudo apt-get install -y capnproto
3937
- name: Test with Miri
4038
run: cargo miri test
4139

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ debug_assert_with_mut_call = "warn"
3434
portgraph = { version = "0.13.0" }
3535
insta = { version = "1.34.0" }
3636
bitvec = "1.0.1"
37+
capnp = "0.20.1"
3738
cgmath = "0.18.0"
3839
cool_asserts = "2.0.3"
3940
criterion = "0.5.1"
@@ -72,6 +73,11 @@ fxhash = "0.2.1"
7273
bumpalo = { version = "3.16.0" }
7374
pathsearch = "0.2.0"
7475
base64 = "0.22.1"
76+
ordered-float = "4.6.0"
77+
pest = "2.7.12"
78+
pest_derive = "2.7.12"
79+
pretty = "0.12.3"
80+
pretty_assertions = "1.4.1"
7581

7682
[profile.dev.package]
7783
insta.opt-level = 3

DEVELOPMENT.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ To setup the environment manually you will need:
3131
- Just: https://just.systems/
3232
- Rust `>=1.75`: https://www.rust-lang.org/tools/install
3333
- uv `>=0.3`: docs.astral.sh/uv/getting-started/installation
34-
- capnproto `>=1.0`: https://capnproto.org/install.html
34+
- Optional: capnproto `>=1.0`: https://capnproto.org/install.html
35+
Required when modifying the `hugr-model` serialization schema.
3536
- Optional: llvm `== 14.0`. The "llvm" feature (backed by the sub-crate `hugr-llvm`)
3637
requires LLVM installed. We use the rust bindings
3738
[llvm-sys](https://crates.io/crates/llvm-sys) to [llvm](https://llvm.org/).

hugr-model/Cargo.toml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,20 @@ bench = false
1818
[dependencies]
1919
base64 = { workspace = true }
2020
bumpalo = { workspace = true, features = ["collections"] }
21-
capnp = "0.20.1"
22-
derive_more = { version = "1.0.0", features = ["display"] }
21+
capnp = { workspace = true }
22+
derive_more = { workspace = true, features = ["display"] }
2323
fxhash.workspace = true
2424
indexmap.workspace = true
25-
ordered-float = "4.6.0"
26-
pest = "2.7.12"
27-
pest_derive = "2.7.12"
28-
pretty = "0.12.3"
25+
ordered-float = { workspace = true }
26+
pest = { workspace = true }
27+
pest_derive = { workspace = true }
28+
pretty = { workspace = true }
2929
smol_str = { workspace = true, features = ["serde"] }
3030
thiserror.workspace = true
3131

3232
[lints]
3333
workspace = true
3434

35-
[build-dependencies]
36-
capnpc = "0.20.0"
37-
3835
[dev-dependencies]
39-
insta.workspace = true
40-
pretty_assertions = "1.4.1"
36+
insta = { workspace = true }
37+
pretty_assertions = { workspace = true }

hugr-model/build.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)