Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
build --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build --cxxopt=-fsized-deallocation
common --enable_platform_specific_config

build --enable_bzlmod
build --copt=-Wno-deprecated-declarations
build --compilation_mode=fastbuild

build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:linux --cxxopt=-fsized-deallocation
build:linux --copt=-Wno-deprecated-declarations

# you will typically need to spell out the compiler for local dev
# BAZEL_VC=<install directory>
# BAZEL_VC_FULL_VERSION=14.44.3520
build:msvc --cxxopt="-std:c++20" --host_cxxopt="-std:c++20"
build:msvc --define=protobuf_allow_msvc=true
build:msvc --test_tag_filters=-benchmark,-notap,-notestmsvc
build:msvc --build_tag_filters=-notestmsvc

test --test_output=errors

# Enable matchers in googletest
Expand Down
6 changes: 6 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ cc_binary(
"@com_google_absl//absl/types:span",
],
)

cc_binary(
name = "cat_param_file",
srcs = ["cat_param_file.cc"],
visibility = ["//:__subpackages__"],
)
44 changes: 38 additions & 6 deletions bazel/antlr.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,25 @@ def antlr_cc_library(name, src, package):
name = generated,
src = src,
package = package,
shell = select(
{
"@bazel_tools//src/conditions:windows": "PowerShell.exe",
"//conditions:default": "bash"
}
),
genfiles_prefixed = select(
{
"@bazel_tools//src/conditions:windows": False,
"//conditions:default": True
}
)
)
cc_library(
name = name + "_cc_parser",
srcs = [generated],
defines = [
"ANTLR4CPP_STATIC"
],
deps = [
generated,
"@antlr4-cpp-runtime//:antlr4-cpp-runtime",
Expand Down Expand Up @@ -64,26 +79,37 @@ def _antlr_library(ctx):
inputs = [ctx.file.src],
outputs = [output],
executable = ctx.executable._tool,
progress_message = "Processing ANTLR grammar",
progress_message = "Processing ANTLR grammar. -o " + output.path,
)

files = []
for suffix in suffixes:
header = ctx.actions.declare_file(basename + suffix + ".h")
source = ctx.actions.declare_file(basename + suffix + ".cpp")
generated = output.path + "/" + ctx.file.src.path[:-3] + suffix
prefix = ctx.file.src.path[:-3] if ctx.attr.genfiles_prefixed else basename
generated = output.path + "/" + prefix + suffix

executable = ctx.attr.shell

ctx.actions.run_shell(
ctx.actions.run(
mnemonic = "CopyHeader" + suffix,
inputs = [output],
outputs = [header],
command = 'cp "{generated}" "{out}"'.format(generated = generated + ".h", out = header.path),
executable = executable,
arguments = [
'-c',
'cp "{generated}" "{out}"'.format(generated = generated + ".h", out = header.path)
],
)
ctx.actions.run_shell(
ctx.actions.run(
mnemonic = "CopySource" + suffix,
inputs = [output],
outputs = [source],
command = 'cp "{generated}" "{out}"'.format(generated = generated + ".cpp", out = source.path),
executable = executable,
arguments = [
'-c',
'cp "{generated}" "{out}"'.format(generated = generated + ".cpp", out = source.path)
],
)

files.append(header)
Expand All @@ -102,5 +128,11 @@ antlr_library = rule(
cfg = "exec", # buildifier: disable=attr-cfg
default = Label("//bazel:antlr4_tool"),
),
"shell": attr.string(
mandatory = True
),
"genfiles_prefixed": attr.bool(
mandatory = True
),
},
)
52 changes: 52 additions & 0 deletions bazel/cat_param_file.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include <fstream>
#include <iostream>

// Read a bazel param file and concatentate the inputs.
// file is line delimited with each line a file to concat.
int main(int argc, char** argv) {
if (argc != 3) {
std::cerr << "usage: cat_param_file <param_file> <out>" << std::endl;
std::cerr << "args " << argc << std::endl;
return 2;
}

const char* param_file = argv[1];
const char* out_file = argv[2];
std::ifstream ifs(param_file, std::ios::binary);
std::ofstream ofs(out_file, std::ios::binary);

for (std::string line; std::getline(ifs, line);) {
std::ifstream in(line, std::ios::binary);
std::cerr << line << ":" << in.good() << std::endl;
int read = 0;
constexpr size_t kBufSize = 256;
char buf[kBufSize];
while (true) {
read = 0;
in.read(buf, kBufSize);
read = in.gcount();
if (read == 0) {
break;
}
ofs.write(buf, read);
}
}

ofs.flush();

return 0;
}
37 changes: 29 additions & 8 deletions bazel/cel_cc_embed.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,33 @@
Provides the `cel_cc_embed` build rule.
"""

def cel_cc_embed(name, src, testonly = False):
native.genrule(
name = name,
srcs = [src],
outs = ["{}.inc".format(name)],
cmd = "$(location //bazel:cel_cc_embed) --in=$< --out=$@",
tools = ["//bazel:cel_cc_embed"],
testonly = testonly,
def _cel_cc_embed(ctx):
output = ctx.actions.declare_file(ctx.attr.name + ".inc")
args = ctx.actions.args()
src = ctx.file.src
args.add("--in", src)
args.add("--out", output.path)
ctx.actions.run(
outputs = [output],
inputs = [src],
progress_message = "generating embed textual header",
executable = ctx.executable.gen_tool,
arguments = [args]
)

return DefaultInfo(files = depset([output]),
runfiles = ctx.runfiles(files=[output]))


cel_cc_embed = rule(
implementation = _cel_cc_embed,
attrs = {
"src": attr.label(allow_single_file=True, mandatory=True),
"gen_tool": attr.label(
executable = True,
cfg = "exec",
allow_files = True,
default = Label("//bazel:cel_cc_embed")
)
}
)
13 changes: 10 additions & 3 deletions bazel/cel_proto_transitive_descriptor_set.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def _cel_proto_transitive_descriptor_set(ctx):
args = ctx.actions.args()
args.use_param_file(param_file_arg = "%s", use_always = True)
args.add_all(transitive_descriptor_sets)
ctx.actions.run_shell(
ctx.actions.run(
outputs = [output],
inputs = transitive_descriptor_sets,
progress_message = "Joining descriptors.",
command = ("< \"$1\" xargs cat >{output}".format(output = output.path)),
Copy link

@chokoswitch chokoswitch Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jnthntatum - just randomly ran into this since I was thinking of sending a different PR for this file that got updated overnight. I am looking in the context of Envoy and noticed that the previous form could have been made to work by adding use_default_shell_env = True so that PATH is properly exported within the command. By default, bash starts with an empty env, and on msys64 that results in PATH set as a shell variable, not an exported environment variable that could be used by xargs. Notably, xargs will call exec etc to run the command, which on unix use a default path defined by libc including /usr/bin, but on Windows tools under msys cannot be known to the default path which is effectively only OS binaries.

Anyways, avoiding shell completely seems even better but just wanted to let you know in case you need to go back to the shell approach for any reason

arguments = [args],
executable = ctx.executable.cat_tool,
arguments = [args] + [output.path],
)
return DefaultInfo(
files = depset([output]),
Expand All @@ -39,9 +39,16 @@ def _cel_proto_transitive_descriptor_set(ctx):
cel_proto_transitive_descriptor_set = rule(
attrs = {
"deps": attr.label_list(providers = [[ProtoInfo]]),
"cat_tool": attr.label(
executable = True,
cfg = "exec",
allow_files = True,
default = Label("//bazel:cat_param_file"),
)
},
outputs = {
"out": "%{name}.binarypb",
},
implementation = _cel_proto_transitive_descriptor_set,
)

2 changes: 2 additions & 0 deletions common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ cc_test(
"@com_google_absl//absl/strings:string_view",
"@com_google_protobuf//:protobuf",
],
tags = ["notestmsvc"],
)

cc_library(
Expand Down Expand Up @@ -882,6 +883,7 @@ cc_test(
"@com_google_absl//absl/strings:string_view",
"@com_google_protobuf//:protobuf",
],
tags = ["notestmsvc"],
)

cc_library(
Expand Down
26 changes: 16 additions & 10 deletions common/value.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1148,12 +1148,10 @@ struct WellKnownTypesValueVisitor {
Value operator()(absl::Time value) const { return TimestampValue(value); }
};

struct OwningWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor {
struct OwningWellKnownTypesValueVisitor {
google::protobuf::Arena* absl_nullable arena;
std::string* absl_nonnull scratch;

using WellKnownTypesValueVisitor::operator();

Value operator()(well_known_types::BytesValue&& value) const {
return absl::visit(absl::Overload(
[&](absl::string_view string) -> BytesValue {
Expand Down Expand Up @@ -1242,15 +1240,18 @@ struct OwningWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor {
}
return ParsedMessageValue(value.release(), arena);
}

template <typename T>
Value operator()(T t) const {
return WellKnownTypesValueVisitor{}.operator()(t);
}
};

struct BorrowingWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor {
struct BorrowingWellKnownTypesValueVisitor {
const google::protobuf::Message* absl_nonnull message;
google::protobuf::Arena* absl_nonnull arena;
std::string* absl_nonnull scratch;

using WellKnownTypesValueVisitor::operator();

Value operator()(well_known_types::BytesValue&& value) const {
return absl::visit(
absl::Overload(
Expand Down Expand Up @@ -1332,6 +1333,11 @@ struct BorrowingWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor {
}
return ParsedMessageValue(value.release(), arena);
}

template <typename T>
Value operator()(T t) const {
return WellKnownTypesValueVisitor{}.operator()(t);
}
};

} // namespace
Expand All @@ -1355,7 +1361,7 @@ Value Value::FromMessage(
}
return absl::visit(
absl::Overload(
OwningWellKnownTypesValueVisitor{.arena = arena, .scratch = &scratch},
OwningWellKnownTypesValueVisitor{/* .arena = */ arena, /* .scratch = */ &scratch},
[&](absl::monostate) -> Value {
auto* cloned = message.New(arena);
cloned->CopyFrom(message);
Expand Down Expand Up @@ -1383,7 +1389,7 @@ Value Value::FromMessage(
}
return absl::visit(
absl::Overload(
OwningWellKnownTypesValueVisitor{.arena = arena, .scratch = &scratch},
OwningWellKnownTypesValueVisitor{/* .arena = */ arena, /* .scratch = */ &scratch},
[&](absl::monostate) -> Value {
auto* cloned = message.New(arena);
cloned->GetReflection()->Swap(cloned, &message);
Expand Down Expand Up @@ -1414,7 +1420,7 @@ Value Value::WrapMessage(
return absl::visit(
absl::Overload(
BorrowingWellKnownTypesValueVisitor{
.message = message, .arena = arena, .scratch = &scratch},
/* .message = */ message, /* .arena = */ arena, /* .scratch = */ &scratch},
[&](absl::monostate) -> Value {
if (message->GetArena() != arena) {
auto* cloned = message->New(arena);
Expand Down Expand Up @@ -1448,7 +1454,7 @@ Value Value::WrapMessageUnsafe(
return absl::visit(
absl::Overload(
BorrowingWellKnownTypesValueVisitor{
.message = message, .arena = arena, .scratch = &scratch},
/* .message = */ message, /* .arena = */ arena, /* .scratch = */ &scratch},
[&](absl::monostate) -> Value {
if (message->GetArena() != arena) {
return UnsafeParsedMessageValue(message);
Expand Down
8 changes: 8 additions & 0 deletions common/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
#include "google/protobuf/map_field.h"
#include "google/protobuf/message.h"


#undef CEL_DISPATCHER_CONST_INIT
#ifdef _MSC_VER > 0
#define CEL_DISPATCHER_CONST_INIT static
#else
#define CEL_DISPATCHER_CONST_INIT ABSL_CONST_INIT
#endif // ifdef _MSC_VE

namespace cel {

// `Value` is a composition type which encompasses all values supported by the
Expand Down
4 changes: 3 additions & 1 deletion common/values/error_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ class ABSL_ATTRIBUTE_TRIVIAL_ABI ErrorValue final

ErrorValue(google::protobuf::Arena* absl_nonnull arena,
const absl::Status* absl_nonnull status)
: arena_(arena), status_{.ptr = status} {}
: arena_(arena) {
status_.ptr = status;
}

void CopyConstruct(const ErrorValue& other) {
arena_ = other.arena_;
Expand Down
Loading