Skip to content

refactor: enable protoc toolchains #614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ common --@aspect_rules_ts//ts:default_to_tsc_transpiler
# We have some empty globs in this repo
common --noincompatible_disallow_empty_glob

# Never Compile protoc Again
common --incompatible_enable_proto_toolchain_resolution

# Ugh, stardoc needs to compile Java sources.
# Don't depend on a JAVA_HOME pointing at a system JDK
# see https://github.com/bazelbuild/rules_jvm_external/issues/445
build --repo_env=JAVA_HOME=../bazel_tools/jdk

# verbose
common:verbose --@aspect_rules_ts//ts:verbose --worker_verbose

Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ jobs:
- bazel-version:
major: 6
config: rbe
# Dont' test root workspace with Bazel 6 to reduce the size of the test matrix
- bazel-version:
major: 6
folder: .
# Don't run bzlmod tests with Bazel 6 to reduce the size of the test matrix
- bazel-version:
major: 6
Expand Down Expand Up @@ -186,8 +190,8 @@ jobs:
--bazelrc=${GITHUB_WORKSPACE//\\/\/}/.github/workflows/ci.bazelrc \
test \
--config=${{ matrix.config }} \
--test_tag_filters=-skip-on-${{ matrix.config }},-skip-on-bazel${{ matrix.bazel-version.major }} \
--build_tag_filters=-skip-on-${{ matrix.config }},-skip-on-bazel${{ matrix.bazel-version.major }} \
--test_tag_filters=-skip-on-${{ matrix.config }},-skip-on-bazel${{ matrix.bazel-version.major }},-skip-on-bzlmod-${{ matrix.bzlmod }} \
--build_tag_filters=-skip-on-${{ matrix.config }},-skip-on-bazel${{ matrix.bazel-version.major }},-skip-on-bzlmod-${{ matrix.bzlmod }} \
--enable_bzlmod=${{ matrix.bzlmod }} \
//...
env:
Expand Down
16 changes: 16 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ bazel_dep(name = "gazelle", version = "0.36.0", dev_dependency = True, repo_name
bazel_dep(name = "rules_go", version = "0.46.0", dev_dependency = True, repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_nodejs", version = "6.1.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "toolchains_protoc", version = "0.3.0", dev_dependency = True)

# Should not be required, stardoc leaks a dependency
bazel_dep(name = "rules_java", version = "7.6.1", dev_dependency = True)

register_toolchains(
"//tools/toolchains:all",
dev_dependency = True,
)

# pick up fix: https://github.com/bazelbuild/stardoc/pull/221
git_override(
module_name = "stardoc",
commit = "3baa5d1761970c6285d2ac9c3adccfaac42f54c5",
remote = "https://github.com/bazelbuild/stardoc.git",
)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
Expand Down
35 changes: 29 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,35 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

######################
# toolchains_protoc setup #
######################
# Fetches the toolchains_protoc dependencies.
# If you want to have a different version of some dependency,
# you should fetch it *before* calling this.
# Alternatively, you can skip calling this function, so long as you've
# already fetched all the dependencies.
load("@toolchains_protoc//protoc:repositories.bzl", "rules_protoc_dependencies")

rules_protoc_dependencies()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

rules_proto_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

load("@toolchains_protoc//protoc:toolchain.bzl", "protoc_toolchains")

protoc_toolchains(
name = "protoc_toolchains",
version = "v25.3",
)

register_toolchains("//tools/toolchains:all")

############################################
# Gazelle, for generating bzl_library targets
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
Expand Down Expand Up @@ -100,14 +129,8 @@ npm_repositories()
# bazel run -- @npm_typescript//:tsc --version
rules_ts_dependencies(ts_version_from = "@npm//examples:typescript/resolved.json")

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

###########################################
# Protobuf rules to test ts_proto_library
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

rules_proto_dependencies()

# rules_lint
Expand Down
8 changes: 8 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
load("//.github/workflows:deps.bzl", "aspect_workflows_github_actions_deps")

aspect_workflows_github_actions_deps()
Expand All @@ -9,3 +10,10 @@ load(
)

fetch_shfmt()

# Needed for stardoc to compile from Java sources
http_jar(
name = "protobuf-java",
integrity = "sha256-kHLmD+Zs/11sDxGh3yHY8+Sym17ngrRcP8dfWfviuDk=",
urls = ["https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.27.0/protobuf-java-4.27.0.jar"],
)
4 changes: 4 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ stardoc_with_diff_test(
bzl_library_target = "//ts:defs",
tags = [
"skip-on-bazel6",
"skip-on-bzlmod-0",
"skip-on-rbe",
],
)
Expand All @@ -16,6 +17,7 @@ stardoc_with_diff_test(
bzl_library_target = "//ts:proto",
tags = [
"skip-on-bazel6",
"skip-on-bzlmod-0",
"skip-on-rbe",
],
)
Expand All @@ -26,6 +28,7 @@ stardoc_with_diff_test(
symbol_names = ["rules_ts_dependencies"],
tags = [
"skip-on-bazel6",
"skip-on-bzlmod-0",
"skip-on-rbe",
],
)
Expand All @@ -34,6 +37,7 @@ update_docs(
name = "update",
tags = [
"skip-on-bazel6",
"skip-on-bzlmod-0",
"skip-on-rbe",
],
)
Expand Down
24 changes: 23 additions & 1 deletion internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Users should *not* need to install these. If users see a load()
statement from these, that's a bug in our distribution.
"""

load("@bazel_tools//tools/build_defs/repo:http.bzl", _http_archive = "http_archive")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar", _http_archive = "http_archive")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("//.github/workflows:deps.bzl", "aspect_workflows_github_actions_deps")

Expand Down Expand Up @@ -72,4 +72,26 @@ def rules_ts_internal_deps():
url = "https://github.com/aspect-build/rules_swc/releases/download/v1.0.1/rules_swc-v1.0.1.tar.gz",
)

http_archive(
name = "toolchains_protoc",
sha256 = "117af61ee2f1b9b014dcac7c9146f374875551abb8a30e51d1b3c5946d25b142",
strip_prefix = "toolchains_protoc-0.3.0",
url = "https://github.com/aspect-build/toolchains_protoc/releases/download/v0.3.0/toolchains_protoc-v0.3.0.tar.gz",
)

http_archive(
name = "rules_java",
urls = [
"https://github.com/bazelbuild/rules_java/releases/download/7.6.1/rules_java-7.6.1.tar.gz",
],
sha256 = "f8ae9ed3887df02f40de9f4f7ac3873e6dd7a471f9cddf63952538b94b59aeb3",
)

# Needed for stardoc to compile from Java sources
http_jar(
name = "protobuf-java",
integrity = "sha256-kHLmD+Zs/11sDxGh3yHY8+Sym17ngrRcP8dfWfviuDk=",
urls = ["https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.27.0/protobuf-java-4.27.0.jar"],
)

aspect_workflows_github_actions_deps()
9 changes: 9 additions & 0 deletions tools/toolchains/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain")

proto_lang_toolchain(
name = "protoc_java_toolchain",
command_line = "--java_out=%s",
progress_message = "Generating Java proto_library %{label}",
runtime = "@protobuf-java//jar",
toolchain_type = "@rules_java//java/proto:toolchain_type",
)
Loading