From 9918f6da67d898cd02bec61442803286e532303d Mon Sep 17 00:00:00 2001 From: ADD-SP Date: Tue, 5 Nov 2024 08:47:37 +0000 Subject: [PATCH] chore(build): refine the locking of Rust dependencies --- WORKSPACE | 6 +- build/kong_crate/crates.bzl | 4 +- build/kong_crate/deps.bzl | 18 ++---- .../atc_router/BUILD.atc_router.bazel | 2 +- crate_locks/README.md | 28 ++++++++++ .../atc_router.Cargo.lock | 24 ++++---- .../atc_router.lock | 56 +++++++++---------- 7 files changed, 76 insertions(+), 62 deletions(-) create mode 100644 crate_locks/README.md rename Cargo.Bazel.lock => crate_locks/atc_router.Cargo.lock (92%) rename Cargo.Bazel.lock.json => crate_locks/atc_router.lock (97%) diff --git a/WORKSPACE b/WORKSPACE index f721ab7370d6..bdc920470247 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -65,11 +65,7 @@ openresty_repositories() # [[ BEGIN: must happen after any Rust repositories are loaded load("//build/kong_crate:deps.bzl", "kong_crate_repositories") -kong_crate_repositories( - cargo_home_isolated = False, - cargo_lockfile = "//:Cargo.Bazel.lock", - lockfile = "//:Cargo.Bazel.lock.json", -) +kong_crate_repositories(cargo_home_isolated = False) load("//build/kong_crate:crates.bzl", "kong_crates") diff --git a/build/kong_crate/crates.bzl b/build/kong_crate/crates.bzl index db3aec2fa4c0..3e9ab4b6f38a 100644 --- a/build/kong_crate/crates.bzl +++ b/build/kong_crate/crates.bzl @@ -1,6 +1,6 @@ """Setup Crates repostories """ -load("@kong_crate_index//:defs.bzl", "crate_repositories") +load("@atc_router_crate_index//:defs.bzl", atc_router_crate_repositories = "crate_repositories") def kong_crates(): - crate_repositories() + atc_router_crate_repositories() diff --git a/build/kong_crate/deps.bzl b/build/kong_crate/deps.bzl index f51e8880b97d..ea9f1ac0bb20 100644 --- a/build/kong_crate/deps.bzl +++ b/build/kong_crate/deps.bzl @@ -4,21 +4,11 @@ load("@rules_rust//crate_universe:defs.bzl", "crates_repository") load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set") -def kong_crate_repositories(cargo_lockfile, lockfile, cargo_home_isolated = True): +def kong_crate_repositories(cargo_home_isolated = True): """ Setup Kong Crates repostories Args: - cargo_lockfile (label): Label to the Cargo.Bazel.lock file, - the document of the crate_universe says that this is to make sure that - Bazel and Cargo are using the same crate versions. - However, we just need the source of the Rust dependencies, we don't need the - `Cargo.lock` file, but this is a mandatory argument, so we just pass the path - to the `Cargo.Bazel.lock` file to make it happy. - - lockfile (label): Label to the Cargo.Bazel.lock.json file, - this is the lockfile for reproducible builds. - cargo_home_isolated (bool): `False` to reuse system CARGO_HOME for faster builds. `True` is default and will use isolated Cargo home, which takes about 2 minutes to bootstrap. @@ -42,10 +32,10 @@ def kong_crate_repositories(cargo_lockfile, lockfile, cargo_home_isolated = True crate_universe_dependencies() crates_repository( - name = "kong_crate_index", - cargo_lockfile = cargo_lockfile, + name = "atc_router_crate_index", + cargo_lockfile = "//:crate_locks/atc_router.Cargo.lock", isolated = cargo_home_isolated, - lockfile = lockfile, + lockfile = "//:crate_locks/atc_router.lock", manifests = [ "@atc_router//:Cargo.toml", ], diff --git a/build/openresty/atc_router/BUILD.atc_router.bazel b/build/openresty/atc_router/BUILD.atc_router.bazel index ec7c67c58afc..bd87dfccd687 100644 --- a/build/openresty/atc_router/BUILD.atc_router.bazel +++ b/build/openresty/atc_router/BUILD.atc_router.bazel @@ -1,4 +1,4 @@ -load("@kong_crate_index//:defs.bzl", "aliases", "all_crate_deps") +load("@atc_router_crate_index//:defs.bzl", "aliases", "all_crate_deps") load("@rules_rust//rust:defs.bzl", "rust_shared_library") filegroup( diff --git a/crate_locks/README.md b/crate_locks/README.md new file mode 100644 index 000000000000..e18d5c52fb3b --- /dev/null +++ b/crate_locks/README.md @@ -0,0 +1,28 @@ +# Crate Locks + +This directory contains the lock files for the Rust dependencies. + +* `xxx.Cargo.lock`: This file is generated by `cargo`, but we generate it with `bazel` to make the `rules_rust` happy. +* `xxx.lock`: This file is generated by `bazel` and is used by `rules_rust` for reproducibility. + +## Repin + +For more information on how to repin the dependencies, +please check out the [rules_rust](https://github.com/bazelbuild/rules_rust). + +### Bash + +```bash +crates="atc_router_crate_index" +CARGO_BAZEL_REPIN=1 CARGO_BAZEL_REPIN_ONLY=$scrates bazel sync --only=$crates +unset crates +``` + +### Fish + +```fish +set -l crates \ + atc_router_crate_index +CARGO_BAZEL_REPIN=1 CARGO_BAZEL_REPIN_ONLY=$(string join ',' $crates) bazel sync --only=$(string join ',' $crates) +set -e crates +``` diff --git a/Cargo.Bazel.lock b/crate_locks/atc_router.Cargo.lock similarity index 92% rename from Cargo.Bazel.lock rename to crate_locks/atc_router.Cargo.lock index ad2452b6dcb2..6e4688c2fc45 100644 --- a/Cargo.Bazel.lock +++ b/crate_locks/atc_router.Cargo.lock @@ -184,9 +184,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -213,18 +213,18 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "serde" -version = "1.0.213" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ea7893ff5e2466df8d720bb615088341b295f849602c6956047f8f80f0e9bc1" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.213" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e85ad2009c50b58e87caa8cd6dac16bdf511bbfb7af6c33df902396aa480fa5" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", @@ -254,9 +254,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.82" +version = "2.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" dependencies = [ "proc-macro2", "quote", @@ -265,18 +265,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.65" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" +checksum = "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.65" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" +checksum = "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.Bazel.lock.json b/crate_locks/atc_router.lock similarity index 97% rename from Cargo.Bazel.lock.json rename to crate_locks/atc_router.lock index b8ba9443b786..b6f2a7fdaa87 100644 --- a/Cargo.Bazel.lock.json +++ b/crate_locks/atc_router.lock @@ -1,5 +1,5 @@ { - "checksum": "8374b41763bef26d4f617b2183d2c0e94616f961822b5b6f31c4d8ada177b48c", + "checksum": "71a528ead48a5f4f3d5eda359189caaecdd17e47fe58e6e0e5ab3a90d010e3d4", "crates": { "aho-corasick 1.1.3": { "name": "aho-corasick", @@ -106,7 +106,7 @@ "target": "pest" }, { - "id": "regex 1.11.0", + "id": "regex 1.11.1", "target": "regex" }, { @@ -818,7 +818,7 @@ "target": "memchr" }, { - "id": "thiserror 1.0.65", + "id": "thiserror 1.0.68", "target": "thiserror" }, { @@ -951,7 +951,7 @@ "target": "quote" }, { - "id": "syn 2.0.82", + "id": "syn 2.0.87", "target": "syn" } ], @@ -1156,14 +1156,14 @@ ], "license_file": "LICENSE-APACHE" }, - "regex 1.11.0": { + "regex 1.11.1": { "name": "regex", - "version": "1.11.0", + "version": "1.11.1", "package_url": "https://github.com/rust-lang/regex", "repository": { "Http": { - "url": "https://static.crates.io/crates/regex/1.11.0/download", - "sha256": "38200e5ee88914975b69f657f0801b6f6dccafd44fd9326302a4aaeecfacb1d8" + "url": "https://static.crates.io/crates/regex/1.11.1/download", + "sha256": "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" } }, "targets": [ @@ -1229,7 +1229,7 @@ "selects": {} }, "edition": "2021", - "version": "1.11.0" + "version": "1.11.1" }, "license": "MIT OR Apache-2.0", "license_ids": [ @@ -1434,14 +1434,14 @@ ], "license_file": "LICENSE-APACHE" }, - "syn 2.0.82": { + "syn 2.0.87": { "name": "syn", - "version": "2.0.82", + "version": "2.0.87", "package_url": "https://github.com/dtolnay/syn", "repository": { "Http": { - "url": "https://static.crates.io/crates/syn/2.0.82/download", - "sha256": "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" + "url": "https://static.crates.io/crates/syn/2.0.87/download", + "sha256": "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" } }, "targets": [ @@ -1492,7 +1492,7 @@ "selects": {} }, "edition": "2021", - "version": "2.0.82" + "version": "2.0.87" }, "license": "MIT OR Apache-2.0", "license_ids": [ @@ -1501,14 +1501,14 @@ ], "license_file": "LICENSE-APACHE" }, - "thiserror 1.0.65": { + "thiserror 1.0.68": { "name": "thiserror", - "version": "1.0.65", + "version": "1.0.68", "package_url": "https://github.com/dtolnay/thiserror", "repository": { "Http": { - "url": "https://static.crates.io/crates/thiserror/1.0.65/download", - "sha256": "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" + "url": "https://static.crates.io/crates/thiserror/1.0.68/download", + "sha256": "02dd99dc800bbb97186339685293e1cc5d9df1f8fae2d0aecd9ff1c77efea892" } }, "targets": [ @@ -1545,7 +1545,7 @@ "deps": { "common": [ { - "id": "thiserror 1.0.65", + "id": "thiserror 1.0.68", "target": "build_script_build" } ], @@ -1555,13 +1555,13 @@ "proc_macro_deps": { "common": [ { - "id": "thiserror-impl 1.0.65", + "id": "thiserror-impl 1.0.68", "target": "thiserror_impl" } ], "selects": {} }, - "version": "1.0.65" + "version": "1.0.68" }, "build_script_attrs": { "data_glob": [ @@ -1575,14 +1575,14 @@ ], "license_file": "LICENSE-APACHE" }, - "thiserror-impl 1.0.65": { + "thiserror-impl 1.0.68": { "name": "thiserror-impl", - "version": "1.0.65", + "version": "1.0.68", "package_url": "https://github.com/dtolnay/thiserror", "repository": { "Http": { - "url": "https://static.crates.io/crates/thiserror-impl/1.0.65/download", - "sha256": "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" + "url": "https://static.crates.io/crates/thiserror-impl/1.0.68/download", + "sha256": "a7c61ec9a6f64d2793d8a45faba21efbe3ced62a886d44c36a009b2b519b4c7e" } }, "targets": [ @@ -1615,14 +1615,14 @@ "target": "quote" }, { - "id": "syn 2.0.82", + "id": "syn 2.0.87", "target": "syn" } ], "selects": {} }, "edition": "2021", - "version": "1.0.65" + "version": "1.0.68" }, "license": "MIT OR Apache-2.0", "license_ids": [ @@ -2016,7 +2016,7 @@ "lazy_static 1.5.0", "pest 2.7.14", "pest_derive 2.7.14", - "regex 1.11.0", + "regex 1.11.1", "uuid 1.11.0" ], "direct_dev_deps": []