From 32240f23bf5726bba12da75b3bf69dd001ec6b5d Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Mon, 21 Jul 2025 16:35:19 +0200 Subject: [PATCH 1/2] chore: inline dependencies in types crates This inlines `DEPENDENCIES` and other dep bundles in `BUILD.bazel` files for the crates under `rs/types`. This makes the dependencies of each target more explicit and helps analysis tools. --- rs/types/base_types/BUILD.bazel | 90 ++++++------ rs/types/exhaustive_derive/BUILD.bazel | 14 +- .../fuzz/BUILD.bazel | 42 ++++-- rs/types/types/BUILD.bazel | 130 ++++++++++-------- rs/types/wasm_types/BUILD.bazel | 51 +++---- 5 files changed, 189 insertions(+), 138 deletions(-) diff --git a/rs/types/base_types/BUILD.bazel b/rs/types/base_types/BUILD.bazel index 474f732bcdf6..e9a94fd8ef10 100644 --- a/rs/types/base_types/BUILD.bazel +++ b/rs/types/base_types/BUILD.bazel @@ -9,42 +9,6 @@ filegroup( srcs = glob(["proto/**"]), ) -DEPENDENCIES = [ - # Keep sorted. - "//rs/crypto/sha2", - "//rs/phantom_newtype", - "//rs/protobuf", - "@crate_index//:byte-unit", - "@crate_index//:bytes", - "@crate_index//:candid", - "@crate_index//:comparable", - "@crate_index//:hex", - "@crate_index//:prost", - "@crate_index//:serde", - "@crate_index//:serde_bytes", - "@crate_index//:strum", -] + select({ - "//bazel:fuzzing_code_enabled": ["@crate_index//:arbitrary"], - "//conditions:default": [], -}) - -PROC_MACRO_DEPENDENCIES = [ - # Keep sorted. - "@crate_index//:strum_macros", -] - -DEV_DEPENDENCIES = [ - # Keep sorted. - "@crate_index//:assert_matches", - "@crate_index//:proptest", - "@crate_index//:serde_cbor", -] - -PROC_MACRO_DEV_DEPENDENCIES = [ - # Keep sorted. - "@crate_index//:proptest-derive", -] - rust_library( name = "base_types", srcs = glob([ @@ -55,20 +19,66 @@ rust_library( "//conditions:default": [], }), crate_name = "ic_base_types", - proc_macro_deps = PROC_MACRO_DEPENDENCIES, + proc_macro_deps = [ + # Keep sorted. + "@crate_index//:strum_macros", + ], rustc_flags = select({ "//bazel:fuzzing_code_enabled": DEFAULT_RUSTC_FLAGS_FOR_FUZZING, "//conditions:default": [], }), version = "0.9.0", - deps = DEPENDENCIES, + deps = [ + # Keep sorted. + "//rs/crypto/sha2", + "//rs/phantom_newtype", + "//rs/protobuf", + "@crate_index//:byte-unit", + "@crate_index//:bytes", + "@crate_index//:candid", + "@crate_index//:comparable", + "@crate_index//:hex", + "@crate_index//:prost", + "@crate_index//:serde", + "@crate_index//:serde_bytes", + "@crate_index//:strum", + ] + select({ + "//bazel:fuzzing_code_enabled": ["@crate_index//:arbitrary"], + "//conditions:default": [], + }), ) rust_test( name = "base_types_test", crate = ":base_types", - proc_macro_deps = PROC_MACRO_DEPENDENCIES + PROC_MACRO_DEV_DEPENDENCIES, - deps = DEPENDENCIES + DEV_DEPENDENCIES, + proc_macro_deps = [ + # Keep sorted. + "@crate_index//:strum_macros", + ] + [ + # Keep sorted. + "@crate_index//:proptest-derive", + ], + deps = [ + # Keep sorted. + "//rs/crypto/sha2", + "//rs/phantom_newtype", + "//rs/protobuf", + "@crate_index//:assert_matches", + "@crate_index//:byte-unit", + "@crate_index//:bytes", + "@crate_index//:candid", + "@crate_index//:comparable", + "@crate_index//:hex", + "@crate_index//:proptest", + "@crate_index//:prost", + "@crate_index//:serde", + "@crate_index//:serde_bytes", + "@crate_index//:serde_cbor", + "@crate_index//:strum", + ] + select({ + "//bazel:fuzzing_code_enabled": ["@crate_index//:arbitrary"], + "//conditions:default": [], + }), ) generated_files_check( diff --git a/rs/types/exhaustive_derive/BUILD.bazel b/rs/types/exhaustive_derive/BUILD.bazel index cb82595760c9..a2c9fe687397 100644 --- a/rs/types/exhaustive_derive/BUILD.bazel +++ b/rs/types/exhaustive_derive/BUILD.bazel @@ -2,18 +2,16 @@ load("@rules_rust//rust:defs.bzl", "rust_proc_macro") package(default_visibility = ["//visibility:public"]) -DEPENDENCIES = [ - # Keep sorted. - "@crate_index//:proc-macro2", - "@crate_index//:quote", - "@crate_index//:syn", -] - rust_proc_macro( name = "exhaustive_derive", testonly = True, srcs = glob(["src/**"]), crate_name = "ic_exhaustive_derive", version = "0.1.0", - deps = DEPENDENCIES, + deps = [ + # Keep sorted. + "@crate_index//:proc-macro2", + "@crate_index//:quote", + "@crate_index//:syn", + ], ) diff --git a/rs/types/management_canister_types/fuzz/BUILD.bazel b/rs/types/management_canister_types/fuzz/BUILD.bazel index 6632a0b59ee9..28c6d0877b1d 100644 --- a/rs/types/management_canister_types/fuzz/BUILD.bazel +++ b/rs/types/management_canister_types/fuzz/BUILD.bazel @@ -2,27 +2,30 @@ load("//bazel:fuzz_testing.bzl", "rust_fuzz_test_binary", "rust_fuzz_test_binary package(default_visibility = ["//visibility:private"]) -DEPENDENCIES = [ - # Keep sorted. - "//rs/types/management_canister_types", - "@crate_index//:candid", - "@crate_index//:libfuzzer-sys", -] - MACRO_DEPENDENCIES = [] rust_fuzz_test_binary( name = "decode_canister_http_request_args", srcs = ["fuzz_targets/decode_canister_http_request_args.rs"], proc_macro_deps = MACRO_DEPENDENCIES, - deps = DEPENDENCIES, + deps = [ + # Keep sorted. + "//rs/types/management_canister_types", + "@crate_index//:candid", + "@crate_index//:libfuzzer-sys", + ], ) rust_fuzz_test_binary( name = "decode_ecdsa_public_key_args", srcs = ["fuzz_targets/decode_ecdsa_public_key_args.rs"], proc_macro_deps = MACRO_DEPENDENCIES, - deps = DEPENDENCIES, + deps = [ + # Keep sorted. + "//rs/types/management_canister_types", + "@crate_index//:candid", + "@crate_index//:libfuzzer-sys", + ], ) rust_fuzz_test_binary( @@ -30,7 +33,12 @@ rust_fuzz_test_binary( srcs = ["fuzz_targets/decode_install_code_args.rs"], crate_root = "fuzz_targets/decode_install_code_args.rs", proc_macro_deps = MACRO_DEPENDENCIES, - deps = DEPENDENCIES, + deps = [ + # Keep sorted. + "//rs/types/management_canister_types", + "@crate_index//:candid", + "@crate_index//:libfuzzer-sys", + ], ) rust_fuzz_test_binary_afl( @@ -38,12 +46,22 @@ rust_fuzz_test_binary_afl( srcs = ["fuzz_targets/decode_install_code_args.rs"], crate_root = "fuzz_targets/decode_install_code_args.rs", proc_macro_deps = MACRO_DEPENDENCIES, - deps = DEPENDENCIES, + deps = [ + # Keep sorted. + "//rs/types/management_canister_types", + "@crate_index//:candid", + "@crate_index//:libfuzzer-sys", + ], ) rust_fuzz_test_binary( name = "decode_sign_with_ecdsa_args", srcs = ["fuzz_targets/decode_sign_with_ecdsa_args.rs"], proc_macro_deps = MACRO_DEPENDENCIES, - deps = DEPENDENCIES, + deps = [ + # Keep sorted. + "//rs/types/management_canister_types", + "@crate_index//:candid", + "@crate_index//:libfuzzer-sys", + ], ) diff --git a/rs/types/types/BUILD.bazel b/rs/types/types/BUILD.bazel index 13c4085dfb9a..a646bd8f822e 100644 --- a/rs/types/types/BUILD.bazel +++ b/rs/types/types/BUILD.bazel @@ -3,57 +3,6 @@ load("//bazel:fuzz_testing.bzl", "DEFAULT_RUSTC_FLAGS_FOR_FUZZING") package(default_visibility = ["//visibility:public"]) -DEPENDENCIES = [ - # Keep sorted. - "//packages/ic-error-types", - "//rs/bitcoin/replica_types", - "//rs/crypto/internal/crypto_lib/types", - "//rs/crypto/sha2", - "//rs/crypto/tree_hash", - "//rs/limits", - "//rs/phantom_newtype", - "//rs/protobuf", - "//rs/types/base_types", - "//rs/types/management_canister_types", - "//rs/utils", - "//rs/utils/validate_eq", - "@crate_index//:base64", - "@crate_index//:bincode", - "@crate_index//:candid", - "@crate_index//:hex", - "@crate_index//:maplit", - "@crate_index//:once_cell", - "@crate_index//:prost", - "@crate_index//:rand", - "@crate_index//:serde", - "@crate_index//:serde_bytes", - "@crate_index//:serde_cbor", - "@crate_index//:serde_json", - "@crate_index//:serde_with", - "@crate_index//:strum", - "@crate_index//:thiserror", - "@crate_index//:thousands", -] - -DEV_DEPENDENCIES = [ - # Keep sorted. - "//rs/crypto/test_utils/canister_threshold_sigs", - "//rs/crypto/test_utils/reproducible_rng", - "//rs/types/types_test_utils", - "@crate_index//:assert_matches", - "@crate_index//:hex-literal", - "@crate_index//:pretty_assertions", - "@crate_index//:proptest", - "@crate_index//:rand_chacha", - "@crate_index//:rusty-fork", -] - -MACRO_DEV_DEPENDENCIES = [ - # Keep sorted. - "//rs/types/exhaustive_derive", - "@crate_index//:proptest-derive", -] - rust_library( name = "types", srcs = glob(["src/**"]), @@ -68,7 +17,37 @@ rust_library( "//conditions:default": [], }), version = "0.9.0", - deps = DEPENDENCIES + select({ + deps = [ + # Keep sorted. + "//packages/ic-error-types", + "//rs/bitcoin/replica_types", + "//rs/crypto/internal/crypto_lib/types", + "//rs/crypto/sha2", + "//rs/crypto/tree_hash", + "//rs/limits", + "//rs/phantom_newtype", + "//rs/protobuf", + "//rs/types/base_types", + "//rs/types/management_canister_types", + "//rs/utils", + "//rs/utils/validate_eq", + "@crate_index//:base64", + "@crate_index//:bincode", + "@crate_index//:candid", + "@crate_index//:hex", + "@crate_index//:maplit", + "@crate_index//:once_cell", + "@crate_index//:prost", + "@crate_index//:rand", + "@crate_index//:serde", + "@crate_index//:serde_bytes", + "@crate_index//:serde_cbor", + "@crate_index//:serde_json", + "@crate_index//:serde_with", + "@crate_index//:strum", + "@crate_index//:thiserror", + "@crate_index//:thousands", + ] + select({ "@rules_rust//rust/platform:wasm32-unknown-unknown": [], "//conditions:default": ["@crate_index//:chrono"], }), @@ -77,8 +56,51 @@ rust_library( rust_test( name = "types_test", crate = ":types", - proc_macro_deps = MACRO_DEV_DEPENDENCIES, - deps = DEPENDENCIES + DEV_DEPENDENCIES, + proc_macro_deps = [ + # Keep sorted. + "//rs/types/exhaustive_derive", + "@crate_index//:proptest-derive", + ], + deps = [ + # Keep sorted. + "//packages/ic-error-types", + "//rs/bitcoin/replica_types", + "//rs/crypto/internal/crypto_lib/types", + "//rs/crypto/sha2", + "//rs/crypto/test_utils/canister_threshold_sigs", + "//rs/crypto/test_utils/reproducible_rng", + "//rs/crypto/tree_hash", + "//rs/limits", + "//rs/phantom_newtype", + "//rs/protobuf", + "//rs/types/base_types", + "//rs/types/management_canister_types", + "//rs/types/types_test_utils", + "//rs/utils", + "//rs/utils/validate_eq", + "@crate_index//:assert_matches", + "@crate_index//:base64", + "@crate_index//:bincode", + "@crate_index//:candid", + "@crate_index//:hex", + "@crate_index//:hex-literal", + "@crate_index//:maplit", + "@crate_index//:once_cell", + "@crate_index//:pretty_assertions", + "@crate_index//:proptest", + "@crate_index//:prost", + "@crate_index//:rand", + "@crate_index//:rand_chacha", + "@crate_index//:rusty-fork", + "@crate_index//:serde", + "@crate_index//:serde_bytes", + "@crate_index//:serde_cbor", + "@crate_index//:serde_json", + "@crate_index//:serde_with", + "@crate_index//:strum", + "@crate_index//:thiserror", + "@crate_index//:thousands", + ], ) rust_doc( diff --git a/rs/types/wasm_types/BUILD.bazel b/rs/types/wasm_types/BUILD.bazel index 94b6ea9c79ec..c637eb094adb 100644 --- a/rs/types/wasm_types/BUILD.bazel +++ b/rs/types/wasm_types/BUILD.bazel @@ -2,38 +2,41 @@ load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test") package(default_visibility = ["//visibility:public"]) -DEPENDENCIES = [ - # Keep sorted. - "//rs/crypto/sha2", - "//rs/sys", - "//rs/types/types", - "//rs/utils", - "//rs/utils/validate_eq", - "@crate_index//:serde", -] - -PROC_MACRO_DEPENDENCIES = [ - # Keep sorted. - "//rs/utils/validate_eq_derive", -] - -DEV_DEPENDENCIES = [ - # Keep sorted. - "@crate_index//:tempfile", -] - rust_library( name = "wasm_types", srcs = glob(["src/**"]), crate_name = "ic_wasm_types", - proc_macro_deps = PROC_MACRO_DEPENDENCIES, + proc_macro_deps = [ + # Keep sorted. + "//rs/utils/validate_eq_derive", + ], version = "0.9.0", - deps = DEPENDENCIES, + deps = [ + # Keep sorted. + "//rs/crypto/sha2", + "//rs/sys", + "//rs/types/types", + "//rs/utils", + "//rs/utils/validate_eq", + "@crate_index//:serde", + ], ) rust_test( name = "wasm_types_test", crate = ":wasm_types", - proc_macro_deps = PROC_MACRO_DEPENDENCIES, - deps = DEPENDENCIES + DEV_DEPENDENCIES, + proc_macro_deps = [ + # Keep sorted. + "//rs/utils/validate_eq_derive", + ], + deps = [ + # Keep sorted. + "//rs/crypto/sha2", + "//rs/sys", + "//rs/types/types", + "//rs/utils", + "//rs/utils/validate_eq", + "@crate_index//:serde", + "@crate_index//:tempfile", + ], ) From 9cccc42a5a5380088435cc817127b18d3ce98f24 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Tue, 22 Jul 2025 17:51:29 +0200 Subject: [PATCH 2/2] Update rs/types/management_canister_types/fuzz/BUILD.bazel Co-authored-by: Pierugo Pace --- rs/types/management_canister_types/fuzz/BUILD.bazel | 7 ------- 1 file changed, 7 deletions(-) diff --git a/rs/types/management_canister_types/fuzz/BUILD.bazel b/rs/types/management_canister_types/fuzz/BUILD.bazel index 28c6d0877b1d..7f5cf38f8340 100644 --- a/rs/types/management_canister_types/fuzz/BUILD.bazel +++ b/rs/types/management_canister_types/fuzz/BUILD.bazel @@ -2,12 +2,9 @@ load("//bazel:fuzz_testing.bzl", "rust_fuzz_test_binary", "rust_fuzz_test_binary package(default_visibility = ["//visibility:private"]) -MACRO_DEPENDENCIES = [] - rust_fuzz_test_binary( name = "decode_canister_http_request_args", srcs = ["fuzz_targets/decode_canister_http_request_args.rs"], - proc_macro_deps = MACRO_DEPENDENCIES, deps = [ # Keep sorted. "//rs/types/management_canister_types", @@ -19,7 +16,6 @@ rust_fuzz_test_binary( rust_fuzz_test_binary( name = "decode_ecdsa_public_key_args", srcs = ["fuzz_targets/decode_ecdsa_public_key_args.rs"], - proc_macro_deps = MACRO_DEPENDENCIES, deps = [ # Keep sorted. "//rs/types/management_canister_types", @@ -32,7 +28,6 @@ rust_fuzz_test_binary( name = "decode_install_code_args_libfuzzer", srcs = ["fuzz_targets/decode_install_code_args.rs"], crate_root = "fuzz_targets/decode_install_code_args.rs", - proc_macro_deps = MACRO_DEPENDENCIES, deps = [ # Keep sorted. "//rs/types/management_canister_types", @@ -45,7 +40,6 @@ rust_fuzz_test_binary_afl( name = "decode_install_code_args_afl", srcs = ["fuzz_targets/decode_install_code_args.rs"], crate_root = "fuzz_targets/decode_install_code_args.rs", - proc_macro_deps = MACRO_DEPENDENCIES, deps = [ # Keep sorted. "//rs/types/management_canister_types", @@ -57,7 +51,6 @@ rust_fuzz_test_binary_afl( rust_fuzz_test_binary( name = "decode_sign_with_ecdsa_args", srcs = ["fuzz_targets/decode_sign_with_ecdsa_args.rs"], - proc_macro_deps = MACRO_DEPENDENCIES, deps = [ # Keep sorted. "//rs/types/management_canister_types",