From 1a83c49953bfbdb7f89a3e3605baa8ab09fb5ff0 Mon Sep 17 00:00:00 2001 From: Jonathan Tatum Date: Mon, 15 Dec 2025 16:11:53 -0800 Subject: [PATCH] Draft fixes for windows builds. --- .bazelrc | 17 +- bazel/BUILD | 6 + bazel/antlr.bzl | 44 +++++- bazel/cat_param_file.cc | 52 ++++++ bazel/cel_cc_embed.bzl | 37 ++++- bazel/cel_proto_transitive_descriptor_set.bzl | 13 +- common/BUILD | 2 + common/value.cc | 26 +-- common/value.h | 8 + common/values/error_value.h | 4 +- common/values/optional_value.cc | 148 +++++++++--------- common/values/value_variant_test.cc | 4 +- internal/BUILD | 2 + internal/json.cc | 1 + internal/overflow_test.cc | 80 +++++----- parser/BUILD | 3 + parser/parser_test.cc | 2 +- 17 files changed, 301 insertions(+), 148 deletions(-) create mode 100644 bazel/cat_param_file.cc diff --git a/.bazelrc b/.bazelrc index 9d16de1c4..f72689360 100644 --- a/.bazelrc +++ b/.bazelrc @@ -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= +# 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 diff --git a/bazel/BUILD b/bazel/BUILD index 7a72be0e7..f771874f9 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -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__"], +) diff --git a/bazel/antlr.bzl b/bazel/antlr.bzl index 73c5a9d2c..e8c5f3893 100644 --- a/bazel/antlr.bzl +++ b/bazel/antlr.bzl @@ -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", @@ -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) @@ -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 + ), }, ) diff --git a/bazel/cat_param_file.cc b/bazel/cat_param_file.cc new file mode 100644 index 000000000..ff0264f75 --- /dev/null +++ b/bazel/cat_param_file.cc @@ -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 +#include + +// 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 " << 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; +} \ No newline at end of file diff --git a/bazel/cel_cc_embed.bzl b/bazel/cel_cc_embed.bzl index cec4d7897..ac96d818b 100644 --- a/bazel/cel_cc_embed.bzl +++ b/bazel/cel_cc_embed.bzl @@ -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") + ) + } +) \ No newline at end of file diff --git a/bazel/cel_proto_transitive_descriptor_set.bzl b/bazel/cel_proto_transitive_descriptor_set.bzl index e65e0b4a2..034251b80 100644 --- a/bazel/cel_proto_transitive_descriptor_set.bzl +++ b/bazel/cel_proto_transitive_descriptor_set.bzl @@ -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)), - arguments = [args], + executable = ctx.executable.cat_tool, + arguments = [args] + [output.path], ) return DefaultInfo( files = depset([output]), @@ -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, ) + diff --git a/common/BUILD b/common/BUILD index 3800e55b2..50bbdc16c 100644 --- a/common/BUILD +++ b/common/BUILD @@ -855,6 +855,7 @@ cc_test( "@com_google_absl//absl/strings:string_view", "@com_google_protobuf//:protobuf", ], + tags = ["notestmsvc"], ) cc_library( @@ -882,6 +883,7 @@ cc_test( "@com_google_absl//absl/strings:string_view", "@com_google_protobuf//:protobuf", ], + tags = ["notestmsvc"], ) cc_library( diff --git a/common/value.cc b/common/value.cc index e6764223c..54a3fd93a 100644 --- a/common/value.cc +++ b/common/value.cc @@ -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 { @@ -1242,15 +1240,18 @@ struct OwningWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor { } return ParsedMessageValue(value.release(), arena); } + + template + 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( @@ -1332,6 +1333,11 @@ struct BorrowingWellKnownTypesValueVisitor : public WellKnownTypesValueVisitor { } return ParsedMessageValue(value.release(), arena); } + + template + Value operator()(T t) const { + return WellKnownTypesValueVisitor{}.operator()(t); + } }; } // namespace @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/common/value.h b/common/value.h index 062257961..fcd6d5df7 100644 --- a/common/value.h +++ b/common/value.h @@ -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 diff --git a/common/values/error_value.h b/common/values/error_value.h index 3decc850f..66a9ba601 100644 --- a/common/values/error_value.h +++ b/common/values/error_value.h @@ -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_; diff --git a/common/values/optional_value.cc b/common/values/optional_value.cc index ad0a65efb..67bb01945 100644 --- a/common/values/optional_value.cc +++ b/common/values/optional_value.cc @@ -122,18 +122,18 @@ absl::Status OptionalValueEqual( return absl::OkStatus(); } -ABSL_CONST_INIT const OptionalValueDispatcher +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher empty_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -149,18 +149,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher }, }; -ABSL_CONST_INIT const OptionalValueDispatcher null_optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher null_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -171,18 +171,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher null_optional_value_dispatcher = { cel::Value* absl_nonnull result) -> void { *result = NullValue(); }, }; -ABSL_CONST_INIT const OptionalValueDispatcher bool_optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher bool_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -195,18 +195,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher bool_optional_value_dispatcher = { }, }; -ABSL_CONST_INIT const OptionalValueDispatcher int_optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher int_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -219,18 +219,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher int_optional_value_dispatcher = { }, }; -ABSL_CONST_INIT const OptionalValueDispatcher uint_optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher uint_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -243,18 +243,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher uint_optional_value_dispatcher = { }, }; -ABSL_CONST_INIT const OptionalValueDispatcher +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher double_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -268,18 +268,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher }, }; -ABSL_CONST_INIT const OptionalValueDispatcher +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher duration_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -293,18 +293,18 @@ ABSL_CONST_INIT const OptionalValueDispatcher }, }; -ABSL_CONST_INIT const OptionalValueDispatcher +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher timestamp_optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = [](const OpaqueValueDispatcher* absl_nonnull, + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent) -> google::protobuf::Arena* absl_nullable { return nullptr; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { return common_internal::MakeOptionalValue(dispatcher, content); @@ -323,19 +323,19 @@ struct OptionalValueContent { google::protobuf::Arena* absl_nonnull arena; }; -ABSL_CONST_INIT const OptionalValueDispatcher optional_value_dispatcher = { +CEL_DISPATCHER_CONST_INIT const OptionalValueDispatcher optional_value_dispatcher = { { - .get_type_id = &OptionalValueGetTypeId, - .get_arena = + /*.get_type_id =*/ &OptionalValueGetTypeId, + /*.get_arena =*/ [](const OpaqueValueDispatcher* absl_nonnull, OpaqueValueContent content) -> google::protobuf::Arena* absl_nullable { return content.To().arena; }, - .get_type_name = &OptionalValueGetTypeName, - .debug_string = &OptionalValueDebugString, - .get_runtime_type = &OptionalValueGetRuntimeType, - .equal = &OptionalValueEqual, - .clone = [](const OpaqueValueDispatcher* absl_nonnull dispatcher, + /*.get_type_name =*/ &OptionalValueGetTypeName, + /*.debug_string =*/ &OptionalValueDebugString, + /*.get_runtime_type =*/ &OptionalValueGetRuntimeType, + /*.equal =*/ &OptionalValueEqual, + /*.clone =*/ [](const OpaqueValueDispatcher* absl_nonnull dispatcher, OpaqueValueContent content, google::protobuf::Arena* absl_nonnull arena) -> OpaqueValue { ABSL_DCHECK(arena != nullptr); @@ -350,7 +350,7 @@ ABSL_CONST_INIT const OptionalValueDispatcher optional_value_dispatcher = { return common_internal::MakeOptionalValue( &optional_value_dispatcher, OpaqueValueContent::From( - OptionalValueContent{.value = result, .arena = arena})); + OptionalValueContent{/* .value = */ result, /* .arena = */ arena})); }, }, &OptionalValueHasValue, @@ -407,7 +407,7 @@ OptionalValue OptionalValue::Of(cel::Value value, } return OptionalValue(&optional_value_dispatcher, OpaqueValueContent::From(OptionalValueContent{ - .value = result, .arena = arena})); + /*.value =*/ result, /*.arena =*/ arena})); } } } diff --git a/common/values/value_variant_test.cc b/common/values/value_variant_test.cc index 1fd3629aa..24179522e 100644 --- a/common/values/value_variant_test.cc +++ b/common/values/value_variant_test.cc @@ -20,7 +20,7 @@ namespace cel::common_internal { namespace { - +#ifndef _MSC_VER template class ValueVariantTest : public ::testing::Test {}; @@ -121,6 +121,6 @@ TYPED_TEST(ValueVariantTest, Swap) { EXPECT_TRUE(lhs.Is()); EXPECT_TRUE(rhs.Is()); } - +#endif // ifndef _MSC_VER } // namespace } // namespace cel::common_internal diff --git a/internal/BUILD b/internal/BUILD index 444cec4a1..7bfdcc8fb 100644 --- a/internal/BUILD +++ b/internal/BUILD @@ -39,6 +39,7 @@ cc_test( ":align", ":testing", ], + tags = ["notestmsvc"], ) cc_library( @@ -810,6 +811,7 @@ cc_test( "@com_google_protobuf//:timestamp_cc_proto", "@com_google_protobuf//:wrappers_cc_proto", ], + tags = ["notestmsvc"], ) cc_library( diff --git a/internal/json.cc b/internal/json.cc index 63724cd6d..3c4187897 100644 --- a/internal/json.cc +++ b/internal/json.cc @@ -864,6 +864,7 @@ class MessageToJsonState { case FieldDescriptor::TYPE_GROUP: ABSL_FALLTHROUGH_INTENDED; case FieldDescriptor::TYPE_MESSAGE: + #undef GetMessage return ToJson(reflection->GetMessage(message, field), result); case FieldDescriptor::TYPE_BYTES: BytesValueToJson( diff --git a/internal/overflow_test.cc b/internal/overflow_test.cc index 38c5fa750..d82ad2baa 100644 --- a/internal/overflow_test.cc +++ b/internal/overflow_test.cc @@ -57,11 +57,11 @@ INSTANTIATE_TEST_SUITE_P( CheckedIntMathTest, CheckedIntResultTest, ValuesIn(std::vector{ // Addition tests. - {"OneAddOne", [] { return CheckedAdd(1L, 1L); }, 2L}, - {"ZeroAddOne", [] { return CheckedAdd(0, 1L); }, 1L}, - {"ZeroAddMinusOne", [] { return CheckedAdd(0, -1L); }, -1L}, - {"OneAddZero", [] { return CheckedAdd(1L, 0); }, 1L}, - {"MinusOneAddZero", [] { return CheckedAdd(-1L, 0); }, -1L}, + {"OneAddOne", [] { return CheckedAdd(int64_t{1L}, 1L); }, 2L}, + {"ZeroAddOne", [] { return CheckedAdd(int64_t{0}, 1L); }, 1L}, + {"ZeroAddMinusOne", [] { return CheckedAdd(int64_t{0}, -1L); }, -1L}, + {"OneAddZero", [] { return CheckedAdd(1L, int64_t{0}); }, 1L}, + {"MinusOneAddZero", [] { return CheckedAdd(-1L, int64_t{0}); }, -1L}, {"OneAddIntMax", [] { return CheckedAdd(1L, std::numeric_limits::max()); }, absl::OutOfRangeError("integer overflow")}, @@ -70,12 +70,12 @@ INSTANTIATE_TEST_SUITE_P( absl::OutOfRangeError("integer overflow")}, // Subtraction tests. - {"TwoSubThree", [] { return CheckedSub(2L, 3L); }, -1L}, - {"TwoSubZero", [] { return CheckedSub(2L, 0); }, 2L}, - {"ZeroSubTwo", [] { return CheckedSub(0, 2L); }, -2L}, - {"MinusTwoSubThree", [] { return CheckedSub(-2L, 3L); }, -5L}, - {"MinusTwoSubZero", [] { return CheckedSub(-2L, 0); }, -2L}, - {"ZeroSubMinusTwo", [] { return CheckedSub(0, -2L); }, 2L}, + {"TwoSubThree", [] { return CheckedSub(int64_t{2L}, 3L); }, -1L}, + {"TwoSubZero", [] { return CheckedSub(2L, int64_t{0}); }, 2L}, + {"ZeroSubTwo", [] { return CheckedSub(int64_t{0}, 2L); }, -2L}, + {"MinusTwoSubThree", [] { return CheckedSub(int64_t{-2L}, 3L); }, -5L}, + {"MinusTwoSubZero", [] { return CheckedSub(-2L, int64_t{0}); }, -2L}, + {"ZeroSubMinusTwo", [] { return CheckedSub(int64_t{0}, -2L); }, 2L}, {"IntMinSubIntMax", [] { return CheckedSub(std::numeric_limits::max(), @@ -84,10 +84,10 @@ INSTANTIATE_TEST_SUITE_P( absl::OutOfRangeError("integer overflow")}, // Multiplication tests. - {"TwoMulThree", [] { return CheckedMul(2L, 3L); }, 6L}, - {"MinusTwoMulThree", [] { return CheckedMul(-2L, 3L); }, -6L}, - {"MinusTwoMulMinusThree", [] { return CheckedMul(-2L, -3L); }, 6L}, - {"TwoMulMinusThree", [] { return CheckedMul(2L, -3L); }, -6L}, + {"TwoMulThree", [] { return CheckedMul(2L, int64_t{3L}); }, 6L}, + {"MinusTwoMulThree", [] { return CheckedMul(-2L, int64_t{3L}); }, -6L}, + {"MinusTwoMulMinusThree", [] { return CheckedMul(int64_t{-2L}, -3L); }, 6L}, + {"TwoMulMinusThree", [] { return CheckedMul(int64_t{2L}, -3L); }, -6L}, {"TwoMulIntMax", [] { return CheckedMul(2L, std::numeric_limits::max()); }, absl::OutOfRangeError("integer overflow")}, @@ -109,22 +109,22 @@ INSTANTIATE_TEST_SUITE_P( [] { return CheckedMul(0, std::numeric_limits::max()); }, 0}, // Division cases. - {"ZeroDivOne", [] { return CheckedDiv(0, 1L); }, 0}, - {"TenDivTwo", [] { return CheckedDiv(10L, 2L); }, 5}, - {"TenDivMinusOne", [] { return CheckedDiv(10L, -1L); }, -10}, - {"MinusTenDivMinusOne", [] { return CheckedDiv(-10L, -1L); }, 10}, - {"MinusTenDivTwo", [] { return CheckedDiv(-10L, 2L); }, -5}, - {"OneDivZero", [] { return CheckedDiv(1L, 0L); }, + {"ZeroDivOne", [] { return CheckedDiv(int64_t{0}, 1L); }, 0}, + {"TenDivTwo", [] { return CheckedDiv(int64_t{10L}, 2L); }, 5}, + {"TenDivMinusOne", [] { return CheckedDiv(int64_t{10L}, -1L); }, -10}, + {"MinusTenDivMinusOne", [] { return CheckedDiv(int64_t{-10L}, -1L); }, 10}, + {"MinusTenDivTwo", [] { return CheckedDiv(int64_t{-10L}, 2L); }, -5}, + {"OneDivZero", [] { return CheckedDiv(1L, int64_t{0L}); }, absl::InvalidArgumentError("divide by zero")}, {"IntMinDivMinusOne", [] { return CheckedDiv(std::numeric_limits::lowest(), -1L); }, absl::OutOfRangeError("integer overflow")}, // Modulus cases. - {"ZeroModTwo", [] { return CheckedMod(0, 2L); }, 0}, - {"TwoModTwo", [] { return CheckedMod(2L, 2L); }, 0}, - {"ThreeModTwo", [] { return CheckedMod(3L, 2L); }, 1L}, - {"TwoModZero", [] { return CheckedMod(2L, 0); }, + {"ZeroModTwo", [] { return CheckedMod(0, int64_t{2L}); }, 0}, + {"TwoModTwo", [] { return CheckedMod(int64_t{2L}, int64_t{2L}); }, 0}, + {"ThreeModTwo", [] { return CheckedMod(3L, int64_t{2L}); }, 1L}, + {"TwoModZero", [] { return CheckedMod(int64_t{2L}, 0); }, absl::InvalidArgumentError("modulus by zero")}, {"IntMinModTwo", [] { return CheckedMod(std::numeric_limits::lowest(), 2L); }, @@ -218,37 +218,37 @@ INSTANTIATE_TEST_SUITE_P( CheckedUintMathTest, CheckedUintResultTest, ValuesIn(std::vector{ // Addition tests. - {"OneAddOne", [] { return CheckedAdd(1UL, 1UL); }, 2UL}, - {"ZeroAddOne", [] { return CheckedAdd(0, 1UL); }, 1UL}, - {"OneAddZero", [] { return CheckedAdd(1UL, 0); }, 1UL}, + {"OneAddOne", [] { return CheckedAdd(uint64_t{1UL}, 1UL); }, 2UL}, + {"ZeroAddOne", [] { return CheckedAdd(uint64_t{0}, 1UL); }, 1UL}, + {"OneAddZero", [] { return CheckedAdd(uint64_t{1UL}, 0); }, 1UL}, {"OneAddIntMax", [] { return CheckedAdd(1UL, std::numeric_limits::max()); }, absl::OutOfRangeError("unsigned integer overflow")}, // Subtraction tests. - {"OneSubOne", [] { return CheckedSub(1UL, 1UL); }, 0}, - {"ZeroSubOne", [] { return CheckedSub(0, 1UL); }, + {"OneSubOne", [] { return CheckedSub(uint64_t{1UL}, 1UL); }, 0}, + {"ZeroSubOne", [] { return CheckedSub(uint64_t{0}, 1UL); }, absl::OutOfRangeError("unsigned integer overflow")}, - {"OneSubZero", [] { return CheckedSub(1UL, 0); }, 1UL}, + {"OneSubZero", [] { return CheckedSub(uint64_t{1UL}, 0); }, 1UL}, // Multiplication tests. - {"OneMulOne", [] { return CheckedMul(1UL, 1UL); }, 1UL}, - {"ZeroMulOne", [] { return CheckedMul(0, 1UL); }, 0}, - {"OneMulZero", [] { return CheckedMul(1UL, 0); }, 0}, + {"OneMulOne", [] { return CheckedMul(uint64_t{1UL}, 1UL); }, 1UL}, + {"ZeroMulOne", [] { return CheckedMul(uint64_t{0}, 1UL); }, 0}, + {"OneMulZero", [] { return CheckedMul(uint64_t{1UL}, 0); }, 0}, {"TwoMulUintMax", [] { return CheckedMul(2UL, std::numeric_limits::max()); }, absl::OutOfRangeError("unsigned integer overflow")}, // Division tests. - {"TwoDivTwo", [] { return CheckedDiv(2UL, 2UL); }, 1UL}, - {"TwoDivFour", [] { return CheckedDiv(2UL, 4UL); }, 0}, - {"OneDivZero", [] { return CheckedDiv(1UL, 0); }, + {"TwoDivTwo", [] { return CheckedDiv(uint64_t{2UL}, 2UL); }, 1UL}, + {"TwoDivFour", [] { return CheckedDiv(uint64_t{2UL}, 4UL); }, 0}, + {"OneDivZero", [] { return CheckedDiv(uint64_t{1UL}, 0); }, absl::InvalidArgumentError("divide by zero")}, // Modulus tests. - {"TwoModTwo", [] { return CheckedMod(2UL, 2UL); }, 0}, - {"TwoModFour", [] { return CheckedMod(2UL, 4UL); }, 2UL}, - {"OneModZero", [] { return CheckedMod(1UL, 0); }, + {"TwoModTwo", [] { return CheckedMod(uint64_t{2UL}, 2UL); }, 0}, + {"TwoModFour", [] { return CheckedMod(uint64_t{2UL}, 4UL); }, 2UL}, + {"OneModZero", [] { return CheckedMod(uint64_t{1UL}, 0); }, absl::InvalidArgumentError("modulus by zero")}, // Conversion test cases for int -> uint, double -> uint. diff --git a/parser/BUILD b/parser/BUILD index 554b6ac98..35cca2032 100644 --- a/parser/BUILD +++ b/parser/BUILD @@ -30,6 +30,9 @@ cc_library( copts = [ "-fexceptions", ], + defines = [ + "ANTLR4CPP_STATIC" + ], deps = [ ":macro", ":macro_expr_factory", diff --git a/parser/parser_test.cc b/parser/parser_test.cc index 3865476ee..aee121051 100644 --- a/parser/parser_test.cc +++ b/parser/parser_test.cc @@ -1485,7 +1485,7 @@ TEST_P(ExpressionTest, Parse) { macros.push_back(cel::OptFlatMapMacro()); auto result = EnrichedParse(test_info.I, macros, "", options); if (test_info.E.empty()) { - EXPECT_THAT(result, IsOk()); + ASSERT_THAT(result, IsOk()); } else { EXPECT_THAT(result, Not(IsOk())); EXPECT_EQ(test_info.E, result.status().message());