From dc8802837fac8dd4d2e0e1a29058285a13c59b06 Mon Sep 17 00:00:00 2001 From: mraszyk <31483726+mraszyk@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:05:28 +0200 Subject: [PATCH] chore(PocketIC): PocketIC library build on Windows (#2094) This PR adds a GitHub CI flow for PocketIC library build on Windows. --- .github/workflows/pocket-ic-build-windows.yml | 27 ++++++++++++++++++ Cargo.lock | 10 +++++++ Cargo.toml | 1 + packages/pocket-ic/BUILD.bazel | 28 ++----------------- packages/pocket-ic/test_canister/BUILD.bazel | 14 ++++++++++ packages/pocket-ic/test_canister/Cargo.toml | 17 +++++++++++ .../canister.did} | 0 .../src/canister.rs} | 0 8 files changed, 72 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/pocket-ic-build-windows.yml create mode 100644 packages/pocket-ic/test_canister/BUILD.bazel create mode 100644 packages/pocket-ic/test_canister/Cargo.toml rename packages/pocket-ic/{tests/test_canister.did => test_canister/canister.did} (100%) rename packages/pocket-ic/{tests/test_canister.rs => test_canister/src/canister.rs} (100%) diff --git a/.github/workflows/pocket-ic-build-windows.yml b/.github/workflows/pocket-ic-build-windows.yml new file mode 100644 index 00000000000..7782e939029 --- /dev/null +++ b/.github/workflows/pocket-ic-build-windows.yml @@ -0,0 +1,27 @@ +name: 'PocketIC library build on Windows' +on: + pull_request: + paths: + - packages/pocket-ic/** + push: + branches: + - master +# runs for the same workflow are cancelled on PRs but not on master +# explanation: on push to master head_ref is not set, so we want it to fall back to run_id so it is not cancelled +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true +jobs: + pocket_ic_library_build_windows: + name: 'PocketIC library build on Windows' + runs-on: windows-2022 + steps: + - name: 'Checkout' + uses: actions/checkout@v4 + - name: 'cargo clippy' + run: | + cargo clippy --locked --all-features -p pocket-ic -p pocket-ic-test-canister --all-targets -- -D warnings -D clippy::all -D clippy::mem_forget -C debug-assertions=off + - name: 'cargo build' + run: | + cargo build --release --locked -p pocket-ic + cargo build --release --locked -p pocket-ic-test-canister --target wasm32-unknown-unknown diff --git a/Cargo.lock b/Cargo.lock index 02a2c453911..b1359c9f36f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16731,6 +16731,16 @@ dependencies = [ "wat", ] +[[package]] +name = "pocket-ic-test-canister" +version = "0.9.0" +dependencies = [ + "candid", + "ic-cdk 0.16.0", + "serde", + "serde_bytes", +] + [[package]] name = "polling" version = "3.7.3" diff --git a/Cargo.toml b/Cargo.toml index 913b8787de9..d3b641b1724 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "packages/ic-ledger-hash-of", "packages/ic-signature-verification", "packages/pocket-ic", + "packages/pocket-ic/test_canister", "packages/ic-vetkd-utils", "rs/artifact_pool", "rs/async_utils", diff --git a/packages/pocket-ic/BUILD.bazel b/packages/pocket-ic/BUILD.bazel index 43446b4c325..975cca6723e 100644 --- a/packages/pocket-ic/BUILD.bazel +++ b/packages/pocket-ic/BUILD.bazel @@ -1,5 +1,4 @@ -load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test", "rust_test_suite") -load("//bazel:canisters.bzl", "rust_canister") +load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test_suite") package(default_visibility = ["//visibility:public"]) @@ -46,38 +45,17 @@ rust_library( deps = DEPENDENCIES, ) -rust_canister( - name = "test_canister", - srcs = ["tests/test_canister.rs"], - service_file = ":tests/test_canister.did", - deps = [ - # Keep sorted. - "@crate_index//:candid", - "@crate_index//:ic-cdk", - "@crate_index//:serde", - "@crate_index//:serde_bytes", - ], -) - -rust_test( - name = "test_canister_unit_test", - crate = ":_wasm_test_canister", - data = ["tests/test_canister.did"], - env = {"CARGO_MANIFEST_DIR": "packages/pocket-ic"}, - deps = [":pocket-ic"] + DEPENDENCIES + TEST_DEPENDENCIES, -) - rust_test_suite( name = "test", size = "medium", srcs = ["tests/tests.rs"], data = [ - ":test_canister.wasm", + "//packages/pocket-ic/test_canister:test_canister.wasm", "//rs/pocket_ic_server:pocket-ic-server", ], env = { "POCKET_IC_BIN": "$(rootpath //rs/pocket_ic_server:pocket-ic-server)", - "TEST_WASM": "$(rootpath :test_canister.wasm)", + "TEST_WASM": "$(rootpath //packages/pocket-ic/test_canister:test_canister.wasm)", }, flaky = False, proc_macro_deps = MACRO_DEPENDENCIES, diff --git a/packages/pocket-ic/test_canister/BUILD.bazel b/packages/pocket-ic/test_canister/BUILD.bazel new file mode 100644 index 00000000000..65f2948ca59 --- /dev/null +++ b/packages/pocket-ic/test_canister/BUILD.bazel @@ -0,0 +1,14 @@ +load("//bazel:canisters.bzl", "rust_canister") + +rust_canister( + name = "test_canister", + srcs = ["src/canister.rs"], + service_file = ":canister.did", + deps = [ + # Keep sorted. + "@crate_index//:candid", + "@crate_index//:ic-cdk", + "@crate_index//:serde", + "@crate_index//:serde_bytes", + ], +) diff --git a/packages/pocket-ic/test_canister/Cargo.toml b/packages/pocket-ic/test_canister/Cargo.toml new file mode 100644 index 00000000000..2a2550e3f27 --- /dev/null +++ b/packages/pocket-ic/test_canister/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "pocket-ic-test-canister" +version.workspace = true +authors.workspace = true +edition.workspace = true +description.workspace = true +documentation.workspace = true + +[[bin]] +name = "pocket-ic-test-canister" +path = "src/canister.rs" + +[dependencies] +candid = { workspace = true } +ic-cdk = { workspace = true } +serde = { workspace = true } +serde_bytes = { workspace = true } diff --git a/packages/pocket-ic/tests/test_canister.did b/packages/pocket-ic/test_canister/canister.did similarity index 100% rename from packages/pocket-ic/tests/test_canister.did rename to packages/pocket-ic/test_canister/canister.did diff --git a/packages/pocket-ic/tests/test_canister.rs b/packages/pocket-ic/test_canister/src/canister.rs similarity index 100% rename from packages/pocket-ic/tests/test_canister.rs rename to packages/pocket-ic/test_canister/src/canister.rs