-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bazel 7 broke nested action directory outputs #21782
Comments
This is an intentional change; the associated incompatible flag is actually |
Hmm. Is that intentional change documented anywhere? I might just be missing it, but I don't see it mentioned anywhere in the v7.0 release notes. And also, is it possible to undo that change? I don't understand the motivation behind it, and nested output directories are extremely useful for working with certain language ecosystems. For example, Javascript package managers produce a |
Actually, it was flipped in Bazel 6.0.0 (commit fe16965) but seems to be missing from the 6.0.0 release notes. We've had this issue before with changes that are cherry-picked into a release branch after it has already been cut from the main branch; I'll see if I can get it fixed.
No, sorry. The value of this feature doesn't justify its implementation cost; it broke an extremely useful invariant (that every output file is owned by exactly one declared artifact) whose absence was a constant source of bugs, and whose existence simplifies several subsystems (notably conflict checking and input prefetching).
Do the consumers of this rule receive the entire If consumers always receive the entire If consumers receive only certain modules as inputs but not the rest, I'm afraid you'll have to split each module into its own action. (You might also want to look into how |
Correction: a flip was initially attempted for 6.0.0, but rolled back. A second attempt took place for 7.0.0 (commit: 7bd0ab6) and that one has stuck. tl;dr: 7.0.0 is the first release where |
Do you think there would be any way to provide an equivalent Starlark API to rules authors, while maintaining that new invariant? It's frustrating that a feature present since Bazel v1.0 has been silently broken without providing a replacement. I'm somewhat rusty on the Bazel internals at this point, but given the example rules fragment: a = ctx.actions.declare_directory(name + "/a")
b = ctx.actions.declare_directory(name + "/a/b")
ctx.actions.run(outputs = [a, b], ...) It seems that there is a path forward in which Alternatively, maybe a modified API like this would be acceptable? a = ctx.actions.declare_directory(name + "/a")
b = ctx.actions.declare_directory("b", parent = a)
ctx.actions.run(outputs = [a], ...)
# b is a File that identifies output directory "{name}/a/b" I'd prefer to maintain the old API if possible, but even a new API would be better than just being broken. Note that the desire to identify subsets of a directory wouldn't be as necessary if Bazel supported marking files as non-symlinkable (#10299), because that would allow synthetic
It depends on the consumer. Given a tree of This strategy is because the full Public JS rulesets such as |
Yes, that's strictly better than the nested artifacts being potentially created by different actions, but the fact that an action can consume the inner artifact but not the outer one still creates (created) a lot of implementation complexity and potential for bugs in various places, because the outer artifact can be in a state of having been "half produced" (if e.g. only the inner artifact is fetched from a disk/remote cache). A different API doesn't do away with this issue.
I think the sentence "Node runtime's habit of symlink peeking" is doing a lot of work here, but you have to connect the dots for me because I'm not that familiar with Node.js :) Are you saying that, given a |
Ah well, it sounds like there's no going back to the old capability, so I'll just ask that the change be made clearer in the release notes. And any similarly breaking changes in the future, since otherwise they come as a bit of a shock. Regarding Node: When a For Bazel, this has two consequences:
For my own use I built a Remote Execution executor that can apply Node-specific fixups (replacing symlinks with their targets), but the resulting projects can't be built by Bazel's local executor. My hope is that Bazel will eventually provide enough control over artifact layout and sandbox setup such that such projects can be built with plain vanilla Bazel. |
I will get the release notes for 7.0.0 fixed (and, more importantly, see if the process can also be fixed so we don't lose release notes again in the future.) Thanks for giving some more context on the Node.js limitations around symlinks. It's still a little unclear to me why the ability to nest It also seems to me that Bazel's reliance on symlinks to implement sandboxing is the greater of the two issues, because it will work against Node regardless of whether the |
I'm not sure what you mean by this. The # third_party/github.com/lit/lit/repository.bzl
load("//build/rules_yarn/yarn:yarn.bzl", "yarn_archives")
def com_github_lit_lit():
yarn_archives(
name = "com_github_lit_lit",
lockfiles = ["//third_party/github.com/lit/lit:v2.2.1/yarn.lock"],
)
# third_party/github.com/lit/lit/BUILD
load("//build/rules_yarn/yarn:yarn.bzl", "yarn_install")
licenses(["notice"]) # BSD-3-Clause
yarn_install(
name = "yarn_installed",
archives = ["@com_github_lit_lit"],
package_json = ":v2.2.1/package.json",
packages = [
"lit",
"lit-element",
"lit-html",
"@lit/reactive-element",
"@types/trusted-types",
],
visibility = ["//visibility:public"],
yarn_lock = ":v2.2.1/yarn.lock",
) When the The reason the "fetch archives" and "generate
I haven't used that feature yet, but would be interested in trying it out once it works for macOS. For Linux builds I mostly use a remote execution setup rather than Bazel's built-in sandboxing. |
Thanks, that's the bit I was missing; I assumed you could just run the entire process that produces the
To be clear, I don't believe we have plans at the moment to extend |
Here's an additional thought (apologies if this makes no sense - I haven't worked with Node.js in a long time, and my experience predates yarn :)) My understanding is that yarn produces (or can be convinced to produce?) a flat Does this approximate a viable solution? |
The nested artifacts are direct children of
I think that would be difficult without running Yarn itself during the repository rule phase. The repository rule downloads archives listed in a lock file, and the build rule uses those archives as inputs to build Since the original point of this issue has been addressed (the change being intentional), feel free to close. I'll try to find another way to wrestle Node into cooperation with the new Bazel v7 requirements. |
Description of the bug:
Output directories declared with
ctx.actions.declare_directory
are allowed to be nested, for example an action can declare it outputs"{rule_name}/topdir"
and"{rule_name}/topdir/subdir"
. This functionality broke in Bazel 7, and such output graphs now cause an analysis error.Which category does this issue belong to?
Core
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
The build succeeds with Bazel versions <= 6.5.0:
The build fails with Bazel versions >= 7.0.0 (tested v7.0.0 and v7.1.1)
Which operating system are you running Bazel on?
macOS
What is the output of
bazel info release
?release 7.0.0 / release 7.1.1
If
bazel info release
returnsdevelopment 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.
I suspect this is related to the directory output changes in v7.0 (
--incompatible_disallow_unsound_directory_outputs
, etc), so more of a "forgot to test that case in rewritten impl" rather than a specific bad commit.Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: