Skip to content

Instantly share code, notes, and snippets.

@mbland
Last active January 27, 2026 17:50
Show Gist options
  • Select an option

  • Save mbland/13b540bdde04a85f80dd19896a906791 to your computer and use it in GitHub Desktop.

Select an option

Save mbland/13b540bdde04a85f80dd19896a906791 to your computer and use it in GitHub Desktop.
rules_scala#1803 + protobuf v33.4 prebuilt protoc example
common --@protobuf//bazel/toolchains:prefer_prebuilt_protoc
common --per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT
common --host_per_file_copt=external/.*protobuf.*@--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT
common --per_file_copt=external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT
common --host_per_file_copt=external/.*grpc.*@--GRPC_WAS_NOT_SUPPOSED_TO_BE_BUILT
# Not necessary for Bazel 9. Required for earlier Bazels and rolling releases
# before 10.0.0-pre.20251217.3, which contains
# bazelbuild/bazel@13aa2d7c8b31c67a34c7d19acf291b74e5816654 (cherry-picked into
# 9.0.0 as bazelbuild/bazel@b43bf6191562a9c994399fec1408b0d4c6c46c0a).
common --incompatible_enable_proto_toolchain_resolution
MODULE.bazel.lock
bazel-*

bazel-contrib/rules_scala#1803 + protobuf v33.4 prebuilt protoc example

Install Bazelisk, then run the following command, and you should see:

# With Bazel 9.0.0 from `.bazelversion`, and when prefixed with
# `USE_BAZEL_VERSION=10.0.0=pre.20251208.3`:
$ bazel build :test_scala_proto

Starting local Bazel server (9.0.0) and connecting to it...
INFO: Analyzed target //:test_scala_proto
  (224 packages loaded, 4667 targets configured, 30 aspect applications).
[ ...snip... ]
INFO: Found 1 target...
Target //:test_scala_proto up-to-date:
  bazel-bin/test_proto_scalapb.jar
  bazel-bin/test_proto_scalapb-src.jar
INFO: Elapsed time: 14.107s, Critical Path: 8.14s
INFO: 201 processes: 87 internal, 99 darwin-sandbox, 15 worker.
INFO: Build completed successfully, 201 total actions

$ USE_BAZEL_VERSION=10.0.0-pre.20251217.3 bazel build :test_scala_proto

Starting local Bazel server (10.0.0-pre.20251217.3) and connecting to it...
INFO: Analyzed target //:test_scala_proto
  (202 packages loaded, 5747 targets and 30 aspects configured).
ERROR: .../external/protobuf+/upb/mem/BUILD:14:11:
  Compiling upb/mem/alloc.c [for tool] failed: (Exit 1):
  wrapped_clang failed: error executing CppCompile command
    (from cc_library rule target @@protobuf+//upb/mem:mem)
[ ...snip... ]

clang: error: unknown argument: '--PROTOBUF_WAS_NOT_SUPPOSED_TO_BE_BUILT'
Error in child process '/usr/bin/xcrun'. 1 
[ ...snip... ]
Target //:test_scala_proto failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 7.488s, Critical Path: 0.14s
INFO: 24 processes: 306 action cache hit, 23 internal, 1 darwin-sandbox.
ERROR: Build did NOT complete successfully
load("@protobuf//bazel:proto_library.bzl", "proto_library")
load("@rules_scala//scala:providers.bzl", "declare_deps_provider")
load("@rules_scala//scala_proto:scala_proto.bzl", "scala_proto_library")
load(
"@rules_scala//scala_proto:scala_proto_toolchain.bzl",
"scala_proto_deps_toolchain",
"scala_proto_toolchain",
)
declare_deps_provider(
name = "scalapb_worker_deps_provider",
deps_id = "scalapb_worker_deps",
deps = [
"@example_maven//:com_thesamet_scalapb_compilerplugin_2_13",
"@example_maven//:com_thesamet_scalapb_protoc_bridge_2_13",
"@example_maven//:com_thesamet_scalapb_protoc_gen_2_13",
"@protobuf//java/core",
],
)
declare_deps_provider(
name = "scalapb_compile_deps_provider",
deps_id = "scalapb_compile_deps",
deps = [
"@example_maven//:com_thesamet_scalapb_lenses_2_13",
"@example_maven//:com_thesamet_scalapb_scalapb_runtime_2_13",
"@example_maven//:org_scala_lang_scala_library",
"@protobuf//java/core",
],
)
scala_proto_deps_toolchain(
name = "scala_proto_deps_toolchain_def",
dep_providers = [
":scalapb_worker_deps_provider",
":scalapb_compile_deps_provider",
],
)
toolchain(
name = "scala_proto_deps_toolchain",
toolchain = ":scala_proto_deps_toolchain_def",
toolchain_type = "@rules_scala//scala_proto:deps_toolchain_type",
)
scala_proto_toolchain(
name = "scala_proto_toolchain_def",
generators = {
"scala": "scalapb.ScalaPbCodeGenerator",
},
generators_opts = {
"scala": [
"flat_package",
],
},
)
toolchain(
name = "scala_proto_toolchain",
toolchain = ":scala_proto_toolchain_def",
toolchain_type = "@rules_scala//scala_proto:toolchain_type",
)
proto_library(
name = "test_proto",
srcs = ["test.proto"],
)
scala_proto_library(
name = "test_scala_proto",
deps = [":test_proto"],
)
module(name = "prebuilt_protoc_toolchain_example")
bazel_dep(name = "rules_scala")
git_override(
module_name = "rules_scala",
commit = "ee30d0ebc99c2b5729f0663a624545e3f11be8e9",
remote = "https://github.com/mbland/rules_scala",
)
bazel_dep(name = "protobuf", version = "33.4")
scala_config = use_extension(
"@rules_scala//scala/extensions:config.bzl",
"scala_config",
)
scala_config.settings(
scala_version = "2.13.17",
)
scala_deps = use_extension(
"@rules_scala//scala/extensions:deps.bzl",
"scala_deps",
dev_dependency = True,
)
scala_deps.scala()
bazel_dep(name = "rules_jvm_external", version = "6.9")
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
name = "example_maven",
artifacts = [
"com.google.protobuf:protobuf-java:4.33.4",
"com.thesamet.scalapb:compilerplugin_2.13:1.0.0-alpha.3",
"com.thesamet.scalapb:lenses_2.13:1.0.0-alpha.3",
"com.thesamet.scalapb:protoc-bridge_2.13:0.9.9",
"com.thesamet.scalapb:protoc-gen_2.13:0.9.9",
"com.thesamet.scalapb:scalapb-runtime_2.13:1.0.0-alpha.3",
"org.scala-lang:scala-library:2.13.17",
],
)
use_repo(maven, "example_maven")
register_toolchains("//:all")
syntax = "proto3";
message Message {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment