@@ -75,7 +75,8 @@ load("@platforms//host:extension.bzl", "host_platform_repo")
7575host_platform_repo(name = " host_platform" )
7676
7777# This is optional, but still safe to include even when not using
78- # `--incompatible_enable_proto_toolchain_resolution`.
78+ # `--incompatible_enable_proto_toolchain_resolution`. Requires calling
79+ # `scala_toolchains()`.
7980register_toolchains(" @rules_scala//protoc:all" )
8081
8182load(" @rules_java//java:rules_java_deps.bzl" , " rules_java_dependencies" )
@@ -225,6 +226,10 @@ other toolchain registrations. It's safe to include even when not using
225226register_toolchains(" @rules_scala//protoc:all" )
226227```
227228
229+ Note that you _ must_ call ` scala_toolchains() ` in ` WORKSPACE ` , even if all other
230+ toolchains are disabled (i.e., if using ` scala_toolchains(scala = False) ` ). This
231+ isn't necessary under Bzlmod.
232+
228233#### Specifying additional ` protoc ` platforms
229234
230235Use the ` protoc_platforms ` parameter to specify additional [ platforms] [ ] if the
@@ -480,10 +485,41 @@ maximum available at the time of writing.
480485| Bazel versions using Bzlmod<br />(Coming soon! See bazelbuild/rules_scala #1482 .) | 7.5.0, 8.x,<br />` rolling ` , ` last_green ` |
481486| Bazel versions using ` WORKSPACE ` | 6.5.0, 7.5.0, 8.x<br />(see the [ notes on 6.5.0 compatibility] ( #6.5.0 ) ) |
482487| ` protobuf ` | v30.1 |
483- | ` abseil-cpp ` | 20250127.0 |
488+ | ` abseil-cpp ` | 20250127.1 |
484489| ` rules_java ` | 8.11.0 |
485490| ` ScalaPB ` | 1.0.0-alpha.1 |
486491
492+ ### Using a prebuilt ` @com_google_protobuf//:protoc ` or C++ compiler flags
493+
494+ Newer versions of ` abseil-cpp ` , required by newer versions of
495+ ` @com_google_protobuf//:protoc ` , fail to compile under Bazel 6.5.0 and 7.5.0 by
496+ default. [ protoc will also fail to build on Windows when using
497+ MSVC] ( #protoc-msvc ) . You will have to choose one of the following approaches to
498+ resolve this problem.
499+
500+ You may use protocol compiler toolchainization with ` protobuf ` v29 or later to
501+ avoid recompiling ` protoc ` . You may want to enable this even if your build
502+ doesn't break, as it saves time by avoiding frequent ` protoc ` recompilation. See
503+ the [ Using a precompiled protocol compiler] ( #protoc ) section for details.
504+
505+ Otherwise, if migrating to Bazel 8 isn't an immediate option, you will need to
506+ set the following compiler flags in ` .bazelrc ` per bazelbuild/rules_scala #1647 :
507+
508+ ``` txt
509+ common --enable_platform_specific_config
510+
511+ common:linux --cxxopt=-std=c++17
512+ common:linux --host_cxxopt=-std=c++17
513+ common:macos --cxxopt=-std=c++17
514+ common:macos --host_cxxopt=-std=c++17
515+ common:windows --cxxopt=/std=c++17
516+ common:windows --host_cxxopt=/std=c++17
517+ ```
518+
519+ Note that this example uses ` common: ` config settings instead of ` build: ` . This
520+ seems to prevent invalidating the action cache between ` bazel ` runs, which
521+ improves performance.
522+
487523## Usage with [ bazel-deps] ( https://github.com/johnynek/bazel-deps )
488524
489525Bazel-deps allows you to generate bazel dependencies transitively for maven artifacts. Generally we don't want bazel-deps to fetch
@@ -711,23 +747,25 @@ In `WORKSPACE`, this `register_toolchains()` call must come before calling
711747` scala_register_toolchains() ` to ensure this toolchain takes precedence. The
712748same exact call will also work in ` MODULE.bazel ` .
713749
714- ### Disabling Scala version validation when defining a custom Scala toolchain
750+ ### Disabling builtin Scala toolchains when defining custom Scala toolchains
715751
716752When [ defining a 'scala_toolchain()' using custom compiler JARs] (
717753docs/scala_toolchain.md#b-defining-your-own-scala_toolchain), while using
718- ` scala_toolchains() ` to instantiate other builtin toolchains, set
719- ` validate_scala_version = False` :
754+ ` scala_toolchains() ` to instantiate builtin toolchains (like the [ protoc
755+ toolchain ] ( #protoc ) ), set ` scala = False` :
720756
721757``` py
722758# WORKSPACE
723759scala_toolchains(
724- validate_scala_version = False ,
760+ scala = False ,
725761 # ...other toolchain parameters...
726762)
727763```
728764
729- This differs from the previous API in two ways that avoided instantiating the
730- default Scala compiler JAR repositories, and thus Scala version validation:
765+ This avoids instantiating the default Scala toolchain and compiler JAR
766+ repositories and a corresponding Scala version check, which may fail when
767+ defining a custom toolchain. It's equivalent to two ways in which the previous
768+ API avoided the same default behavior:
731769
732770- Calling ` scala_repositories(load_jar_deps = False) ` would instantiate only
733771 other ` rules_scala ` dependency repos (` rules_java ` , ` protobuf ` , etc.) and
@@ -896,6 +934,29 @@ supporting Bazel + MSVC builds per:
896934Enable [ protocol compiler toolchainization] ( #protoc ) to fix broken Windows
897935builds by avoiding ` @com_google_protobuf//:protoc ` recompilation.
898936
937+ ### Minimum of ` protobuf ` v28
938+
939+ ` rules_scala ` requires at least ` protobuf ` v28, which contains the
940+ ` bazel/common/proto_common.bzl ` required for [ protocol compiler
941+ toolchain] ( #protoc ) support. This file appeared in v27, and no ` ScalaPB ` release
942+ supports ` protobuf ` v25.6, v26, or v27.
943+
944+ #### Using earlier ` protobuf ` versions
945+
946+ If you can't update to ` protobuf ` v28 or later right now, you will need to patch:
947+
948+ - ` scala/toolchains.bzl ` : remove ` setup_protoc_toolchains() ` references
949+ - ` protoc/BUILD ` : remove entirely
950+
951+ Then build using Bazel 7 and the following maximum versions of key dependencies:
952+
953+ | Dependency | Max compatible version | Reason |
954+ | :-: | :-: | :- |
955+ | ` protobuf ` | v25.5 | Maximum version supported by ` ScalaPB ` 0.11.17. |
956+ | ` rules_java ` | 7.12.4 | 8.x requires ` protobuf ` v27 and later. |
957+ | ` rules_cc ` | 0.0.9 | 0.0.10 requires Bazel 7 to define ` CcSharedLibraryHintInfo ` .<br />0.0.13 requires at least ` protobuf ` v27.0. |
958+ | ` ScalaPB ` | 0.11.17<br />(0.9.8 for Scala 2.11) | Later versions only support ` protobuf ` >= v28. |
959+
899960### Embedded resource paths no longer begin with ` external/<repo_name> `
900961
901962[ Any program compiled with an external repo asset in its 'resources' attribute
@@ -1022,9 +1083,8 @@ not out of the box, and may break at any time.
10221083
10231084#### Maximum of ` protobuf ` v29
10241085
1025- First of all, you _ must_ use ` protobuf ` v29 or earlier. ` rules_scala ` now uses
1026- v30 by default, which removes ` py_proto_library ` and other symbols that Bazel
1027- 6.5.0 requires:
1086+ You _ must_ use ` protobuf ` v29 or earlier. ` rules_scala ` now uses v30 by default,
1087+ which removes ` py_proto_library ` and other symbols that Bazel 6.5.0 requires:
10281088
10291089``` txt
10301090ERROR: Traceback (most recent call last):
@@ -1045,47 +1105,17 @@ ERROR: .../src/java/io/bazel/rulesscala/worker/BUILD:3:13:
10451105 and referenced by '//src/java/io/bazel/rulesscala/worker:worker'
10461106```
10471107
1048- #### Using a prebuilt ` @com_google_protobuf//:protoc ` or C++ compiler flags
1049-
1050- Newer versions of ` @com_google_protobuf//:protoc ` fail to compile under Bazel
1051- 6.5.0 by default. You will have to choose one of the following approaches to
1052- resolve this problem, if migrating to Bazel 7 or 8 isn't an immediate option.
1108+ #### Configuring the protocol compiler toolchain
10531109
1054- You may use protocol compiler toolchainization with ` protobuf ` v29 to avoid
1055- recompiling ` protoc ` . See the [ Using a precompiled protocol compiler] ( #protoc )
1056- section for details.
1110+ See [ Using a prebuilt @com_google_protobuf//: protoc or C++ compiler
1111+ flags] [ protoc-opts ] for protocol compiler configuration requirements.
10571112
1058- Otherwise, per bazelbuild/rules_scala #1647 , add the following flags to
1059- ` .bazelrc ` to compile the newer ` abseil-cpp ` versions used by newer ` protobuf `
1060- versions:
1113+ [ protoc-opts ] : #using-a-prebuilt-com_google_protobufprotoc-or-c-compiler-flags
10611114
1062- ``` txt
1063- common --enable_platform_specific_config
1115+ #### Using older versions of ` protobuf `
10641116
1065- common:linux --cxxopt=-std=c++17
1066- common:linux --host_cxxopt=-std=c++17
1067- common:macos --cxxopt=-std=c++17
1068- common:macos --host_cxxopt=-std=c++17
1069- common:windows --cxxopt=/std=c++17
1070- common:windows --host_cxxopt=/std=c++17
1071- ```
1072-
1073- Note that this example uses ` common: ` config settings instead of ` build: ` . This
1074- seems to prevent invalidating the action cache between ` bazel ` runs, which
1075- improves performance.
1076-
1077- #### Using older ` protobuf ` versions
1078-
1079- If you have a dependency that requires ` protobuf ` version before v28, use the
1080- following maximum versions of key dependencies. Note that no ` ScalaPB ` release
1081- supports ` protobuf ` v25.6, v26, or v27.
1082-
1083- | Dependency | Max compatible version | Reason |
1084- | :-: | :-: | :- |
1085- | ` protobuf ` | v25.5 | Maximum version supported by ` ScalaPB ` 0.11.17. |
1086- | ` rules_java ` | 7.12.4 | 8.x requires ` protobuf ` v27 and later. |
1087- | ` rules_cc ` | 0.0.9 | 0.0.10 requires Bazel 7 to define ` CcSharedLibraryHintInfo ` .<br />0.0.13 requires at least ` protobuf ` v27.0. |
1088- | ` ScalaPB ` | 0.11.17<br />(0.9.8 for Scala 2.11) | Later versions only support ` protobuf ` >= v28. |
1117+ See [ Minimum of protobuf v28] ( #minimum-of-protobuf-v28 ) for details on using
1118+ older versions of protobuf.
10891119
10901120### ` scala_proto ` not supported for Scala 2.11
10911121
0 commit comments