Skip to content

Commit

Permalink
feat: test bzlmod usage on CI (#16319)
Browse files Browse the repository at this point in the history
Closes #16319

COPYBARA_INTEGRATE_REVIEW=#16319 from protocolbuffers:bcr d66845c
PiperOrigin-RevId: 619939078
  • Loading branch information
alexeagle authored and copybara-github committed Mar 28, 2024
1 parent 6262097 commit 71e4061
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 2 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test_bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Bazel

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main]
pull_request:
branches: [main]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

concurrency:
# Cancel previous actions from the same PR or branch except 'main' branch.
# See https://docs.github.com/en/actions/using-jobs/using-concurrency and https://docs.github.com/en/actions/learn-github-actions/contexts for more info.
group: concurrency-group::${{ github.workflow }}::${{ github.event.pull_request.number > 0 && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}${{ github.ref_name == 'main' && format('::{0}', github.run_id) || ''}}
cancel-in-progress: ${{ github.ref_name != 'main' }}

jobs:
test:
uses: bazel-contrib/.github/.github/workflows/bazel.yaml@v6
with:
folders: '["examples"]'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,6 @@ compile_commands.json

# Ignore GHA NodeJS files
.github/**/node_modules/

# Ignore Bzlmod lock file until it is more stable
MODULE.bazel.lock
21 changes: 21 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
# https://github.com/protocolbuffers/protobuf/issues/14313
module(
name = "protobuf",
compatibility_level = 1,
version = "27.0",
)

# LOWER BOUND dependency versions.
# Bzlmod follows MVS:
# https://bazel.build/versions/6.0.0/build/bzlmod#version-resolution
# Thus the highest version in their module graph is resolved.
bazel_dep(name = "abseil-cpp", repo_name = "com_google_absl", version = "20230802.0.bcr.1")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "jsoncpp", version = "1.9.5")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_java", version = "4.0.0")
bazel_dep(name = "rules_jvm_external", version = "5.1")
bazel_dep(name = "rules_pkg", version = "0.7.0")
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_python", version = "0.10.2")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "zlib", version = "1.2.11")
1 change: 1 addition & 0 deletions examples/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.1.0
9 changes: 9 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# the WORKSPACE file in the same directory with this BUILD file for an
# example.

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_proto_library")
load("@rules_java//java:defs.bzl", "java_binary", "java_lite_proto_library", "java_proto_library")
load("@rules_pkg//pkg:mappings.bzl", "pkg_files", "strip_prefix")
Expand Down Expand Up @@ -113,6 +114,14 @@ java_binary(
deps = [":addressbook_java_lite_proto"],
)

build_test(
name = "test",
targets = [
":add_person_cpp",
":add_person_java",
],
)

# Files included in all source distributions
pkg_files(
name = "dist_files",
Expand Down
13 changes: 13 additions & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""Bazel module dependencies"""
bazel_dep(name = "protobuf", version = "0.0.0", dev_dependency = True, repo_name = "com_google_protobuf")

local_path_override(
module_name = "protobuf",
path = "..",
)

bazel_dep(name = "bazel_skylib", version = "1.0.3")
bazel_dep(name = "rules_cc", version = "0.0.1")
bazel_dep(name = "rules_java", version = "7.3.0")
bazel_dep(name = "rules_pkg", version = "0.7.0")
bazel_dep(name = "rules_proto", version = "4.0.0")
9 changes: 9 additions & 0 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ local_repository(
path = "..",
)

# Needed because protobuf_deps brings rules_python 0.26.0 which is broken:
# https://github.com/bazelbuild/rules_python/issues/1543
http_archive(
name = "rules_python",
sha256 = "5868e73107a8e85d8f323806e60cad7283f34b32163ea6ff1020cf27abef6036",
strip_prefix = "rules_python-0.25.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.25.0/rules_python-0.25.0.tar.gz",
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()
1 change: 1 addition & 0 deletions examples/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This file shadows WORKSPACE in builds with `--enable_bzlmod`
4 changes: 2 additions & 2 deletions src/google/protobuf/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ cc_library(
hdrs = ["time_util.h"],
strip_include_prefix = "/src",
visibility = [
"//:__subpackages__",
"@com_google_protobuf_examples//:__subpackages__",
# Needed when building from within the /examples repository
"//visibility:public",
],
deps = [
"//src/google/protobuf",
Expand Down

0 comments on commit 71e4061

Please sign in to comment.