Skip to content

Commit ce302c9

Browse files
authored
Simplify CI setup and use prebuilt protoc (#90)
1 parent 7e97c5e commit ce302c9

File tree

8 files changed

+83
-49
lines changed

8 files changed

+83
-49
lines changed

.bazelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ common --check_direct_dependencies=off
1313
# Improve build caching by redacting environment variables.
1414
common --incompatible_strict_action_env
1515

16+
# Avoid building protoc from source.
17+
common --incompatible_enable_proto_toolchain_resolution
18+
19+
# Debug where options came from
20+
common:ci --announce_rc
21+
# Don't rely on test logs being easily accessible from the test runner,
22+
# though it makes the log noisier.
23+
common:ci --test_output=errors
24+
1625
# Load any settings specific to the current user.
1726
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
1827
# This needs to be last statement in this

.github/workflows/ci.bazelrc

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,15 @@ jobs:
2626
matrix:
2727
os: [ubuntu-20.04, macos-12, windows-2022]
2828
bazelversion: [6.4.0, last_rc, last_green]
29-
folder: [".", examples]
30-
exclude:
31-
- os: windows-2022
32-
folder: "."
33-
- os: macos-12
34-
folder: "."
35-
- bazelversion: last_green
36-
folder: "."
37-
- bazelversion: 6.4.0
29+
folder: [examples]
30+
include:
31+
- os: ubuntu-20.04
32+
bazelversion: last_rc
3833
folder: "."
3934

4035
steps:
4136
- uses: actions/checkout@v4
4237

43-
# Cache build artifacts so that the next ci build is incremental.
44-
# Because github action caches cannot be updated after a build, we need to
45-
# store the contents of each build in a unique cache key, then fall back to loading
46-
# it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
47-
# the prefix to load the most recent cache for the branch on a cache miss. You
48-
# should customize the contents of hashFiles to capture any bazel input sources,
49-
# although this doesn't need to be perfect. If none of the input sources change
50-
# then a cache hit will load an existing cache and bazel won't have to do any work.
51-
# In the case of a cache miss, you want the fallback cache to contain most of the
52-
# previously built artifacts to minimize build time. The more precise you are with
53-
# hashFiles sources the less work bazel will have to do.
54-
# We do not cache downloaded external artifacts as these are generally
55-
# faster to download again than to fetch them from the GitHub actions
56-
# cache.
57-
- name: Mount bazel caches
58-
uses: actions/cache@v4
59-
with:
60-
path: |
61-
~/.cache/bazel
62-
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', '**/MODULE.bazel', '**/.bazelrc') }}
63-
restore-keys: bazel-cache-
64-
6538
- name: Configure Bazel version
6639
working-directory: ${{ matrix.folder }}
6740
run: echo "${{ matrix.bazelversion }}" > .bazelversion
@@ -76,9 +49,9 @@ jobs:
7649
7750
- name: bazel test //...
7851
working-directory: ${{ matrix.folder }}
79-
run: bazel --bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...
52+
run: bazel test --config=ci //...
8053

8154
- name: bazel coverage //...
8255
if: matrix.os == 'ubuntu-20.04' && matrix.folder == 'examples'
8356
working-directory: ${{ matrix.folder }}
84-
run: bazel --bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc --bazelrc=.bazelrc coverage //...
57+
run: bazel coverage --config=ci //...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ bazel-*
22
.bazelrc.user
33
.idea/
44
.ijwb/
5+
MODULE.bazel.lock

MODULE.bazel

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,38 @@ bazel_dep(name = "buildifier_prebuilt", version = "6.1.0", dev_dependency = True
1212
bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle")
1313
bazel_dep(name = "platforms", version = "0.0.6", dev_dependency = True)
1414
bazel_dep(name = "rules_testing", version = "0.4.0", dev_dependency = True)
15-
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True)
15+
bazel_dep(name = "stardoc", dev_dependency = True)
16+
git_override(
17+
module_name = "stardoc",
18+
commit = "3baa5d1761970c6285d2ac9c3adccfaac42f54c5",
19+
remote = "https://github.com/bazelbuild/stardoc.git",
20+
)
21+
22+
bazel_dep(name = "rules_java", version = "7.6.1", dev_dependency = True)
23+
bazel_dep(name = "rules_proto", version = "6.0.0", dev_dependency = True)
24+
bazel_dep(name = "toolchains_protoc", version = "0.3.0", dev_dependency = True)
25+
26+
protoc = use_extension(
27+
"@toolchains_protoc//protoc:extensions.bzl",
28+
"protoc",
29+
dev_dependency = True,
30+
)
31+
protoc.toolchain(
32+
# Creates a repository to satisfy well-known-types dependencies such as
33+
# deps=["@com_google_protobuf//:any_proto"]
34+
google_protobuf = "com_google_protobuf",
35+
# Pin to any version of protoc
36+
version = "v26.0",
37+
)
38+
39+
protobuf_java_repos = use_extension(
40+
"//tools:extensions.bzl",
41+
"protobuf_java_repo",
42+
dev_dependency = True,
43+
)
44+
use_repo(protobuf_java_repos, "protobuf_java")
45+
46+
register_toolchains(
47+
"//docs/...",
48+
dev_dependency = True,
49+
)

docs/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
# This load statement must be in the docs/ package rather than anything users depend on
22
# so that the dependency on stardoc doesn't leak to them.
33
load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs")
4+
load("@rules_proto//proto:proto_lang_toolchain.bzl", "proto_lang_toolchain")
45

56
stardoc_with_diff_test(
67
name = "defs",
78
bzl_library_target = "//with_cfg:defs",
89
)
910

1011
update_docs(name = "update")
12+
13+
# Precompiled proto toolchain for stardoc
14+
proto_lang_toolchain(
15+
name = "protoc_java_toolchain",
16+
command_line = "--java_out=$(OUT)",
17+
progress_message = "Generating java_proto_library %{label}",
18+
runtime = "@protobuf_java//jar",
19+
)
20+
21+
toolchain(
22+
name = "protoc_java_toolchain.registration",
23+
toolchain = ":protoc_java_toolchain",
24+
toolchain_type = "@rules_java//java/proto:toolchain_type",
25+
)

examples/.bazelrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ common:windows --noincompatible_strict_action_env
2525
common:windows --test_env=PATH
2626
# Allow build to start before all external deps have been fetched.
2727
common --experimental_merged_skyframe_analysis_execution
28+
29+
# Debug where options came from
30+
common:ci --announce_rc
31+
# Don't rely on test logs being easily accessible from the test runner,
32+
# though it makes the log noisier.
33+
common:ci --test_output=errors

tools/extensions.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
load("@bazel_skylib//lib:modules.bzl", "modules")
2+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")
3+
4+
def _protobuf_java_repo():
5+
http_jar(
6+
name = "protobuf_java",
7+
urls = ["https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.26.1/protobuf-java-4.26.1.jar"],
8+
integrity = "sha256-CRkz5YcK+BB0gyb3rOSmc6ynISUxd1QoQvBEtUbxQoI=",
9+
)
10+
11+
protobuf_java_repo = modules.as_extension(_protobuf_java_repo)

0 commit comments

Comments
 (0)