From 398ee0e443e9d84dda9238457aa24eec903df551 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Mon, 3 Mar 2025 17:23:03 -0500 Subject: [PATCH] Update README, minor protoc toolchain cleanups 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. --- README.md | 26 ++++++++++++++++++-------- protoc/private/protoc_toolchain.bzl | 4 +--- scripts/update_protoc_integrity.py | 10 +++------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 2a55f6655..1351f8dcc 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -667,7 +673,7 @@ register_toolchains( ) ``` -### `@io_bazel_rules_scala_config` is now `@rules_scala_config` +### `@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 @@ -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 @@ -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`: diff --git a/protoc/private/protoc_toolchain.bzl b/protoc/private/protoc_toolchain.bzl index 3ba457856..9bc94affe 100644 --- a/protoc/private/protoc_toolchain.bzl +++ b/protoc/private/protoc_toolchain.bzl @@ -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( @@ -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 diff --git a/scripts/update_protoc_integrity.py b/scripts/update_protoc_integrity.py index 2ee3ff266..d6ff33e6d 100755 --- a/scripts/update_protoc_integrity.py +++ b/scripts/update_protoc_integrity.py @@ -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()