From d90e934eb440c730d44d9d9b1ece2cc3f9505d05 Mon Sep 17 00:00:00 2001 From: Paul Liu Date: Wed, 15 Jan 2025 17:38:57 +0800 Subject: [PATCH] fix: cargo build registry-canister for wasm32 target (#3408) The following command currently failed to compile the registry canister if running from the /ic/rs/registery/canister sub-directory: cargo build --profile canister-release --target wasm32-unknown-unknown --bin registry-canister The fix is to make sure the feature `getrandom/custom` is enabled. Note that the above command would succeed if running from the top-level directory, but would produce incorrect wasm binary. This is because cargo would bring in global dependencies that enable both `getrandom/custom` and `getrandom/js` features, and the latter will lead to wasm binaries having unwanted imports (See #3309 for more details). Since this problem does not affect bazel builds, this fix is only relevant to cargo. --- Cargo.lock | 1 + rs/registry/canister/Cargo.toml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 098b9048d54..9b761dcc7bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18343,6 +18343,7 @@ dependencies = [ "dfn_core", "dfn_http_metrics", "futures", + "getrandom", "ic-base-types", "ic-canister-client-sender", "ic-cdk 0.16.0", diff --git a/rs/registry/canister/Cargo.toml b/rs/registry/canister/Cargo.toml index 25ad4b78899..43ed07df70b 100644 --- a/rs/registry/canister/Cargo.toml +++ b/rs/registry/canister/Cargo.toml @@ -51,6 +51,9 @@ prost = { workspace = true } serde = { workspace = true } url = { workspace = true } +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { version = "0.2", features = [ "custom" ] } + [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] assert_matches = { workspace = true } candid_parser = { workspace = true }