Skip to content

Commit 02680fb

Browse files
committed
chore(bazel): get bazel 8 working (#15042)
* chore(bazel): get bazel 8 working * enable workspace where we disable bzlmod * patch googleapis BUILD.bazel when using workspace * check for null json * determine generation proto paths dynamically * bazel quickstart version has to be changed in two phases * update quickstart bazelrc to use c++17
1 parent 11c1ff5 commit 02680fb

File tree

157 files changed

+1334
-1163
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+1334
-1163
lines changed

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7.6.1
1+
8.1.1

MODULE.bazel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ module(
2222

2323
bazel_dep(name = "platforms", version = "0.0.11")
2424
bazel_dep(name = "bazel_skylib", version = "1.7.1")
25-
bazel_dep(name = "rules_cc", version = "0.0.17")
25+
bazel_dep(name = "rules_cc", version = "0.1.1")
2626
bazel_dep(name = "abseil-cpp", version = "20250127.1", repo_name = "abseil-cpp")
27-
bazel_dep(name = "protobuf", version = "30.0", repo_name = "com_google_protobuf")
27+
bazel_dep(name = "protobuf", version = "30.2", repo_name = "com_google_protobuf")
2828
bazel_dep(name = "boringssl", version = "0.0.0-20230215-5c22014")
2929
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "com_github_nlohmann_json")
3030
bazel_dep(name = "curl", version = "8.8.0.bcr.3", repo_name = "com_github_curl_curl")

bazel/gapic.bzl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ def cc_gapic_library(name, service_dirs = [], googleapis_deps = [], additional_d
3838

3939
native.filegroup(
4040
name = "srcs",
41-
srcs = native.glob(sources_glob),
41+
srcs = native.glob(sources_glob, allow_empty = True),
4242
)
4343

4444
native.filegroup(
4545
name = "hdrs",
46-
srcs = native.glob(include = code_glob, exclude = sources_glob),
46+
srcs = native.glob(include = code_glob, exclude = sources_glob, allow_empty = True),
4747
)
4848

4949
native.filegroup(
5050
name = "public_hdrs",
51-
srcs = native.glob([d + "*.h" for d in service_dirs]),
51+
srcs = native.glob([d + "*.h" for d in service_dirs], allow_empty = True),
5252
visibility = ["//:__pkg__"],
5353
)
5454

5555
native.filegroup(
5656
name = "mocks",
57-
srcs = native.glob([d + "mocks/*.h" for d in service_dirs]),
57+
srcs = native.glob([d + "mocks/*.h" for d in service_dirs], allow_empty = True),
5858
visibility = ["//:__pkg__"],
5959
)
6060

@@ -84,4 +84,4 @@ def cc_gapic_library(name, service_dirs = [], googleapis_deps = [], additional_d
8484
"//:" + name,
8585
"//google/cloud/testing_util:google_cloud_cpp_testing_private",
8686
],
87-
) for sample in native.glob([d + "samples/*_samples.cc" for d in service_dirs])]
87+
) for sample in native.glob([d + "samples/*_samples.cc" for d in service_dirs], allow_empty = True)]

bazel/googleapis.workspace.patch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/BUILD.bazel b/BUILD.bazel
2+
index 95e4c12e5..83838d3f0 100644
3+
--- a/BUILD.bazel
4+
+++ b/BUILD.bazel
5+
@@ -2,7 +2,7 @@ genrule(
6+
name = "build_gen",
7+
outs = ["build_gen.sh"],
8+
executable = True,
9+
- srcs = glob(["run_build_gen.sh"]),
10+
+ srcs = glob(["run_build_gen.sh"], allow_empty=True),
11+
cmd = """
12+
if test -z \"$(SRCS)\"; then
13+
cat <<EOD > $@

bazel/workspace0.bzl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ def gl_cpp_workspace0(name = None):
7171
http_archive,
7272
name = "rules_cc",
7373
urls = [
74-
"https://github.com/bazelbuild/rules_cc/releases/download/0.0.17/rules_cc-0.0.17.tar.gz",
74+
"https://github.com/bazelbuild/rules_cc/releases/download/0.1.1/rules_cc-0.1.1.tar.gz",
7575
],
76-
sha256 = "abc605dd850f813bb37004b77db20106a19311a96b2da1c92b789da529d28fe1",
77-
strip_prefix = "rules_cc-0.0.17",
76+
sha256 = "712d77868b3152dd618c4d64faaddefcc5965f90f5de6e6dd1d5ddcd0be82d42",
77+
strip_prefix = "rules_cc-0.1.1",
7878
)
7979

8080
maybe(
@@ -146,7 +146,7 @@ def gl_cpp_workspace0(name = None):
146146
# protobuf message. No changes to `patches` should ever be
147147
# committed to the main branch.
148148
patch_tool = "patch",
149-
patch_args = ["-p1"],
149+
patch_args = ["-p1", "-l", "-n"],
150150
patches = [],
151151
)
152152

@@ -155,10 +155,10 @@ def gl_cpp_workspace0(name = None):
155155
http_archive,
156156
name = "com_google_protobuf",
157157
urls = [
158-
"https://github.com/protocolbuffers/protobuf/archive/v30.0.tar.gz",
158+
"https://github.com/protocolbuffers/protobuf/archive/v30.2.tar.gz",
159159
],
160-
sha256 = "9df0e9e8ebe39f4fbbb9cf7db3d811287fe3616b2f191eb2bf5eaa12539c881f",
161-
strip_prefix = "protobuf-30.0",
160+
sha256 = "07a43d88fe5a38e434c7f94129cad56a4c43a51f99336074d0799c2f7d4e44c5",
161+
strip_prefix = "protobuf-30.2",
162162
)
163163

164164
# Load BoringSSL. This could be automatically loaded by gRPC. But as of
Binary file not shown.

ci/cloudbuild/builds/bazel-oldest.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ mapfile -t args < <(bazel::common_args)
3030
args+=(
3131
# Test without bzlmod as WORKSPACE is still supported in bazel 7 LTS.
3232
--noenable_bzlmod
33+
--enable_workspace
3334
# Only run the unit tests, no need to waste time running everything.
3435
--test_tag_filters=-integration-test
3536
)

ci/cloudbuild/builds/generate-libraries.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ source module ci/cloudbuild/builds/lib/git.sh
2222

2323
bazel_output_base="$(bazel info output_base)"
2424

25+
# As we support both WORKSPACE and MODULE modes for bazel, we need to determine
26+
# the path to these dependencies dynamically.
27+
read -r protobuf_proto_path < <(find "${bazel_output_base}/external" -name "empty.proto" | sed -nE 's/(.+\/src)\/google\/protobuf\/empty.proto/\1/p')
28+
read -r googleapis_proto_path < <(find "${bazel_output_base}/external" -name "api-index-v1.json" | sed -nE 's/(.+)\/api-index-v1.json/\1/p')
29+
2530
if [ -z "${UPDATED_DISCOVERY_DOCUMENT}" ]; then
2631
io::log_h2 "Removing previously generated golden files"
2732
git grep -l "Generated by the Codegen C++ plugin" generator/integration_tests/golden | xargs rm
@@ -34,8 +39,8 @@ fi
3439
io::log_h2 "Running the generator to update the golden files"
3540
bazel run --action_env=GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes \
3641
//generator:google-cloud-cpp-codegen -- \
37-
--protobuf_proto_path="${bazel_output_base}/external/protobuf~/src" \
38-
--googleapis_proto_path="${bazel_output_base}/external/googleapis~" \
42+
--protobuf_proto_path="${protobuf_proto_path}" \
43+
--googleapis_proto_path="${googleapis_proto_path}" \
3944
--golden_proto_path="${PWD}" \
4045
--output_path="${PWD}" \
4146
--update_ci=false \
@@ -47,8 +52,8 @@ if [ -z "${GENERATE_GOLDEN_ONLY}" ]; then
4752
io::log_h2 "Running the generator to emit protos from discovery docs"
4853
bazel run --action_env=GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes \
4954
//generator:google-cloud-cpp-codegen -- \
50-
--protobuf_proto_path="${bazel_output_base}"/external/protobuf~/src \
51-
--googleapis_proto_path="${bazel_output_base}"/external/googleapis~ \
55+
--protobuf_proto_path="${protobuf_proto_path}" \
56+
--googleapis_proto_path="${googleapis_proto_path}" \
5257
--discovery_proto_path="${PWD}/protos" \
5358
--output_path="${PROJECT_ROOT}/protos" \
5459
--export_output_path="${PROJECT_ROOT}" \
@@ -79,8 +84,8 @@ if [ -z "${GENERATE_GOLDEN_ONLY}" ]; then
7984
io::log_h2 "Running the generator to update the generated libraries"
8085
bazel run --action_env=GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes \
8186
//generator:google-cloud-cpp-codegen -- \
82-
--protobuf_proto_path="${bazel_output_base}"/external/protobuf~/src \
83-
--googleapis_proto_path="${bazel_output_base}"/external/googleapis~ \
87+
--protobuf_proto_path="${protobuf_proto_path}" \
88+
--googleapis_proto_path="${googleapis_proto_path}" \
8489
--discovery_proto_path="${PWD}/protos" \
8590
--output_path="${PROJECT_ROOT}" \
8691
--check_comment_substitutions=true \

ci/cloudbuild/builds/lib/integration.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,16 @@ function integration::bazel_with_emulators() {
263263
else
264264
io::log_h2 "Running generator integration test"
265265
bazel_output_base="$(bazel info output_base)"
266+
267+
# As we support both WORKSPACE and MODULE modes for bazel, we need to determine
268+
# the path to these dependencies dynamically.
269+
read -r protobuf_proto_path < <(find "${bazel_output_base}/external" -name "empty.proto" | sed -nE 's/(.+\/src)\/google\/protobuf\/empty.proto/\1/p')
270+
read -r googleapis_proto_path < <(find "${bazel_output_base}/external" -name "api-index-v1.json" | sed -nE 's/(.+)\/api-index-v1.json/\1/p')
271+
266272
bazel run --action_env=GOOGLE_CLOUD_CPP_ENABLE_CLOG=yes \
267273
//generator:google-cloud-cpp-codegen -- \
268-
--protobuf_proto_path="${bazel_output_base}/external/protobuf~/src" \
269-
--googleapis_proto_path="${bazel_output_base}/external/googleapis~" \
274+
--protobuf_proto_path="${protobuf_proto_path}" \
275+
--googleapis_proto_path="${googleapis_proto_path}" \
270276
--golden_proto_path="${PWD}" \
271277
--output_path="${PWD}" \
272278
--update_ci=false \

ci/cloudbuild/builds/quickstart-bazel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ export CXX=g++
2727
mapfile -t args < <(bazel::common_args)
2828
for lib in $(quickstart::libraries); do
2929
io::log_h2 "Running Bazel quickstart for ${lib}"
30-
env -C "${PROJECT_ROOT}/google/cloud/${lib}/quickstart" \
30+
io::run env -C "${PROJECT_ROOT}/google/cloud/${lib}/quickstart" \
3131
bazel build "${args[@]}" :quickstart
3232
done

0 commit comments

Comments
 (0)