Skip to content

Commit

Permalink
chore(build): refine the locking of Rust dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ADD-SP authored and fffonion committed Nov 21, 2024
1 parent 5901c5a commit 9918f6d
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 62 deletions.
6 changes: 1 addition & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions build/kong_crate/crates.bzl
Original file line number Diff line number Diff line change
@@ -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()
18 changes: 4 additions & 14 deletions build/kong_crate/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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",
],
Expand Down
2 changes: 1 addition & 1 deletion build/openresty/atc_router/BUILD.atc_router.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
28 changes: 28 additions & 0 deletions crate_locks/README.md
Original file line number Diff line number Diff line change
@@ -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
```
24 changes: 12 additions & 12 deletions Cargo.Bazel.lock → crate_locks/atc_router.Cargo.lock

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

56 changes: 28 additions & 28 deletions Cargo.Bazel.lock.json → crate_locks/atc_router.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"checksum": "8374b41763bef26d4f617b2183d2c0e94616f961822b5b6f31c4d8ada177b48c",
"checksum": "71a528ead48a5f4f3d5eda359189caaecdd17e47fe58e6e0e5ab3a90d010e3d4",
"crates": {
"aho-corasick 1.1.3": {
"name": "aho-corasick",
Expand Down Expand Up @@ -106,7 +106,7 @@
"target": "pest"
},
{
"id": "regex 1.11.0",
"id": "regex 1.11.1",
"target": "regex"
},
{
Expand Down Expand Up @@ -818,7 +818,7 @@
"target": "memchr"
},
{
"id": "thiserror 1.0.65",
"id": "thiserror 1.0.68",
"target": "thiserror"
},
{
Expand Down Expand Up @@ -951,7 +951,7 @@
"target": "quote"
},
{
"id": "syn 2.0.82",
"id": "syn 2.0.87",
"target": "syn"
}
],
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -1229,7 +1229,7 @@
"selects": {}
},
"edition": "2021",
"version": "1.11.0"
"version": "1.11.1"
},
"license": "MIT OR Apache-2.0",
"license_ids": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -1492,7 +1492,7 @@
"selects": {}
},
"edition": "2021",
"version": "2.0.82"
"version": "2.0.87"
},
"license": "MIT OR Apache-2.0",
"license_ids": [
Expand All @@ -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": [
Expand Down Expand Up @@ -1545,7 +1545,7 @@
"deps": {
"common": [
{
"id": "thiserror 1.0.65",
"id": "thiserror 1.0.68",
"target": "build_script_build"
}
],
Expand All @@ -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": [
Expand All @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": []
Expand Down

1 comment on commit 9918f6d

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel Build

Docker image available kong/kong:9918f6da67d898cd02bec61442803286e532303d
Artifacts available https://github.com/Kong/kong/actions/runs/11949383389

Please sign in to comment.