Skip to content
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

Add the gazelle plugin to the distribution #400

Merged
merged 13 commits into from Nov 7, 2022

Conversation

shs96c
Copy link
Contributor

@shs96c shs96c commented Oct 6, 2022

To avoid everyone needing to take a dep on rules_go, we do the following:

  1. Regular Bazel users need to load bazel_skylib_gazelle_plugin_workspace and call that, and then bazel_skylib_gazelle_plugin_setup

  2. bzlmod users need do nothing, but we now include the rules_go dep in the MODULE.bazel shipped in the release. This is fine, because bzlmod will lazily load dependencies.

MODULE.bazel Show resolved Hide resolved
@shs96c
Copy link
Contributor Author

shs96c commented Oct 14, 2022

Is there anything else I need to do?

@shs96c shs96c requested review from fmeum and nickgooding and removed request for achew22, tetromino, brandjon, comius, hvadehra, c-mita and fmeum October 18, 2022 09:48
Copy link
Contributor

@fmeum fmeum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you may have removed all reviewers with write access to this repo :-)

@@ -51,3 +51,25 @@ gazelle(
name = "gazelle",
gazelle = ":gazelle-skylib",
)

# The files needed for distribution
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would adding allow_empty to the glob be an alternative? It wouldnt' be error-prone in this context.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, allow_empty defaults to True, but I've made it explicit.


def bazel_skylib_gazelle_plugin_setup():
go_rules_dependencies()
go_register_toolchains(version = "1.17.1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried calling this macro from a WORKSPACE that already sets up a Go toolchain somewhere else? You might have to make running this configurable via a parameter.

If possible, also bump the version to 1.18.7 as 1.17 is out of support. 1.19 is available, but requires a relatively recent version of rules_go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and done.

To avoid everyone needing to take a dep on `rules_go`, we
do the following:

1. Regular Bazel users need to load `bazel_skylib_gazelle_plugin_workspace`
   and call that, and then `bazel_skylib_gazelle_plugin_setup`

2. `bzlmod` users need do nothing, but we now include the
   `rules_go` dep in the `MODULE.bazel` shipped in the release.
    This is fine, because `bzlmod` will lazily load
    dependencies.
@shs96c
Copy link
Contributor Author

shs96c commented Oct 18, 2022

@fmeum I thought you could commit to this repo :) Oops. Will add an owner as a reviewer!

@shs96c
Copy link
Contributor Author

shs96c commented Oct 18, 2022

Apparently, I can't add reviewers now in the GH UI, but it looks like @Wyverald can merge changes. Pinging them in this comment :)

@Wyverald
Copy link
Member

Have you tried out the approach we discussed in #250 where the part using gazelle is separated out into its own module? I still think it's rather intrusive to have rules_go in basically everyone's dependency graph.

@shs96c
Copy link
Contributor Author

shs96c commented Oct 18, 2022

As I understand it, bzlmod will only lazily load the dependencies, so it should make any difference to the time it takes to build a project. Having rules_go in the dependency graph will mostly be a no-op. I don't think users will be in the habit of expecting more than one module per repo, so the user experience of this approach is "lower friction" for bzlmod users.

For people not using bzlmod, they need to actively pull in the rules_go dep by calling gazelle_setup: it's not part of the default workflow.

@fmeum
Copy link
Contributor

fmeum commented Oct 18, 2022

I obviously don't like saying that, but unfortunately having a transitive Bzlmod dep on rules_go isn't really a no-op (yet):

  1. Since we are still in a phase of rapid iteration on rules_go's Bzlmod interface, it emits warnings like the following when depended on:
DEBUG: gazelle@0.26.0/MODULE.bazel:6:6: WARNING: The bazel_gazelle Bazel module is still highly experimental and subject to change at any time. Only use it to try out bzlmod for now.
DEBUG: rules_go@0.33.0/MODULE.bazel:7:6: WARNING: The rules_go Bazel module is still highly experimental and subject to change at any time. Only use it to try out bzlmod for now.

We will try to stabilize this shortly after the Bazel 6 release, but I can't promise anything.

  1. I am still working on making the toolchain fetching in rules_go lazy. Currently, it does perform some network I/O if it is depended on even if you don't build Go targets.

At least before both these issues have been fixed introducing a rules_go dependency on a core module such as skylib won't be a good user experience. It should be pretty simple to migrate users off of a separate module though after these limitations have been addressed.

@Wyverald
Copy link
Member

As I understand it, bzlmod will only lazily load the dependencies, so it should make any difference to the time it takes to build a project.

That's true, but as Fabian also pointed out, bringing in other modules sometimes does fetch them eagerly, particularly when toolchains are registered in them. Besides, adding dependencies has other costs -- version resolution takes more time and includes more noise, and a "vendor mode" setup ("download everything for me so that I can work offline") will fetch much more random stuff.

I don't think users will be in the habit of expecting more than one module per repo, [...]

If by "repo" here you mean "git repo" instead of "Bazel repo", we need to normalize the expectation of multiple modules hosted in the same git repository. That would be the only sane way to avoid an explosion of the dependency graph.

@shs96c
Copy link
Contributor Author

shs96c commented Nov 3, 2022

@Wyverald updated to be a two module, one git repo setup.

@shs96c
Copy link
Contributor Author

shs96c commented Nov 3, 2022

The build is failing with last_green because a target in rules_pkg isn't visible:

ERROR: /workdir/distribution/BUILD:17:8: in pkg_tar_impl rule //distribution:bazel-skylib-1.3.0: target '@rules_pkg//private:private_stamp_detect' is not visible from target '//distribution:bazel-skylib-1.3.0'. Check the visibility declaration of the former target if you think the dependency is legitimate
ERROR: /workdir/distribution/BUILD:17:8: Analysis of target '//distribution:bazel-skylib-1.3.0' failed

With last_rc and Bazel 5.3.2, this doesn't appear to be a problem.

@fmeum
Copy link
Contributor

fmeum commented Nov 3, 2022

@shs96c HEAD broke downstream projects, should be fixed in about an hour thanks to bazelbuild/bazel@7dcf0c3.

Copy link
Member

@Wyverald Wyverald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice start!

@@ -0,0 +1,24 @@
bazel_dep(name = "bazel_skylib", version = "1.3.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a module(name="skylib_gazelle", version="...") declaration here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

MODULE.bazel Outdated
@@ -14,8 +14,8 @@ bazel_dep(name = "platforms", version = "0.0.4")
### INTERNAL ONLY - lines after this are not included in the release packaging.

# Gazelle extension is experimental
bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.33.0")
bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.26.0")
bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.35.0")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the plan to remove these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can try removing them and see what breaks....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

WORKSPACE Outdated
@@ -69,17 +69,5 @@ register_unittest_toolchains()
# github.com/bazelbuild/rules_go is available from io_bazel_rules_go and it
# doesn't need to duplicatively fetch it.
# gazelle:repository go_repository name=io_bazel_rules_go importpath=github.com/bazelbuild/rules_go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with gazelle repository hints, do these need to be moved to gazelee/WORKSPACE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved them, and everything still seems to build. Apparently, it's fine to move them.

Copy link
Member

@Wyverald Wyverald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all looks good except for the question about the gazelle hints left over in the WORKSPACE file. thanks!

@Wyverald Wyverald merged commit 60abca8 into bazelbuild:main Nov 7, 2022
@shs96c shs96c mentioned this pull request Nov 8, 2022
@cgrindel
Copy link
Contributor

cgrindel commented Nov 8, 2022

@shs96c Will we be adding instructions on how to load the @bazel_skylib_gazelle_plugin repository into a workspace?

leovitch added a commit to leovitch/bazel-skylib that referenced this pull request Nov 15, 2022
Add the gazelle plugin to the distribution (bazelbuild#400)
tetromino added a commit that referenced this pull request Jan 20, 2023
After #400, the gazelle plugin has been cleanly separated out into its own bazel workspace, which will soon finally allow us to mark it stable. But this means:

* we need to change our bazelci config to explicitly build and test it, since `bazel build //...` no longer includes the plugin;
* we need to add proper distribution rules for it;
* we need to update release instructions, since now we will have two distribution tarballs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants