Skip to content

Commit

Permalink
chore: migrate wasm crates to workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanosdev committed Nov 16, 2023
1 parent 2b4e67b commit bb9c58c
Show file tree
Hide file tree
Showing 24 changed files with 360 additions and 6,191 deletions.
11 changes: 1 addition & 10 deletions .cz.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,8 @@ commitizen:
update_changelog_on_bump: true
version: 1.2.0
version_files:
- Cargo.toml
- packages/certificate-verification-js/package.json:version
- packages/ic-cbor/Cargo.toml:version
- packages/ic-certificate-verification/Cargo.toml:version
- packages/ic-certification/Cargo.toml:version
- packages/ic-certification-testing/Cargo.toml:version
- packages/ic-certification-testing-wasm/Cargo.toml:version
- packages/ic-certification-testing-wasm/package.json:version
- packages/ic-representation-independent-hash/Cargo.toml:version
- packages/ic-response-verification/Cargo.toml:version
- packages/ic-response-verification-test-utils/Cargo.toml:version
- packages/ic-response-verification-tests/Cargo.toml:version
- packages/ic-response-verification-tests/package.json:version
- packages/ic-response-verification-wasm/package.json:version
- packages/ic-response-verification-wasm/Cargo.toml:version
13 changes: 1 addition & 12 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,9 @@ jobs:
add-paths: |
.cz.yaml
CHANGELOG.md
Cargo.toml
Cargo.lock
packages/certificate-verification-js/package.json
packages/ic-cbor/Cargo.toml
packages/ic-certificate-verification/Cargo.toml
packages/ic-certification/Cargo.toml
packages/ic-certification-testing/Cargo.toml
packages/ic-certification-testing-wasm/Cargo.lock
packages/ic-certification-testing-wasm/Cargo.toml
packages/ic-certification-testing-wasm/package.json
packages/ic-representation-independent-hash/Cargo.toml
packages/ic-response-verification/Cargo.toml
packages/ic-response-verification-test-utils/Cargo.toml
packages/ic-response-verification-tests/Cargo.toml
packages/ic-response-verification-tests/package.json
packages/ic-response-verification-wasm/Cargo.lock
packages/ic-response-verification-wasm/Cargo.toml
packages/ic-response-verification-wasm/package.json
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh

- name: Build Cargo crates
run: cargo build --release --workspace --exclude certified_counter_backend
run: cargo build --release

- name: DFX prepare Certified Counter
working-directory: examples/certified-counter
Expand Down
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rust-analyzer.cargo.extraEnv": {
"CARGO_PROFILE_RUST_ANALYZER_INHERITS": "dev"
},
"rust-analyzer.cargo.extraArgs": ["--profile", "rust-analyzer"]
}
32 changes: 30 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 98 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,109 @@ members = [
"packages/ic-response-verification",
"packages/ic-response-verification-test-utils",
"packages/ic-response-verification-tests",
"packages/ic-response-verification-wasm",
"packages/ic-certification-testing-wasm",
]

# https://github.com/rust-lang/cargo/issues/9406
# these projects need wasm32-unknown-unknown as their target
exclude = [
"packages/ic-response-verification-wasm",
"packages/ic-certification-testing-wasm",
# includes all members except those that must be compiled to WASM
default-members = [
"examples/rust",
"packages/ic-cbor",
"packages/ic-certification",
"packages/ic-certificate-verification",
"packages/ic-certification-testing",
"packages/ic-representation-independent-hash",
"packages/ic-response-verification",
"packages/ic-response-verification-test-utils",
"packages/ic-response-verification-tests",
]

[workspace.package]
version = "1.2.0"
authors = ["DFINITY Stiftung"]
edition = "2021"
repository = "https://github.com/dfinity/response-verification"
homepage = "https://github.com/dfinity/response-verification#readme"
license = "Apache-2.0"

[workspace.dependencies]
nom = "7.1"
leb128 = "0.2"
log = "0.4"
hex = "0.4"
base64 = "0.21"
http = "0.2"
flate2 = "1.0"
sha2 = "0.10"
urlencoding = "2.1.3"
rstest = "0.18"
tokio = { version = "1.24", features = ["full"] }

serde_bytes = "0.11"
serde_cbor = "0.11"

thiserror = "1.0"
anyhow = "1.0"

candid = "0.9"
ic-agent = "0.29"
ic-utils = "0.29"
ic-cdk = "0.6.0"
ic-cdk-macros = "0.6.0"

wasm-bindgen = "0.2"
wasm-bindgen-test = "0.3"
serde-wasm-bindgen = "0.5"
js-sys = "0.3"
console_error_panic_hook = "0.1"
wasm-bindgen-console-logger = "0.1"
# https://github.com/rust-random/rand#wasm-support
# https://docs.rs/getrandom/latest/getrandom/#webassembly-support
rand = "0.8"
getrandom = { version = "0.2", features = ["js"] }


ic-certification = { path = "./packages/ic-certification", default-features = false }
ic-certification-testing = { path = "./packages/ic-certification-testing" }
ic-representation-independent-hash = { path = "./packages/ic-representation-independent-hash" }
ic-certificate-verification = { path = "./packages/ic-certificate-verification" }
ic-response-verification = { path = "./packages/ic-response-verification" }
ic-response-verification-test-utils = { path = "./packages/ic-response-verification-test-utils" }
ic-cbor = { path = "./packages/ic-cbor" }


[workspace.dependencies.ic-types]
git = "https://github.com/dfinity/ic"
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"

[workspace.dependencies.ic-crypto-tree-hash]
git = "https://github.com/dfinity/ic"
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"

[workspace.dependencies.ic-crypto-internal-threshold-sig-bls12381]
git = "https://github.com/dfinity/ic"
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"

[workspace.dependencies.ic-crypto-internal-seed]
git = "https://github.com/dfinity/ic"
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"

[workspace.dependencies.ic-crypto-internal-types]
git = "https://github.com/dfinity/ic"
rev = "6e3bb8100e7724a8ec53dac26faa3426378a6953"


[workspace.dependencies.serde]
version = "1.0"
features = ["derive"]

[workspace.dependencies.miracl_core_bls12381]
version = "4.2"
default_features = false
features = ["std", "allow_alt_compress"]


[profile.release]
lto = true
opt-level = 'z'
Expand Down
46 changes: 31 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ Install and activate the correct version of PNPM:
corepack enable
```

### Working on WASM crates

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.
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).

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:

```toml
[build]
target = "wasm32-unknown-unknown"
```

While this file exists, some of the non-WASM crates will show errors instead. Delete the file to work on the non-WASM crates.

### Making a Commit

```shell
Expand All @@ -134,24 +148,26 @@ See [Conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) for m
- Add the package's package manager file to the `version_files` field in `.cz.yaml`.
- `package.json` for NPM packages
- `Cargo.toml` for Cargo crates
- Set the initial version of the package in its package manager file to match the current version in the `version` field in `.cz.yaml`.
- 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`.
- Set the initial version of the package in its package manager file to match the current version in the `version` field in `.cz.yaml`
- For `package.json`, set the version manually
- For `Cargo.toml`, use `version.workspace = true`
- 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`
- `package.json` for NPM packages
- `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`
- No files need to be added for Cargo crates
- If the package is a Rust crate:
- Add the package to the `members` section in `Cargo.toml`.
- If the package must be compiled to WASM then add it to the `exclude` section instead.
- Add a `Release ic-<package-name> Cargo crate` job to the `Release` workflow in `.github/workflows/release.yml`.
- 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`.
- Make sure every entry except the last is comma delimited.
- If the crate has dependenencies in this repository, make sure it is published _after_ the dependencies.
- If the crate has dependent in this repository, make sure it is published _before_ the dependents.
- Add the package to the `members` section in `Cargo.toml` and the `default-members` section
- If the package must be compiled to WASM then do not add it to the `default-members` section
- Add a `Release ic-<package-name> Cargo crate` job to the `Release` workflow in `.github/workflows/release.yml`
- 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`
- Make sure every entry except the last is comma delimited
- If the crate has dependenencies in this repository, make sure it is published _after_ the dependencies
- If the crate has a dependent in this repository, make sure it is published _before_ the dependents
- If the package is an NPM package:
- Add the package to `pnpm-workspace.yaml`.
- Add a `Pack @dfinity/<package-name> NPM package` job to the `Release` workflow in `.github/workflows/release.yml`.
- Add a `Release @dfinity/<package-name> NPM package` job to the `Release` workflow in `.github/workflows/release.yml`.
- 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`.
- Make sure every entry except the last is comma delimited.
- Add the package to `pnpm-workspace.yaml`
- Add a `Pack @dfinity/<package-name> NPM package` job to the `Release` workflow in `.github/workflows/release.yml`
- Add a `Release @dfinity/<package-name> NPM package` job to the `Release` workflow in `.github/workflows/release.yml`
- 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`
- Make sure every entry except the last is comma delimited

### Package naming conventions

Expand Down
16 changes: 8 additions & 8 deletions examples/certified-counter/src/backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
anyhow = "1.0.71"
candid = "0.8.2"
ic-cdk = "0.6.0"
ic-cdk-macros = "0.6.0"
ic-certification = { path = "../../../../packages/ic-certification" }
serde = "1.0.164"
serde_cbor = "0.11.2"
sha2 = "0.10"
anyhow.workspace = true
candid.workspace = true
ic-cdk.workspace = true
ic-cdk-macros.workspace = true
ic-certification.workspace = true
serde.workspace = true
serde_cbor.workspace = true
sha2.workspace = true
Loading

0 comments on commit bb9c58c

Please sign in to comment.