Skip to content

Commit

Permalink
Make bazel lock file cross-platform
Browse files Browse the repository at this point in the history
Since the host tools are os and arch specific, previously bazel would cache the resolution of these in the lock file, causing the repo for the wrong OS or arch to be used when moving between machines.

Bazel has the `os_dependent` and `arch_dependent` attributes in the module extension to "key" this resolution by OS and arch. However, the `rust` module extension handles fetching of all the other toolchains as well as the host tools, and we don't really want to key these too. Therefore the host tools are moved to their own module extension. This means we can no longer match the host toolchain's version, edition, etc with the toolchain registered via `rust.toolchain` by default, and instead default to a fixed version. This can still be overriden separately in the root module. I think this is okay, because the host tools are only used for bootstrapping and I don't think there's much need to have them match.

This is tested by now checking in the MODULE.bazel.lock file of the bzlmod example, and the CI runners that test on multiple platforms will pass.

Resolves #2452
  • Loading branch information
cameron-martin committed Feb 1, 2024
1 parent 0f777e1 commit 504e521
Show file tree
Hide file tree
Showing 4 changed files with 15,097 additions and 55 deletions.
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ register_toolchains(
"@rust_toolchains//:all",
)

use_repo(rust, "rust_host_tools")
rust_host_tools = use_extension("//rust:extensions.bzl", "rust_host_tools")
use_repo(rust_host_tools, "rust_host_tools")

cargo_bazel_bootstrap = use_extension("//crate_universe/private/module_extensions:cargo_bazel_bootstrap.bzl", "cargo_bazel_bootstrap")
use_repo(cargo_bazel_bootstrap, "cargo_bazel_bootstrap")
1 change: 0 additions & 1 deletion examples/bzlmod/hello_world/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/bazel-*
/MODULE.bazel.lock
Loading

0 comments on commit 504e521

Please sign in to comment.