-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
Description of the bug:
Some time last week I migrated Buildbarn from WORKSPACE to MODULE.bazel. This process went smoother than I had expected up front, so kudos to the folks implementing this.
Unfortunately, I came to the conclusion that the MODULE.bazel approach still isn't as 'modular' as I had hoped.
Which category does this issue belong to?
No response
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
For example, let's create a toy project that uses rules_rust:
$ cat > MODULE.bazel << 'EOF'
module(name = "foo")
bazel_dep(name = "rules_rust", version = "0.41.1")
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(edition = "2021")
EOF
$ cat > BUILD.bazel << 'EOF'
load("@rules_rust//rust:defs.bzl", "rust_binary")
rust_binary(
name = "hello",
srcs = ["hello.rs"],
)
EOF
cat > hello.rs << 'EOF'
fn main() {
println!("Hello World!");
}
EOF
$ bazel run //:hello
...
Hello World!
Now let's consider that some user wants to integrate this project into their organisation in the form of a tarball, so they create a Bazel project that looks like this:
cat > MODULE.bazel << 'EOF'
module(name = "bar")
bazel_dep(name = "foo", version = "0.0.0")
bazel_dep(name = "rules_pkg", version = "0.10.1")
# git_override, archive_override, or local_path_override for "foo" goes here.
EOF
cat > BUILD.bazel << 'EOF'
load("@rules_pkg//:pkg.bzl", "pkg_tar")
pkg_tar(
name = "hello_tar",
srcs = ["@foo//:hello"],
)
EOF
When they try to build their tarball, they get presented with the following error message:
$ bazel build //...
...
ERROR: Traceback (most recent call last):
...
Error in fail:
Your transitive dependency foo is using rules_rust, so you need to define a rust toolchain.
To do so, you will need to add the following to your root MODULE.bazel. For example:
bazel_dep(name = "rules_rust", version = "<rules_rust version>")
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(
edition = "2021",
versions = ["1.70.2"],
)
use_repo(rust, "rust_toolchains")
register_toolchains("@rust_toolchains//:all")
...
So now the user, who couldn't care less that my tool is written in Rust, needs to copy-paste code from the original MODULE.bazel file into their own project, and make sure that that code remains up to date. In my opinion this completely undermines the problem that MODULE.bazel was trying to solve. It adds unnecessary complexity when people try to use Bazel as a meta-build system for tying multiple projects together.
rules_rust isn't the only set of rules that has such weird restrictions. I have also observed this to be an issue with toolchains_llvm.
Which operating system are you running Bazel on?
All of them
What is the output of bazel info release?
7.1.1
If bazel info release returns development version or (@non-git), tell us how you built Bazel.
No response
What's the output of git remote get-url origin; git rev-parse HEAD ?
No response
Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
is_root was introduced here: #15815
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
In my opinion either one of the two following things needs to be done:
- Non-intrusive: change
is_rootto returnTrueif and only if it is the root of all modules that depend on a given module instead of the literal root of the project. - Deprecate
is_rootand introduce a way where rules authors can compare modules along a partial order based on parent/child relationships.
In my opinion archive_override and git_override should be given a similar treatment. Namely, it's completely valid for them to get ignored when declared in a child module when the parent also has a dependency on it. But ignoring it if none of the parents/siblings/... depend on it either? That's just cruel.