Skip to content

Commit b34f08d

Browse files
Initial bzlmod support (#88)
I've held off on adding more CI to this for now, we can tackle that when we tackle getting this on the BCR. Note that cel-cpp is still not on the BCR; I'm not sure if this is a blocker for us getting on the BCR. Still, it should be possible for users to consume protovalidate-cc with bzlmod after this commit using `bazel_dep` + `archive_override` just like we're doing for cel-cpp. Closes #66.
1 parent 0aada05 commit b34f08d

File tree

8 files changed

+874
-3
lines changed

8 files changed

+874
-3
lines changed

.bazelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
common --noenable_bzlmod --enable_workspace
1+
common --enable_bzlmod --noenable_workspace
22

33
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
44
build --cxxopt=-fsized-deallocation

MODULE.bazel

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2023-2025 Buf Technologies, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# DO NOT EDIT MODULE.bazel - Edit MODULE.bazel.tmpl instead, then run make generate.
16+
17+
module(name = "protovalidate-cc")
18+
19+
bazel_dep(name = "re2", version = "2024-07-02.bcr.1", repo_name = "com_googlesource_code_re2")
20+
21+
bazel_dep(name = "protobuf", version = "29.2", repo_name = "com_google_protobuf")
22+
23+
bazel_dep(name = "rules_proto", version = "7.1.0")
24+
25+
bazel_dep(name = "rules_buf", version = "0.3.0")
26+
27+
bazel_dep(name = "googletest", version = "1.16.0.bcr.1", repo_name = "com_google_googletest")
28+
29+
bazel_dep(name = "abseil-cpp", version = "20240722.0", repo_name = "com_google_absl")
30+
31+
bazel_dep(name = "cel-cpp", repo_name = "com_google_cel_cpp")
32+
33+
archive_override(
34+
module_name = "cel-cpp",
35+
strip_prefix = "cel-cpp-0.11.0",
36+
patches=[
37+
"@protovalidate-cc//deps:patches/cel_cpp/0001-Allow-message-field-access-using-index-operator.patch",
38+
"@protovalidate-cc//deps:patches/cel_cpp/0002-Add-missing-include-for-absl-StrCat.patch",
39+
"@protovalidate-cc//deps:patches/cel_cpp/0003-Fix-build-on-Windows-MSVC.patch",
40+
],
41+
patch_args=["-p1"],
42+
urls = [
43+
"https://github.com/google/cel-cpp/archive/v0.11.0.tar.gz"
44+
]
45+
)
46+
47+
bazel_dep(name = "protovalidate", version = "0.10.4", repo_name = "com_github_bufbuild_protovalidate")

MODULE.bazel.lock

+770
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MODULE.bazel.tmpl

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2023-2025 Buf Technologies, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# DO NOT EDIT MODULE.bazel - Edit MODULE.bazel.tmpl instead, then run make generate.
16+
17+
module(name = "protovalidate-cc")
18+
19+
bazel_dep(name = "re2", version = "2024-07-02.bcr.1", repo_name = "com_googlesource_code_re2")
20+
21+
bazel_dep(name = "protobuf", version = "{{protobuf.meta.version}}", repo_name = "com_google_protobuf")
22+
23+
bazel_dep(name = "rules_proto", version = "7.1.0")
24+
25+
bazel_dep(name = "rules_buf", version = "0.3.0")
26+
27+
bazel_dep(name = "googletest", version = "1.16.0.bcr.1", repo_name = "com_google_googletest")
28+
29+
bazel_dep(name = "abseil-cpp", version = "{{absl.meta.version}}", repo_name = "com_google_absl")
30+
31+
bazel_dep(name = "cel-cpp", repo_name = "com_google_cel_cpp")
32+
33+
archive_override(
34+
module_name = "cel-cpp",
35+
strip_prefix = "cel-cpp-{{cel_cpp.meta.version}}",
36+
patches=[
37+
"@protovalidate-cc//deps:patches/cel_cpp/0001-Allow-message-field-access-using-index-operator.patch",
38+
"@protovalidate-cc//deps:patches/cel_cpp/0002-Add-missing-include-for-absl-StrCat.patch",
39+
"@protovalidate-cc//deps:patches/cel_cpp/0003-Fix-build-on-Windows-MSVC.patch",
40+
],
41+
patch_args=["-p1"],
42+
urls = [
43+
"https://github.com/google/cel-cpp/archive/v{{cel_cpp.meta.version}}.tar.gz"
44+
]
45+
)
46+
47+
bazel_dep(name = "protovalidate", version = "{{protovalidate.meta.version}}", repo_name = "com_github_bufbuild_protovalidate")

Makefile

+7-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ clean: ## Delete intermediate build artifacts
3232
git clean -Xdf
3333

3434
.PHONY: generate
35-
generate: generate-license ## Regenerate code and license headers
35+
generate: generate-bzlmod generate-license ## Regenerate code and license headers
3636

3737
.PHONY: test
3838
test: generate ## Run all unit tests
@@ -49,6 +49,12 @@ conformance: $(BIN)/protovalidate-conformance
4949
$(BAZEL) build -c opt //buf/validate/conformance:runner_main && \
5050
$(BIN)/protovalidate-conformance bazel-bin/buf/validate/conformance/runner_main $(ARGS)
5151

52+
.PHONY: generate-bzlmod
53+
generate-bzlmod: ## Generate MODULE.bazel file from template
54+
<MODULE.bazel.tmpl >MODULE.bazel \
55+
jq -nrR --argjson json "$$(<./deps/shared_deps.json)" \
56+
'inputs | gsub("\\{\\{(?<v>[^}]+)\\}\\}"; .v | split(".") as $$path | reduce $$path[] as $$key ($$json; .[$$key]) | tostring)'
57+
5258
.PHONY: generate-license
5359
generate-license: $(BIN)/license-header ## Generate license headers for files
5460
@# We want to operate on a list of modified and new files, excluding

WORKSPACE.bzlmod

Whitespace-only changes.

bazel/deps.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ cc_library(
103103
patches=[
104104
"@com_github_bufbuild_protovalidate_cc//deps:patches/cel_cpp/0001-Allow-message-field-access-using-index-operator.patch",
105105
"@com_github_bufbuild_protovalidate_cc//deps:patches/cel_cpp/0002-Add-missing-include-for-absl-StrCat.patch",
106+
"@com_github_bufbuild_protovalidate_cc//deps:patches/cel_cpp/0003-Fix-build-on-Windows-MSVC.patch",
106107
],
107108
patch_args=["-p1"],
108109
),

buf/validate/validator.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ absl::Status Validator::ValidateMessage(
2121
const auto* constraints_or = factory_->GetMessageConstraints(message.GetDescriptor());
2222
if (constraints_or == nullptr) {
2323
return absl::NotFoundError(
24-
"constraints not loaded for message: " + message.GetDescriptor()->full_name());
24+
absl::StrCat("constraints not loaded for message: ", message.GetDescriptor()->full_name()));
2525
}
2626
if (!constraints_or->ok()) {
2727
return constraints_or->status();

0 commit comments

Comments
 (0)