Skip to content

Commit

Permalink
Simplify CI setup and use prebuilt protoc (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
fmeum authored Jun 11, 2024
1 parent 7e97c5e commit ce302c9
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 49 deletions.
9 changes: 9 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ common --check_direct_dependencies=off
# Improve build caching by redacting environment variables.
common --incompatible_strict_action_env

# Avoid building protoc from source.
common --incompatible_enable_proto_toolchain_resolution

# Debug where options came from
common:ci --announce_rc
# Don't rely on test logs being easily accessible from the test runner,
# though it makes the log noisier.
common:ci --test_output=errors

# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/ci.bazelrc

This file was deleted.

39 changes: 6 additions & 33 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,15 @@ jobs:
matrix:
os: [ubuntu-20.04, macos-12, windows-2022]
bazelversion: [6.4.0, last_rc, last_green]
folder: [".", examples]
exclude:
- os: windows-2022
folder: "."
- os: macos-12
folder: "."
- bazelversion: last_green
folder: "."
- bazelversion: 6.4.0
folder: [examples]
include:
- os: ubuntu-20.04
bazelversion: last_rc
folder: "."

steps:
- uses: actions/checkout@v4

# Cache build artifacts so that the next ci build is incremental.
# Because github action caches cannot be updated after a build, we need to
# store the contents of each build in a unique cache key, then fall back to loading
# it on the next ci run. We use hashFiles(...) in the key and restore-keys- with
# the prefix to load the most recent cache for the branch on a cache miss. You
# should customize the contents of hashFiles to capture any bazel input sources,
# although this doesn't need to be perfect. If none of the input sources change
# then a cache hit will load an existing cache and bazel won't have to do any work.
# In the case of a cache miss, you want the fallback cache to contain most of the
# previously built artifacts to minimize build time. The more precise you are with
# hashFiles sources the less work bazel will have to do.
# We do not cache downloaded external artifacts as these are generally
# faster to download again than to fetch them from the GitHub actions
# cache.
- name: Mount bazel caches
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
key: bazel-cache-${{ hashFiles('**/BUILD.bazel', '**/*.bzl', '**/MODULE.bazel', '**/.bazelrc') }}
restore-keys: bazel-cache-

- name: Configure Bazel version
working-directory: ${{ matrix.folder }}
run: echo "${{ matrix.bazelversion }}" > .bazelversion
Expand All @@ -76,9 +49,9 @@ jobs:
- name: bazel test //...
working-directory: ${{ matrix.folder }}
run: bazel --bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...
run: bazel test --config=ci //...

- name: bazel coverage //...
if: matrix.os == 'ubuntu-20.04' && matrix.folder == 'examples'
working-directory: ${{ matrix.folder }}
run: bazel --bazelrc=${{ github.workspace }}/.github/workflows/ci.bazelrc --bazelrc=.bazelrc coverage //...
run: bazel coverage --config=ci //...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ bazel-*
.bazelrc.user
.idea/
.ijwb/
MODULE.bazel.lock
36 changes: 35 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,38 @@ bazel_dep(name = "buildifier_prebuilt", version = "6.1.0", dev_dependency = True
bazel_dep(name = "gazelle", version = "0.33.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "platforms", version = "0.0.6", dev_dependency = True)
bazel_dep(name = "rules_testing", version = "0.4.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True)
bazel_dep(name = "stardoc", dev_dependency = True)
git_override(
module_name = "stardoc",
commit = "3baa5d1761970c6285d2ac9c3adccfaac42f54c5",
remote = "https://github.com/bazelbuild/stardoc.git",
)

bazel_dep(name = "rules_java", version = "7.6.1", dev_dependency = True)
bazel_dep(name = "rules_proto", version = "6.0.0", dev_dependency = True)
bazel_dep(name = "toolchains_protoc", version = "0.3.0", dev_dependency = True)

protoc = use_extension(
"@toolchains_protoc//protoc:extensions.bzl",
"protoc",
dev_dependency = True,
)
protoc.toolchain(
# Creates a repository to satisfy well-known-types dependencies such as
# deps=["@com_google_protobuf//:any_proto"]
google_protobuf = "com_google_protobuf",
# Pin to any version of protoc
version = "v26.0",
)

protobuf_java_repos = use_extension(
"//tools:extensions.bzl",
"protobuf_java_repo",
dev_dependency = True,
)
use_repo(protobuf_java_repos, "protobuf_java")

register_toolchains(
"//docs/...",
dev_dependency = True,
)
15 changes: 15 additions & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# This load statement must be in the docs/ package rather than anything users depend on
# so that the dependency on stardoc doesn't leak to them.
load("@aspect_bazel_lib//lib:docs.bzl", "stardoc_with_diff_test", "update_docs")
load("@rules_proto//proto:proto_lang_toolchain.bzl", "proto_lang_toolchain")

stardoc_with_diff_test(
name = "defs",
bzl_library_target = "//with_cfg:defs",
)

update_docs(name = "update")

# Precompiled proto toolchain for stardoc
proto_lang_toolchain(
name = "protoc_java_toolchain",
command_line = "--java_out=$(OUT)",
progress_message = "Generating java_proto_library %{label}",
runtime = "@protobuf_java//jar",
)

toolchain(
name = "protoc_java_toolchain.registration",
toolchain = ":protoc_java_toolchain",
toolchain_type = "@rules_java//java/proto:toolchain_type",
)
6 changes: 6 additions & 0 deletions examples/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ common:windows --noincompatible_strict_action_env
common:windows --test_env=PATH
# Allow build to start before all external deps have been fetched.
common --experimental_merged_skyframe_analysis_execution

# Debug where options came from
common:ci --announce_rc
# Don't rely on test logs being easily accessible from the test runner,
# though it makes the log noisier.
common:ci --test_output=errors
11 changes: 11 additions & 0 deletions tools/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@bazel_skylib//lib:modules.bzl", "modules")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_jar")

def _protobuf_java_repo():
http_jar(
name = "protobuf_java",
urls = ["https://repo1.maven.org/maven2/com/google/protobuf/protobuf-java/4.26.1/protobuf-java-4.26.1.jar"],
integrity = "sha256-CRkz5YcK+BB0gyb3rOSmc6ynISUxd1QoQvBEtUbxQoI=",
)

protobuf_java_repo = modules.as_extension(_protobuf_java_repo)

0 comments on commit ce302c9

Please sign in to comment.