Skip to content

Commit 7b7ab2a

Browse files
committed
Add precompiled protoc toolchain
Registers a precompiled protocol compiler toolchain when `--incompatible_enable_proto_toolchain_resolution` is `True`. Part of bazel-contrib#1482 and bazel-contrib#1652. Stops `protoc` recompilation, and fixes the build breakage in bazel-contrib#1710 due to `protobuf` include paths exceeding the Visual Studio path length limit. The updates to `scala_proto/scala_proto_toolchain.bzl` were inspired by: - protocolbuffers/protobuf: bazel: Remove hardcoded dependency on //:protoc from language runtimes #19679 protocolbuffers/protobuf#19679 The `proto_lang_toolchain` call was inspired by the `README` from: - https://github.com/aspect-build/toolchains_protoc/ Adds `scripts/update_protoc_integrity.py` to automatically update `scala/private/protoc/protoc_integrity.bzl`. This should make builds of `rules_scala` much faster all around. Given the fact that this feature depends on recent `protobuf` versions, and the Windows `protobuf` build breaks without it, we have a catch-22. It likely can't be separated from the rest of bazel-contrib#1710, though I would prefer that. It also seems likely that we'd eventually need to do this to continue supporting Windows, per: - protocolbuffers/protobuf#12947 - https://protobuf.dev/news/v30/#poison-msvc--bazel - protocolbuffers/protobuf#20085 More background on proto toolchainization: - Proto Toolchainisation Design Doc https://docs.google.com/document/d/1CE6wJHNfKbUPBr7-mmk_0Yo3a4TaqcTPE0OWNuQkhPs/edit - bazelbuild/bazel: Protobuf repo recompilation sensitivity bazelbuild/bazel#7095 - bazelbuild/rules_proto: Implement proto toolchainisation bazelbuild/rules_proto#179 - rules_proto 6.0.0 release notes mentioning Protobuf Toolchainisation https://github.com/bazelbuild/rules_proto/releases/tag/6.0.0
1 parent b55ab59 commit 7b7ab2a

File tree

23 files changed

+595
-9
lines changed

23 files changed

+595
-9
lines changed

.bazelrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# https://github.com/bazelbuild/rules_scala/issues/1482
33
common --enable_workspace --noenable_bzlmod
44

5+
# Remove once proto toolchainization becomes the default
6+
# - https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution
7+
# - https://docs.google.com/document/d/1CE6wJHNfKbUPBr7-mmk_0Yo3a4TaqcTPE0OWNuQkhPs/edit
8+
common --incompatible_enable_proto_toolchain_resolution
9+
510
build --enable_platform_specific_config
611

712
#Windows needs --worker_quit_after_build due to workers not being shut down when the compiler tools need to be rebuilt (resulting in 'file in use' errors). See Bazel Issue#10498.

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
6262

6363
rules_scala_dependencies()
6464

65+
# The next two calls instantiate the `@host_platform` repo to work around:
66+
# - https://github.com/bazelbuild/bazel/issues/22558
67+
# Only required if using `--incompatible_enable_proto_toolchain_resolution`.
68+
load("@platforms//host:extension.bzl", "host_platform_repo")
69+
70+
host_platform_repo(name = "host_platform")
71+
6572
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
6673

6774
rules_java_dependencies()
@@ -168,6 +175,40 @@ load(
168175
)
169176
```
170177

178+
### <a id="protoc"></a>Using a precompiled protocol compiler
179+
180+
`rules_scala` now supports
181+
[`--incompatible_enable_proto_toolchain_resolution`][]. When using this flag,
182+
`rules_scala` will use a precompiled protocol compiler binary by default. To set
183+
it in your `.bazelrc` file:
184+
185+
[`--incompatible_enable_proto_toolchain_resolution`]: https://bazel.build/reference/command-line-reference#flag--incompatible_enable_proto_toolchain_resolution
186+
187+
```txt
188+
common --incompatible_enable_proto_toolchain_resolution
189+
```
190+
191+
Set the `protoc_platforms` attribute of `scala_toolchains()` if you need to
192+
configure protocol compilers for platforms other than the host platform.
193+
194+
Windows builds now require the precompiled protocol compiler toolchain. See the
195+
[Windows MSVC builds of protobuf broken by default](#protoc-msvc) section
196+
below for details.
197+
198+
More background on proto toolchainization:
199+
200+
- [Proto Toolchainisation Design Doc](
201+
https://docs.google.com/document/d/1CE6wJHNfKbUPBr7-mmk_0Yo3a4TaqcTPE0OWNuQkhPs/edit)
202+
203+
- [bazelbuild/bazel#7095: Protobuf repo recompilation sensitivity](
204+
https://github.com/bazelbuild/bazel/issues/7095)
205+
206+
- [bazelbuild/rules_proto#179: Implement proto toolchainisation](
207+
https://github.com/bazelbuild/rules_proto/issues/179)
208+
209+
- [rules_proto 6.0.0 release notes mentioning Protobuf Toolchainization](
210+
https://github.com/bazelbuild/rules_proto/releases/tag/6.0.0)
211+
171212
### Persistent workers
172213

173214
To run with a persistent worker (much faster), add the following to
@@ -567,6 +608,25 @@ http_archive(
567608
)
568609
```
569610

611+
### <a id="protoc-msvc"></a>Windows MSVC builds of `protobuf` broken by default
612+
613+
MSVC builds of recent `protobuf` versions started failing, as first noted in
614+
bazelbuild/rules_scala#1710. On top of that, `protobuf` is planning to stop
615+
supporting Bazel + MSVC builds per:
616+
617+
- [protocolbuffers/protobuf#12947: src build on windows not working](
618+
https://github.com/protocolbuffers/protobuf/issues/12947)
619+
620+
- [protobuf.dev News Announcements for Version 30.x:Poison MSVC + Bazel](
621+
https://protobuf.dev/news/v30/#poison-msvc--bazel)
622+
623+
- [protocolbuffers/protobuf#20085: Breaking Change: Dropping support for
624+
Bazel+MSVC](https://github.com/protocolbuffers/protobuf/issues/20085)
625+
626+
Enable [protocol compiler toolchainization](#protoc) to avoid recompiling
627+
`@com_google_protobuf//:protoc` on Windows platforms and fix broken Windows
628+
builds.
629+
570630
### Bzlmod configuration (coming soon!)
571631

572632
The upcoming Bzlmod implementation will funnel through the `scala_toolchains()`

WORKSPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ load("//scala:deps.bzl", "rules_scala_dependencies")
55

66
rules_scala_dependencies()
77

8+
# The next two calls instantiate the `@host_platform` repo to work around:
9+
# - https://github.com/bazelbuild/bazel/issues/22558
10+
# Only required if using `--incompatible_enable_proto_toolchain_resolution`.
11+
load("@platforms//host:extension.bzl", "host_platform_repo")
12+
13+
host_platform_repo(name = "host_platform")
14+
815
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
916

1017
rules_java_dependencies()

dt_patches/test_dt_patches/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
1111

1212
rules_scala_dependencies()
1313

14+
load("@platforms//host:extension.bzl", "host_platform_repo")
15+
16+
host_platform_repo(name = "host_platform")
17+
1418
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
1519

1620
rules_java_dependencies()

dt_patches/test_dt_patches_user_srcjar/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
1111

1212
rules_scala_dependencies()
1313

14+
load("@platforms//host:extension.bzl", "host_platform_repo")
15+
16+
host_platform_repo(name = "host_platform")
17+
1418
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
1519

1620
rules_java_dependencies()

examples/crossbuild/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
1111

1212
rules_scala_dependencies()
1313

14+
load("@platforms//host:extension.bzl", "host_platform_repo")
15+
16+
host_platform_repo(name = "host_platform")
17+
1418
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
1519

1620
rules_java_dependencies()

examples/overridden_artifacts/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
1111

1212
rules_scala_dependencies()
1313

14+
load("@platforms//host:extension.bzl", "host_platform_repo")
15+
16+
host_platform_repo(name = "host_platform")
17+
1418
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
1519

1620
rules_java_dependencies()

examples/scala3/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
1111

1212
rules_scala_dependencies()
1313

14+
load("@platforms//host:extension.bzl", "host_platform_repo")
15+
16+
host_platform_repo(name = "host_platform")
17+
1418
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
1519

1620
rules_java_dependencies()

examples/semanticdb/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
1111

1212
rules_scala_dependencies()
1313

14+
load("@platforms//host:extension.bzl", "host_platform_repo")
15+
16+
host_platform_repo(name = "host_platform")
17+
1418
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
1519

1620
rules_java_dependencies()

examples/testing/multi_frameworks_toolchain/WORKSPACE

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ load("@rules_scala//scala:deps.bzl", "rules_scala_dependencies")
1111

1212
rules_scala_dependencies()
1313

14+
load("@platforms//host:extension.bzl", "host_platform_repo")
15+
16+
host_platform_repo(name = "host_platform")
17+
1418
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
1519

1620
rules_java_dependencies()

0 commit comments

Comments
 (0)