-
Notifications
You must be signed in to change notification settings - Fork 179
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
Automatic generation of skylark_library
targets in BUILD
files
#250
Comments
cc: @jayconrod Then we have the question of how to bundle libraries for the optimal stardoc generation. One bzl_library per file is probably not wrong. If startdoc is going to do something for integrated doc sets, that could be structured at the stardoc rule level, rather than having a big library. |
Ideally I think Gazelle extensions should live in the same repos where the rules are defined. That way, the extension can be coupled with the rules being used. Rule authors are also in a much better position to maintain those extensions than I am. From the not-following-my-own-advice department, the Go extension lives in the Gazelle repository (Gazelle was originally Go-only). There have been some issues with Gazelle and rules_go versions drifting apart. |
In order to push the discussion along, I decided to implement a strawman proposal. Please see #251 for that proposal. I have a few questions in there for both of you. If you would be so kind as to review and respond to them I would greatly appreciate it. |
To be honest, I am not going to have the time to look at this for a while. Nor can I commit to approving, because I am not directly a skylib maintainer. |
Friendly ping |
There are a few minor manual modifications that needed to be performed. For example, some `.bzl` files depend on `.bzl` files that are generated outside of this repo and do not presently exist. `@bazel_tools` is a great example of this. Additionally this effort has revealed that bazel gazelle has an explicit dependency on the private parts of rules_go in internal/gazelle_binary.bzl on line 21 where it imports from `go/private:rules/transitions.bzl` which is no longer the path to import from once I created the BUILD file in `go/private/rules`. As a temporary fix for this, I'm included a patch that changes that to point to the new path. I will provide a follow up patch once rules_go has been released to fix it properly in the gazelle repo and then remove the patch from rules_go. Fixed: bazel-contrib#2619 Bug: bazelbuild/bazel-skylib#250 Bug: bazel-contrib/bazel-gazelle#803
There are a few minor manual modifications that needed to be performed. For example, some `.bzl` files depend on `.bzl` files that are generated outside of this repo and do not presently exist. `@bazel_tools` is a great example of this. Additionally this effort has revealed that bazel gazelle has an explicit dependency on the private parts of rules_go in internal/gazelle_binary.bzl on line 21 where it imports from `go/private:rules/transitions.bzl` which is no longer the path to import from once I created the BUILD file in `go/private/rules`. As a temporary fix for this, I'm included a patch that changes that to point to the new path. I will provide a follow up patch once rules_go has been released to fix it properly in the gazelle repo and then remove the patch from rules_go. Fixed: bazel-contrib#2619 Bug: bazelbuild/bazel-skylib#250 Bug: bazel-contrib/bazel-gazelle#803 Co-authored-by: Andreas Herrmann <[email protected]>
There are a few minor manual modifications that needed to be performed. For example, some `.bzl` files depend on `.bzl` files that are generated outside of this repo and do not presently exist. `@bazel_tools` is a great example of this. Additionally this effort has revealed that bazel gazelle has an explicit dependency on the private parts of rules_go in internal/gazelle_binary.bzl on line 21 where it imports from `go/private:rules/transitions.bzl` which is no longer the path to import from once I created the BUILD file in `go/private/rules`. As a temporary fix for this, I'm included a patch that changes that to point to the new path. I will provide a follow up patch once rules_go has been released to fix it properly in the gazelle repo and then remove the patch from rules_go. Fixed: bazel-contrib#2619 Bug: bazelbuild/bazel-skylib#250 Bug: bazel-contrib/bazel-gazelle#803 Co-authored-by: Andreas Herrmann <[email protected]>
There are a few minor manual modifications that needed to be performed. For example, some `.bzl` files depend on `.bzl` files that are generated outside of this repo and do not presently exist. `@bazel_tools` is a great example of this. Additionally this effort has revealed that bazel gazelle has an explicit dependency on the private parts of rules_go in internal/gazelle_binary.bzl on line 21 where it imports from `go/private:rules/transitions.bzl` which is no longer the path to import from once I created the BUILD file in `go/private/rules`. As a temporary fix for this, I'm included a patch that changes that to point to the new path. I will provide a follow up patch once rules_go has been released to fix it properly in the gazelle repo and then remove the patch from rules_go. Fixed: bazel-contrib#2619 Bug: bazelbuild/bazel-skylib#250 Bug: bazel-contrib/bazel-gazelle#803 Co-authored-by: Andreas Herrmann <[email protected]>
There are a few minor manual modifications that needed to be performed. For example, some `.bzl` files depend on `.bzl` files that are generated outside of this repo and do not presently exist. `@bazel_tools` is a great example of this. Additionally this effort has revealed that bazel gazelle has an explicit dependency on the private parts of rules_go in internal/gazelle_binary.bzl on line 21 where it imports from `go/private:rules/transitions.bzl` which is no longer the path to import from once I created the BUILD file in `go/private/rules`. As a temporary fix for this, I'm included a patch that changes that to point to the new path. I will provide a follow up patch once rules_go has been released to fix it properly in the gazelle repo and then remove the patch from rules_go. Fixed: bazel-contrib#2619 Bug: bazelbuild/bazel-skylib#250 Bug: bazel-contrib/bazel-gazelle#803 Co-authored-by: Andreas Herrmann <[email protected]>
There are a few minor manual modifications that needed to be performed. For example, some `.bzl` files depend on `.bzl` files that are generated outside of this repo and do not presently exist. `@bazel_tools` is a great example of this. Additionally this effort has revealed that bazel gazelle has an explicit dependency on the private parts of rules_go in internal/gazelle_binary.bzl on line 21 where it imports from `go/private:rules/transitions.bzl` which is no longer the path to import from once I created the BUILD file in `go/private/rules`. As a temporary fix for this, I'm included a patch that changes that to point to the new path. I will provide a follow up patch once rules_go has been released to fix it properly in the gazelle repo and then remove the patch from rules_go. Fixed: bazel-contrib#2619 Bug: bazelbuild/bazel-skylib#250 Bug: bazel-contrib/bazel-gazelle#803 Co-authored-by: Andreas Herrmann <[email protected]>
There are a few minor manual modifications that needed to be performed. For example, some .bzl files depend on .bzl files that are generated outside of this repo and do not presently exist. @bazel_tools is a great example of this. Additionally this effort has revealed that bazel gazelle has an explicit dependency on the private parts of rules_go in internal/gazelle_binary.bzl on line 21 where it imports from go/private:rules/transitions.bzl which is no longer the path to import from once I created the BUILD file in go/private/rules. As a temporary fix for this, I'm included a patch that changes that to point to the new path. I will provide a follow up patch once rules_go has been released to fix it properly in the gazelle repo and then remove the patch from rules_go. Fixed: #2619 Bug: bazelbuild/bazel-skylib#250 Bug: bazel-contrib/bazel-gazelle#803
Hi @achew22, I'm many months late to the party, but I wanted to ask if it's possible to move this to a separate repo? As you alluded to yourself, the added dependency on rules_go and bazel_gazelle could be problematic. It becomes much more conspicuous in the external deps overhaul (tl;dr doc) since a module needs to declare its direct dependencies and all of those propagate, which means that anyone depending on Skylib would necessarily bring in rules_go and bazel_gazelle. (In fact, that's why I'm only just asking now -- I'm trying to kickstart the Bazel central registry described in the overhaul proposal.) @jayconrod re "Gazelle extensions should live in the same repos where the rules are defined", I would agree except that it brings a dependency on Go/Gazelle to any rules_X module for which such an extension exists. Is it feasible to always have such extensions in a standalone repo (read: standalone module, as described in the overhaul proposal)? |
I also wanted to say for the record that I'm not entirely clear on the details yet, so please don't treat this as an eviction notice :) How exactly does one use the gazelle plugin in this repo? I haven't used Gazelle before and the readme file here doesn't contain instructions. Depending on the answer to that question, we might be able to avoid this move by simply re-introducing the concept of dev-dependencies into the external deps overhaul proposal. |
@Wyverald, it's okay, we're just happy to see someone excited about the project.
"Could be problematic" is an interesting turn of phrase. I would expect that by now it would have already become problematic given that 6 months and a number of releases have happened. It's already been integrated into most repos. Maybe you point me to some complaints from the past few months about adding this dependency? Looking at the data, my conclusion has to be that it is not problematic since not a single soul has complained in any forum that I can witness (with the notable exception of you). I'm open to rebuttal on this one.
Since this is the first instance of someone being concerned about this in the real world. Let's take this as an opportunity to discuss what it is you're doing and why the situation that's been in place for half a year is insufficient.
Uh, I guess that's reassuring.
A usage example is actually included in this repo: bazel-skylib/gazelle/bzl/BUILD Lines 38 to 48 in e19d391
The
I didn't realize the external deps overhaul had dropped the idea of dev-dependencies. I am concerned that is going to leave a lot of projects out in the cold. Most projects already depend on the ability to have deps that aren't a part of their distribution. For example:
This means that if you don't support the idea of having a differentiation between the distribution version of a repo and the developer version of a repo, a hello world in TypeScript is going to require you to download 1500MB of data. |
what I'm trying to doAs described in the overhaul proposal, modules will specify their dependencies using MODULE.bazel files instead of WORKSPACE files, and deps will be pulled from registries (mostly the Bazel Central Registry or BCR) instead of raw URLs. I'm trying to put some initial modules into BCR, and that entails writing a MODULE.bazel file for them. Skylib is the first one I tried. It being such a fundamental standard library, I expected it to have minimal dependencies, and was surprised that its WORKSPACE file contained references to rules_go and bazel_gazelle. They obviously need to go into the MODULE.bazel file as dependencies, which means that they'd propagate to basically all Bazel modules. Hence the original question. (see more discussion about dev-deps below) As such, this is new territory and thus it's largely irrelevant whether anyone has complained in the past few months. dev-dependenciesWe dropped the idea of dev-dependencies because we couldn't cleanly support it. Imagine your module load("@fancy_test//:defs.bzl", "fancy_test")
cc_library(name = "lib")
fancy_test(name = "lib_test", deps = [":lib"]) Now, if another module So we ended up removing dev-deps because:
With all that said, there's a convincing argument to bring dev-deps back, and that is the de-cluttering of the dependency graph. We essentially have to weigh that against the drawback of potentially tricky errors (bullet point 1 above). why rules_go is not a dev-dependency in this caseThanks for providing the usage example. Judging from it, I don't think rules_go is a dev-dep of bazel_skylib (even if we supported dev-deps), because you are expecting a user of bazel_skylib to use the It's worth noting that, we can make bazel_skylib flat out depend on rules_go, and someone who doesn't use the gazelle part of skylib still won't have to download rules_go. (Just like the no-dev-deps situation above.) The problem, of course, is that it clutters the dependency graph -- we can make skylib depend on 1000 other random modules without any users of skylib having to download anything extra (as long as they don't use those parts), but that doesn't make it justifiable. |
IIUC, it sounds like the resolution here from skylib's POV is that we likely will want to put the gazelle dir in another workspace by giving it its own WORKSPACE file? |
One of the major benefits of having it in the same Does this imply that if you bring in Is it possible there is an additional kind of dependency, and I'm throwing out a straw man here, an "optional" dependency. Let's pick a worse and maybe even pathological case,
I guess I'm confused by this section. If you're saying that not having an edge upon these dependencies means that you don't actually download them, then what is the major concern? Slowing things down? Polluting the dependency graph? Can you help me understand what this a little better? |
Sorry for missing the updates, I really need to learn how to use GitHub notifications.
That's not enough, as we're talking about MODULE.bazel files here. The gazelle dir needs to be its own module, which means that it needs its own name, versions, and it needs to be able to be shipped separately (ie. I need to be able to download an archive containing its source, and preferably only its source). I can see how that is a usability hurdle. Every Bazel module needing to be its own GitHub repo can be quite taxing. Maybe we can provide explicit support for using part of a VCS repo as a Bazel module; I can see how that could be possible (for example, the entire Git repo can be packed into one archive, but we can then use
Yes indeed. Ideally the cc, python, and java parts would be separated out into distinct modules, but again, I can see how that can be annoying (see above for a potential solution).
Thanks for bringing up this example. I would definitely consider We have discussed optional dependencies for bzlmod before. There is prior art in Cargo, but it's not quite as simple as just marking certain dependencies as optional. A Cargo package As you can see this is something that warrants very careful design, in particular because it would need changes in Bazel (right now, there's no way for you to tell me in code that certain targets in your
First, to clarify the first sentence in the quoted section: by "the cost of not having dev-deps", I meant "the cost of not having the concept of dev-deps -- i.e. specifying all otherwise dev-only dependencies as normal dependencies". Having a normal dependnecy edge on rules_pkg does not cause you to fetch rules_pkg until something is needed from it. The downside of not having the dev-deps concept is then exactly as you named them: the pollution of the dependency graph and, consequently, the slowdown. |
Slightly off topic, I was trying to use the gazelle skylib extension using the following rule load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
gazelle_binary(
name = "gazelle-skylib",
languages = DEFAULT_LANGUAGES + [
"@bazel_skylib//gazelle/bzl:bzl",
],
visibility = ["//:__pkg__"],
)
gazelle(
name = "gazelle",
gazelle = ":gazelle-skylib",
) I get this error when I run
I am using skylib version |
I'm not aware of any reason why that would not work. Rather than hijacking this thread, can you make a small repo that demonstrates the issue and file a new bug which includes a link to it? That will make it a lot easier to understand what's gone wrong. Thanks! |
@srikrsna-buf is just hitting the same issue being discussed in this thread, which is that the distribution of bazel-skylib ships without the gazelle/ directory. (see target As a workaround you can fetch bazel-skylib from source instead of using the distribution, but it doesn't work under bzlmod where you must trust the central registry (and @Wyverald any progress thinking through the problem of "optional deps"? As it stands, the rules authors SIG is recommending @achew22 's gazelle extension for new rules repos https://github.com/bazel-contrib/rules-template/blob/main/BUILD.bazel#L6 so this is making a bit of a mess for rules authors when they want to introduce bzlmod. |
An approach I don't see on the thread above is to have the Granted, nothing enforces that users take the same version of
and we could document this as the suggested way to install. Since it's a nested workspace, we still get the atomicity of CI covering the two together, avoiding drift and ensuring test coverage. I'm adding a gazelle extension to our aspect-build/rules_ts right now and am planning to try this approach. |
The approach advocated by @alexeagle seems sensible to me. In contrib_rules_jvm we use the Gazelle plugin to help us keep our build files up to date. Because the plugin isn't available in the modularised skylib, we can't fully transition the project to |
Also, I note that the gazelle plugin is already in its own directory. That's what we do in I'm hoping that |
That's already the case, if a repo is not required to build your target, it won't be fetched. Just like a repo defined in the WORKSPACE file. Just watch out this issue to avoid accidentally making rules_go a hard dependency. |
Alright. So it sounds like a module with a dependency on |
Yes, but it does introduce the transitive dependencies of rules_go and affects the final resolved dependency graph though. But all dependencies are lazily fetched. |
I've opened #400 with the macro exposed in the distribution and the changes required to use it added to the README. |
Closing; the |
Hey @aiuto and @laurentlb (who appear to be OWNERS on this repo),
First, thanks so much for all you're doing in the Bazel ecosystem. I hugely appreciate your efforts. One of the things that I have been thinking about creating for a while was a bazel-gazelle plugin for
skylib
that generatedskylark_library
targets. I think this would be generally useful. In my repo's I've found it helpful to haveskylark_library
targets to feed intostardoc
and manually creating the targets is kind of a drag.Fortunately, Gazelle has a really nice plugin system that can be used to add generation for languages beyond golang. If I were to write a skylib plugin for Gazelle, would this repo be a good place to host it? Since the repo is packaged by
rules_pkg
I could iterate on it and not have it released as part of the distribution bundle until it was deemed to be good enough. Additionally I would be happy to update the distribution scripts to support both a gazelle version and a non-gazelle version to keep down dependencies if that's a concern.Please let me know what you think. Thanks so much!
The text was updated successfully, but these errors were encountered: