Skip to content

Commit fcb14de

Browse files
authored
Merge pull request #461 from daira/ci-fixes-from-460
CI and dependency fixes for `no_std`
2 parents 4ac248d + 689df36 commit fcb14de

File tree

4 files changed

+65
-12
lines changed

4 files changed

+65
-12
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ jobs:
3636
- name: Verify working directory is clean (excluding lockfile)
3737
run: git diff --exit-code ':!Cargo.lock'
3838

39-
build-nodefault:
40-
name: Build target ${{ matrix.target }}
39+
build-nostd:
40+
name: Build no_std for target ${{ matrix.target }}
4141
runs-on: ubuntu-latest
4242
strategy:
4343
matrix:
@@ -51,7 +51,7 @@ jobs:
5151
# We use a synthetic crate to ensure no dev-dependencies are enabled, which can
5252
# be incompatible with some of these targets.
5353
- name: Create synthetic crate for testing
54-
run: cargo init --lib ci-build
54+
run: cargo init --edition 2021 --lib ci-build
5555
- name: Copy Rust version into synthetic crate
5656
run: cp crate_root/rust-toolchain.toml ci-build/
5757
- name: Copy patch directives into synthetic crate
@@ -61,16 +61,22 @@ jobs:
6161
- name: Add no_std pragma to lib.rs
6262
run: |
6363
echo "#![no_std]" > ./ci-build/src/lib.rs
64-
- name: Add sapling-crypto as a dependency of the synthetic crate
64+
- name: Add dependencies of the synthetic crate (e.g. sapling-crypto)
6565
working-directory: ./ci-build
6666
run: cargo add --no-default-features --path ../crate_root
6767
- name: Add lazy_static with the spin_no_std feature
6868
working-directory: ./ci-build
69-
run: cargo add lazy_static --features "spin_no_std"
69+
run: cargo add lazy_static --no-default-features --features "spin_no_std"
70+
- name: Add typenum with the no_std feature
71+
working-directory: ./ci-build
72+
run: cargo add typenum --no-default-features --features "no_std"
73+
- name: Show Cargo.toml for the synthetic crate
74+
working-directory: ./ci-build
75+
run: cat Cargo.toml
7076
- name: Add target
7177
working-directory: ./ci-build
7278
run: rustup target add ${{ matrix.target }}
73-
- name: Build for target
79+
- name: Build no_std for target
7480
working-directory: ./ci-build
7581
run: cargo build --verbose --target ${{ matrix.target }}
7682

.github/workflows/lints-stable.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,46 @@ jobs:
1616
token: ${{ secrets.GITHUB_TOKEN }}
1717
working-directory: ${{ inputs.target }}
1818
deny: warnings
19+
20+
clippy-nostd:
21+
name: Clippy (MSRV) no_std for ${{ matrix.target }}
22+
runs-on: ubuntu-latest
23+
strategy:
24+
matrix:
25+
target:
26+
- wasm32-wasi
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
path: crate_root
31+
# We use a synthetic crate to ensure no dev-dependencies are enabled, which can
32+
# be incompatible with some of these targets.
33+
- name: Create synthetic crate for testing
34+
run: cargo init --edition 2021 --lib ci-build
35+
- name: Copy Rust version into synthetic crate
36+
run: cp crate_root/rust-toolchain.toml ci-build/
37+
- name: Copy patch directives into synthetic crate
38+
run: |
39+
echo "[patch.crates-io]" >> ./ci-build/Cargo.toml
40+
cat ./crate_root/Cargo.toml | sed "0,/.\+\(patch.crates.\+\)/d" >> ./ci-build/Cargo.toml
41+
- name: Add no_std pragma to lib.rs
42+
run: |
43+
echo "#![no_std]" > ./ci-build/src/lib.rs
44+
- name: Add dependencies of the synthetic crate (e.g. sapling-crypto)
45+
working-directory: ./ci-build
46+
run: cargo add --no-default-features --path ../crate_root
47+
- name: Add lazy_static with the spin_no_std feature
48+
working-directory: ./ci-build
49+
run: cargo add lazy_static --no-default-features --features "spin_no_std"
50+
- name: Add typenum with the no_std feature
51+
working-directory: ./ci-build
52+
run: cargo add typenum --no-default-features --features "no_std"
53+
- name: Show Cargo.toml for the synthetic crate
54+
working-directory: ./ci-build
55+
run: cat Cargo.toml
56+
- name: Add target
57+
working-directory: ./ci-build
58+
run: rustup target add ${{ matrix.target }}
59+
- name: Clippy no_std for target
60+
working-directory: ./ci-build
61+
run: cargo clippy --verbose --target ${{ matrix.target }}

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ zip32 = { version = "0.2.0", default-features = false }
4848
visibility = "0.1.1"
4949

5050
# Circuit
51-
halo2_gadgets = { version = "0.3", optional = true }
51+
halo2_gadgets = { version = "0.3", optional = true, default-features = false }
5252
halo2_proofs = { version = "0.3", optional = true, default-features = false, features = ["batch", "floor-planner-v1-legacy-pdqsort"] }
5353

5454
# Boilerplate
@@ -87,7 +87,7 @@ circuit = ["dep:halo2_gadgets", "dep:halo2_proofs", "std"]
8787
unstable-frost = []
8888
multicore = ["halo2_proofs?/multicore"]
8989
dev-graph = ["halo2_proofs?/dev-graph", "image", "plotters"]
90-
test-dependencies = ["proptest"]
90+
test-dependencies = ["proptest", "rand/std"]
9191

9292
[[bench]]
9393
name = "note_decryption"

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ Requires Rust 1.66+.
99

1010
## `no_std` compatibility
1111

12-
Downstream users of this crate must enable the `spin_no_std` feature of the
13-
`lazy_static` crate in order to take advantage of `no_std` builds; this is due
14-
to the fact that `--no-default-features` builds of `lazy_static` still rely on
15-
`std`.
12+
In order to take advantage of `no_std` builds, downstream users of this crate
13+
must enable:
14+
15+
* the `spin_no_std` feature of the `lazy_static` crate; and
16+
* the `no_std` feature of the `typenum` crate.
17+
18+
This is needed because the `--no-default-features` builds of these crates still
19+
rely on `std`.
1620

1721
## License
1822

0 commit comments

Comments
 (0)