Skip to content

Commit 23037f5

Browse files
committed
chore: migrate wasm crates to workspace
1 parent c67bd39 commit 23037f5

File tree

24 files changed

+361
-6192
lines changed

24 files changed

+361
-6192
lines changed

.cz.yaml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@ commitizen:
55
update_changelog_on_bump: true
66
version: 1.2.0
77
version_files:
8+
- Cargo.toml
89
- packages/certificate-verification-js/package.json:version
9-
- packages/ic-cbor/Cargo.toml:version
10-
- packages/ic-certificate-verification/Cargo.toml:version
11-
- packages/ic-certification/Cargo.toml:version
12-
- packages/ic-certification-testing/Cargo.toml:version
13-
- packages/ic-certification-testing-wasm/Cargo.toml:version
1410
- packages/ic-certification-testing-wasm/package.json:version
15-
- packages/ic-representation-independent-hash/Cargo.toml:version
16-
- packages/ic-response-verification/Cargo.toml:version
17-
- packages/ic-response-verification-test-utils/Cargo.toml:version
18-
- packages/ic-response-verification-tests/Cargo.toml:version
1911
- packages/ic-response-verification-tests/package.json:version
2012
- packages/ic-response-verification-wasm/package.json:version
21-
- packages/ic-response-verification-wasm/Cargo.toml:version

.github/workflows/create-release-pr.yml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,9 @@ jobs:
6363
add-paths: |
6464
.cz.yaml
6565
CHANGELOG.md
66+
Cargo.toml
6667
Cargo.lock
6768
packages/certificate-verification-js/package.json
68-
packages/ic-cbor/Cargo.toml
69-
packages/ic-certificate-verification/Cargo.toml
70-
packages/ic-certification/Cargo.toml
71-
packages/ic-certification-testing/Cargo.toml
72-
packages/ic-certification-testing-wasm/Cargo.lock
73-
packages/ic-certification-testing-wasm/Cargo.toml
7469
packages/ic-certification-testing-wasm/package.json
75-
packages/ic-representation-independent-hash/Cargo.toml
76-
packages/ic-response-verification/Cargo.toml
77-
packages/ic-response-verification-test-utils/Cargo.toml
78-
packages/ic-response-verification-tests/Cargo.toml
7970
packages/ic-response-verification-tests/package.json
80-
packages/ic-response-verification-wasm/Cargo.lock
81-
packages/ic-response-verification-wasm/Cargo.toml
8271
packages/ic-response-verification-wasm/package.json

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
2929

3030
- name: Build Cargo crates
31-
run: cargo build --release --workspace --exclude certified_counter_backend
31+
run: cargo build --release
3232

3333
- name: DFX prepare Certified Counter
3434
working-directory: examples/certified-counter

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rust-analyzer.cargo.extraEnv": {
3+
"CARGO_PROFILE_RUST_ANALYZER_INHERITS": "dev"
4+
},
5+
"rust-analyzer.cargo.extraArgs": ["--profile", "rust-analyzer"]
6+
}

Cargo.lock

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

Cargo.toml

Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,109 @@ members = [
1010
"packages/ic-response-verification",
1111
"packages/ic-response-verification-test-utils",
1212
"packages/ic-response-verification-tests",
13+
"packages/ic-response-verification-wasm",
14+
"packages/ic-certification-testing-wasm",
1315
]
1416

1517
# https://github.com/rust-lang/cargo/issues/9406
16-
# these projects need wasm32-unknown-unknown as their target
17-
exclude = [
18-
"packages/ic-response-verification-wasm",
19-
"packages/ic-certification-testing-wasm",
18+
# includes all members except those that must be compiled to WASM
19+
default-members = [
20+
"examples/rust",
21+
"packages/ic-cbor",
22+
"packages/ic-certification",
23+
"packages/ic-certificate-verification",
24+
"packages/ic-certification-testing",
25+
"packages/ic-representation-independent-hash",
26+
"packages/ic-response-verification",
27+
"packages/ic-response-verification-test-utils",
28+
"packages/ic-response-verification-tests",
2029
]
2130

31+
[workspace.package]
32+
version = "1.2.0"
33+
authors = ["DFINITY Stiftung"]
34+
edition = "2021"
35+
repository = "https://github.com/dfinity/response-verification"
36+
homepage = "https://github.com/dfinity/response-verification#readme"
37+
license = "Apache-2.0"
38+
39+
[workspace.dependencies]
40+
nom = "7.1"
41+
leb128 = "0.2"
42+
log = "0.4"
43+
hex = "0.4"
44+
base64 = "0.21"
45+
http = "0.2"
46+
flate2 = "1.0"
47+
sha2 = "0.10"
48+
urlencoding = "2.1.3"
49+
rstest = "0.18"
50+
tokio = { version = "1.24", features = ["full"] }
51+
52+
serde_bytes = "0.11"
53+
serde_cbor = "0.11"
54+
55+
thiserror = "1.0"
56+
anyhow = "1.0"
57+
58+
candid = "0.9"
59+
ic-agent = "0.29"
60+
ic-utils = "0.29"
61+
ic-cdk = "0.6.0"
62+
ic-cdk-macros = "0.6.0"
63+
64+
wasm-bindgen = "0.2"
65+
wasm-bindgen-test = "0.3"
66+
serde-wasm-bindgen = "0.5"
67+
js-sys = "0.3"
68+
console_error_panic_hook = "0.1"
69+
wasm-bindgen-console-logger = "0.1"
70+
# https://github.com/rust-random/rand#wasm-support
71+
# https://docs.rs/getrandom/latest/getrandom/#webassembly-support
72+
rand = "0.8"
73+
getrandom = { version = "0.2", features = ["js"] }
74+
75+
76+
ic-certification = { path = "./packages/ic-certification", default-features = false, version = "1.2.0" }
77+
ic-certification-testing = { path = "./packages/ic-certification-testing" }
78+
ic-representation-independent-hash = { path = "./packages/ic-representation-independent-hash", version = "1.2.0" }
79+
ic-certificate-verification = { path = "./packages/ic-certificate-verification", version = "1.2.0" }
80+
ic-response-verification = { path = "./packages/ic-response-verification", version = "1.2.0" }
81+
ic-response-verification-test-utils = { path = "./packages/ic-response-verification-test-utils" }
82+
ic-cbor = { path = "./packages/ic-cbor", version = "1.2.0" }
83+
84+
85+
[workspace.dependencies.ic-types]
86+
git = "https://github.com/dfinity/ic"
87+
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"
88+
89+
[workspace.dependencies.ic-crypto-tree-hash]
90+
git = "https://github.com/dfinity/ic"
91+
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"
92+
93+
[workspace.dependencies.ic-crypto-internal-threshold-sig-bls12381]
94+
git = "https://github.com/dfinity/ic"
95+
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"
96+
97+
[workspace.dependencies.ic-crypto-internal-seed]
98+
git = "https://github.com/dfinity/ic"
99+
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"
100+
101+
[workspace.dependencies.ic-crypto-internal-types]
102+
git = "https://github.com/dfinity/ic"
103+
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"
104+
105+
106+
[workspace.dependencies.serde]
107+
version = "1.0"
108+
features = ["derive"]
109+
110+
[workspace.dependencies.miracl_core_bls12381]
111+
version = "4.2"
112+
default_features = false
113+
features = ["std", "allow_alt_compress"]
114+
115+
22116
[profile.release]
23117
lto = true
24118
opt-level = 'z'

README.md

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,20 @@ Install and activate the correct version of PNPM:
120120
corepack enable
121121
```
122122

123+
### Working on WASM crates
124+
125+
Until Cargo supports [per package targets](https://github.com/rust-lang/cargo/issues/9406), the WASM crates are excluded from the `default_members` array of the Cargo workspace.
126+
Commands such as `cargo build` and `cargo check` will not include these crates, so they must be built separately with the corresponding `pnpm` command listed under [projects](#projects).
127+
128+
Since `rust-analyzer` will also apply the same target to all crates, these crates will show errors in the IDE. To workaround this, create a `.cargo/config.toml` file:
129+
130+
```toml
131+
[build]
132+
target = "wasm32-unknown-unknown"
133+
```
134+
135+
While this file exists, some of the non-WASM crates will show errors instead. Delete the file to work on the non-WASM crates.
136+
123137
### Making a Commit
124138

125139
```shell
@@ -134,24 +148,26 @@ See [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) for m
134148
- Add the package's package manager file to the `version_files` field in `.cz.yaml`.
135149
- `package.json` for NPM packages
136150
- `Cargo.toml` for Cargo crates
137-
- Set the initial version of the package in its package manager file to match the current version in the `version` field in `.cz.yaml`.
138-
- Add the package's package manager file(s) to the `add-paths` property in the `Create Pull Request` job of the `Create Release PR` workflow in `.github/workflows/create-release-pr.yml`.
151+
- Set the initial version of the package in its package manager file to match the current version in the `version` field in `.cz.yaml`
152+
- For `package.json`, set the version manually
153+
- For `Cargo.toml`, use `version.workspace = true`
154+
- Add the package's package manager file(s) to the `add-paths` property in the `Create Pull Request` job of the `Create Release PR` workflow in `.github/workflows/create-release-pr.yml`
139155
- `package.json` for NPM packages
140-
- `Cargo.toml` and `Cargo.lock` for Cargo crates that are compiled to WASM (they are excluded from the root workspace), non-WASM Cargo crates (they are part of the root workspace) only need `Cargo.toml`
156+
- No files need to be added for Cargo crates
141157
- If the package is a Rust crate:
142-
- Add the package to the `members` section in `Cargo.toml`.
143-
- If the package must be compiled to WASM then add it to the `exclude` section instead.
144-
- Add a `Release ic-<package-name> Cargo crate` job to the `Release` workflow in `.github/workflows/release.yml`.
145-
- Add `target/package/ic-<package-name>-${{ github.ref_name }}.crate` to the `artifacts` property in the `Create Github release` job of the `Create Release PR` workflow in `.github/workflows/create-release-pr.yml`.
146-
- Make sure every entry except the last is comma delimited.
147-
- If the crate has dependenencies in this repository, make sure it is published _after_ the dependencies.
148-
- If the crate has dependent in this repository, make sure it is published _before_ the dependents.
158+
- Add the package to the `members` section in `Cargo.toml` and the `default-members` section
159+
- If the package must be compiled to WASM then do not add it to the `default-members` section
160+
- Add a `Release ic-<package-name> Cargo crate` job to the `Release` workflow in `.github/workflows/release.yml`
161+
- Add `target/package/ic-<package-name>-${{ github.ref_name }}.crate` to the `artifacts` property in the `Create Github release` job of the `Create Release PR` workflow in `.github/workflows/create-release-pr.yml`
162+
- Make sure every entry except the last is comma delimited
163+
- If the crate has dependenencies in this repository, make sure it is published _after_ the dependencies
164+
- If the crate has a dependent in this repository, make sure it is published _before_ the dependents
149165
- If the package is an NPM package:
150-
- Add the package to `pnpm-workspace.yaml`.
151-
- Add a `Pack @dfinity/<package-name> NPM package` job to the `Release` workflow in `.github/workflows/release.yml`.
152-
- Add a `Release @dfinity/<package-name> NPM package` job to the `Release` workflow in `.github/workflows/release.yml`.
153-
- Add `dfinity-<package-name>-${{ github.ref_name }}.tgz` to the `artifacts` property in the `Create Github release` job of the `Create Release PR` workflow in `.github/workflows/create-release-pr.yml`.
154-
- Make sure every entry except the last is comma delimited.
166+
- Add the package to `pnpm-workspace.yaml`
167+
- Add a `Pack @dfinity/<package-name> NPM package` job to the `Release` workflow in `.github/workflows/release.yml`
168+
- Add a `Release @dfinity/<package-name> NPM package` job to the `Release` workflow in `.github/workflows/release.yml`
169+
- Add `dfinity-<package-name>-${{ github.ref_name }}.tgz` to the `artifacts` property in the `Create Github release` job of the `Create Release PR` workflow in `.github/workflows/create-release-pr.yml`
170+
- Make sure every entry except the last is comma delimited
155171

156172
### Package naming conventions
157173

examples/certified-counter/src/backend/Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ edition = "2021"
77
crate-type = ["cdylib"]
88

99
[dependencies]
10-
anyhow = "1.0.71"
11-
candid = "0.8.2"
12-
ic-cdk = "0.6.0"
13-
ic-cdk-macros = "0.6.0"
14-
ic-certification = { path = "../../../../packages/ic-certification" }
15-
serde = "1.0.164"
16-
serde_cbor = "0.11.2"
17-
sha2 = "0.10"
10+
anyhow.workspace = true
11+
candid.workspace = true
12+
ic-cdk.workspace = true
13+
ic-cdk-macros.workspace = true
14+
ic-certification.workspace = true
15+
serde.workspace = true
16+
serde_cbor.workspace = true
17+
sha2.workspace = true

0 commit comments

Comments
 (0)