@@ -75,7 +75,8 @@ load("@platforms//host:extension.bzl", "host_platform_repo")
75
75
host_platform_repo(name = " host_platform" )
76
76
77
77
# 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()`.
79
80
register_toolchains(" @rules_scala//protoc:all" )
80
81
81
82
load(" @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
225
226
register_toolchains(" @rules_scala//protoc:all" )
226
227
```
227
228
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
+
228
233
#### Specifying additional ` protoc ` platforms
229
234
230
235
Use the ` protoc_platforms ` parameter to specify additional [ platforms] [ ] if the
@@ -480,10 +485,41 @@ maximum available at the time of writing.
480
485
| Bazel versions using Bzlmod<br />(Coming soon! See bazelbuild/rules_scala #1482 .) | 7.5.0, 8.x,<br />` rolling ` , ` last_green ` |
481
486
| Bazel versions using ` WORKSPACE ` | 6.5.0, 7.5.0, 8.x<br />(see the [ notes on 6.5.0 compatibility] ( #6.5.0 ) ) |
482
487
| ` protobuf ` | v30.1 |
483
- | ` abseil-cpp ` | 20250127.0 |
488
+ | ` abseil-cpp ` | 20250127.1 |
484
489
| ` rules_java ` | 8.11.0 |
485
490
| ` ScalaPB ` | 1.0.0-alpha.1 |
486
491
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
+
487
523
## Usage with [ bazel-deps] ( https://github.com/johnynek/bazel-deps )
488
524
489
525
Bazel-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
711
747
` scala_register_toolchains() ` to ensure this toolchain takes precedence. The
712
748
same exact call will also work in ` MODULE.bazel ` .
713
749
714
- ### Disabling Scala version validation when defining a custom Scala toolchain
750
+ ### Disabling builtin Scala toolchains when defining custom Scala toolchains
715
751
716
752
When [ defining a 'scala_toolchain()' using custom compiler JARs] (
717
753
docs/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` :
720
756
721
757
``` py
722
758
# WORKSPACE
723
759
scala_toolchains(
724
- validate_scala_version = False ,
760
+ scala = False ,
725
761
# ...other toolchain parameters...
726
762
)
727
763
```
728
764
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:
731
769
732
770
- Calling ` scala_repositories(load_jar_deps = False) ` would instantiate only
733
771
other ` rules_scala ` dependency repos (` rules_java ` , ` protobuf ` , etc.) and
@@ -896,6 +934,29 @@ supporting Bazel + MSVC builds per:
896
934
Enable [ protocol compiler toolchainization] ( #protoc ) to fix broken Windows
897
935
builds by avoiding ` @com_google_protobuf//:protoc ` recompilation.
898
936
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
+
899
960
### Embedded resource paths no longer begin with ` external/<repo_name> `
900
961
901
962
[ 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.
1022
1083
1023
1084
#### Maximum of ` protobuf ` v29
1024
1085
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:
1028
1088
1029
1089
``` txt
1030
1090
ERROR: Traceback (most recent call last):
@@ -1045,47 +1105,17 @@ ERROR: .../src/java/io/bazel/rulesscala/worker/BUILD:3:13:
1045
1105
and referenced by '//src/java/io/bazel/rulesscala/worker:worker'
1046
1106
```
1047
1107
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
1053
1109
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.
1057
1112
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
1061
1114
1062
- ``` txt
1063
- common --enable_platform_specific_config
1115
+ #### Using older versions of ` protobuf `
1064
1116
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.
1089
1119
1090
1120
### ` scala_proto ` not supported for Scala 2.11
1091
1121
0 commit comments