Skip to content

Commit

Permalink
Make bazel lock file cross-platform (#2453)
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.

Since bazel 7.1.0, module extensions can be marked as reproducible to
exclude these from the lock file. 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 exclude those 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 overridden 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 running the bzlmod examples on multiple platforms
with `--lockfile_mode` set to `error`.

Resolves #2452
Resolves #2549
  • Loading branch information
cameron-martin authored Apr 5, 2024
1 parent 5f06994 commit fd71efb
Show file tree
Hide file tree
Showing 4 changed files with 15,685 additions and 62 deletions.
5 changes: 5 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ nightly_aspects_flags: &nightly_aspects_flags
- "--//rust/toolchain/channel=nightly"
- "--config=rustfmt"
- "--config=clippy"
bzlmod_flags: &bzlmod_flags
- "--lockfile_mode=error"
single_rust_channel_targets: &single_rust_channel_targets
- "--"
- "//..."
Expand Down Expand Up @@ -660,6 +662,7 @@ tasks:
name: bzlmod BCR presubmit
platform: ubuntu2004
working_directory: examples/bzlmod/hello_world
test_flags: *bzlmod_flags
run_targets:
- "//third-party:vendor"
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
Expand All @@ -669,6 +672,7 @@ tasks:
name: bzlmod BCR presubmit
platform: macos
working_directory: examples/bzlmod/hello_world
test_flags: *bzlmod_flags
run_targets:
- "//third-party:vendor"
- "@rules_rust//tools/rust_analyzer:gen_rust_project"
Expand All @@ -678,6 +682,7 @@ tasks:
name: bzlmod BCR presubmit
platform: windows
working_directory: examples/bzlmod/hello_world
test_flags: *bzlmod_flags
run_targets:
- "//third-party:vendor"
build_targets:
Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ register_toolchains(
dev_dependency = True,
)

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")
Loading

0 comments on commit fd71efb

Please sign in to comment.