Skip to content

Commit

Permalink
Update README, minor protoc toolchain cleanups
Browse files Browse the repository at this point in the history
Fixes a broken `single_version_override` link in the README. Added info
explicitly indicating that `repo_mapping` and other mechanisms used to
translate `@rules_scala_config` also apply to translating
`@rules_scala`.

Slightly touches up `protoc_toolchain.bzl` and
`update_protoc_integrity.py.
  • Loading branch information
mbland committed Mar 4, 2025
1 parent 0c0fb6d commit 398ee0e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
26 changes: 18 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ v6.x:

- __`rules_scala` no longer requires the `io_bazel_rules_scala` repository
name__ unless your `BUILD` files or those of your dependencies require it
(bazelbuild/rules_scala#1696).
(bazelbuild/rules_scala#1696). You can use the `repo_mapping` attribute of
`http_archive`, or equivalent Bzlmod mechanisms, to translate `@rules_scala`
to `@io_bazel_rules_scala` for dependencies. The
['@io_bazel_rules_scala_config' is now '@rules_scala_config'](#map) section
below describes these options in detail. (That section is about
`@rules_scala_config`, but the same mechanisms apply.)

- __`rules_scala` v7.0.0 introduces a new `scala_toolchains()` API that is
very different from `rules_scala` 6__. For details on what's changed, see
Expand Down Expand Up @@ -237,6 +242,7 @@ which also requires that the patch be a regular file in your own repo. In other
words, neither `@rules_scala//protoc:0001-protobuf-19679-rm-protoc-dep.patch`
nor an [`alias`][] to it will work.

[`single_version_override`]: https://bazel.build/rules/lib/globals/module#single_version_override
[`alias`]: https://bazel.build/reference/be/general#alias

Assuming you've copied the patch to a file called `protobuf.patch` in the root
Expand Down Expand Up @@ -667,7 +673,7 @@ register_toolchains(
)
```

### `@io_bazel_rules_scala_config` is now `@rules_scala_config`
### <a id="map"></a>`@io_bazel_rules_scala_config` is now `@rules_scala_config`

Since `@io_bazel_rules_scala` is no longer hardcoded in `rules_scala` internals,
we've shortened `@io_bazel_rules_scala_config` to `@rules_scala_config`. This
Expand All @@ -676,7 +682,16 @@ shouldn't affect most users, but it may break some builds using
./docs/cross-compilation.md).

If you can't fix uses of `@io_bazel_rules_scala_config` in your own project
immediately, you can remap `@rules_scala_config` via [`use_repo()`]:
immediately, or have dependencies that need it, there are options.
Use one of the following mechanisms to override it with `@rules_scala_config`.

The same mechanisms also apply if you need to translate `@rules_scala` to
`@io_bazel_rules_scala` for your dependencies.

#### Bzlmod

You can remap `@rules_scala_config` via [`use_repo()`] if you need it in your
own project:

[`use_repo()`]: https://bazel.build/rules/lib/globals/module#use_repo

Expand All @@ -689,11 +704,6 @@ scala_config = use_extension(
use_repo(scala_config, io_bazel_rules_scala_config = "rules_scala_config")
```

If any of your dependencies still require `@io_bazel_rules_scala_config`, use
one of the following mechanisms to override it with `@rules_scala_config`:

#### Bzlmod

For [`bazel_dep()`][] dependencies, use [`override_repo()`][] to
override `@io_bazel_rules_scala_config` with `@rules_scala_config`:

Expand Down
4 changes: 1 addition & 3 deletions protoc/private/protoc_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def _platform_build(platform):
)
return protoc_build

_PROTOC_BUILD_ENTRY_TEMPLATE = """ "{platform}": [\n{specs}\n ],"""

def _download_build(repository_ctx, package, platform, protoc_build):
repository_ctx.download_and_extract(
url = PROTOC_DOWNLOAD_URL.format(
Expand All @@ -41,7 +39,7 @@ def _download_build(repository_ctx, package, platform, protoc_build):
)

def _emit_platform_entry(platform, protoc_build):
return _PROTOC_BUILD_ENTRY_TEMPLATE.format(
return ' "{platform}": [\n{specs}\n ],'.format(
platform = platform,
specs = "\n".join([
' "%s",' % s
Expand Down
10 changes: 3 additions & 7 deletions scripts/update_protoc_integrity.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,10 @@ def get_protoc_integrity(platform, version):
Raises:
`UpdateProtocIntegrityError` if downloading or checksumming fails
"""
try:
url = PROTOC_DOWNLOAD_URL.format(
version = version,
platform = platform
)
print(f'Updating protoc {version} for {platform}:')
print(f' {url}')
url = PROTOC_DOWNLOAD_URL.format(version = version, platform = platform)
print(f'Updating protoc {version} for {platform}:\n {url}')

try:
with urllib.request.urlopen(url) as data:
body = data.read()

Expand Down

0 comments on commit 398ee0e

Please sign in to comment.