Skip to content

Commit

Permalink
docs: Mention use_repo automation (#3573)
Browse files Browse the repository at this point in the history
* docs: Mention `use_repo` automation

* Update bzlmod.md
  • Loading branch information
fmeum committed May 30, 2023
1 parent f2dcbd6 commit 58b24ea
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions docs/go/core/bzlmod.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Add the following lines to your `MODULE.bazel` file:

```starlark
bazel_dep(name = "rules_go", version = "0.39.1")
bazel_dep(name = "gazelle", version = "0.29.0")
bazel_dep(name = "gazelle", version = "0.31.0")
```

The latest versions are always listed on https://registry.bazel.build/.
Expand All @@ -18,7 +18,7 @@ If you have WORKSPACE dependencies that reference rules_go and/or Gazelle, you c

```starlark
bazel_dep(name = "rules_go", version = "0.39.1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.29.0", repo_name = "bazel_gazelle")
bazel_dep(name = "gazelle", version = "0.31.0", repo_name = "bazel_gazelle")
```

## Registering Go SDKs
Expand Down Expand Up @@ -113,7 +113,8 @@ use_repo(
)
```

There is [ongoing work](https://github.com/bazelbuild/bazel-gazelle/pull/1511) targeted for Bazel 6.2.0 to automate the generation of the `use_repo` statement.
Bazel emits a warning if the `use_repo` statement is out of date or missing entirely (requires Bazel 6.2.0 or higher).
The warning contains a `buildozer` command to automatically fix the `MODULE.bazel` file (requires buildozer 6.1.1 or higher).

Alternatively, you can specify a module extension tag to add an individual dependency.
This can be useful for dependencies of generated code that `go mod tidy` would remove. (There is [ongoing work](https://github.com/bazelbuild/bazel-gazelle/pull/1495) to provide a Bazel-aware version of `tidy`.)
Expand Down Expand Up @@ -169,7 +170,7 @@ go_deps.gazelle_override(
)
```

If you need to use a `gazelle_override` to get a public Go module to build with Bazel, consider contributing the directives to the [public registry for Gazelle directives](https://github.com/bazelbuild/bazel-gazelle/blob/master/internal/bzlmod/directives.bzl) via a PR.
If you need to use a `gazelle_override` to get a public Go module to build with Bazel, consider contributing the directives to the [public registry for default Gazelle overrides](https://github.com/bazelbuild/bazel-gazelle/blob/master/internal/bzlmod/default_gazelle_overrides.bzl) via a PR.
This will allow you to drop the `gazelle_override` tag and also makes the Go module usable in non-root Bazel modules.

### Not yet supported
Expand Down

0 comments on commit 58b24ea

Please sign in to comment.