diff --git a/BUILD b/BUILD index 3289a0640f..c2b4103684 100644 --- a/BUILD +++ b/BUILD @@ -31,11 +31,11 @@ load( ) load( "//bazel:upb_proto_library.bzl", - "upb_fasttable_enabled", "upb_proto_library", "upb_proto_library_copts", "upb_proto_reflection_library", ) +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") # begin:google_only # load( @@ -69,7 +69,7 @@ config_setting( visibility = ["//visibility:public"], ) -upb_fasttable_enabled( +bool_flag( name = "fasttable_enabled", build_setting_default = False, visibility = ["//visibility:public"], diff --git a/bazel/upb_proto_library.bzl b/bazel/upb_proto_library.bzl index e7ebb72d7f..88ef5a605f 100644 --- a/bazel/upb_proto_library.bzl +++ b/bazel/upb_proto_library.bzl @@ -167,29 +167,6 @@ def _cc_library_func(ctx, name, hdrs, srcs, copts, includes, dep_ccinfos): linking_context = linking_context, ) -# Build setting for whether fasttable code generation is enabled ############### - -_FastTableEnabledInfo = provider( - "Provides fasttable configuration", - fields = { - "enabled": "whether fasttable is enabled", - }, -) - -def fasttable_enabled_impl(ctx): - raw_setting = ctx.build_setting_value - - if raw_setting: - # TODO(haberman): check that the target CPU supports fasttable. - pass - - return _FastTableEnabledInfo(enabled = raw_setting) - -upb_fasttable_enabled = rule( - implementation = fasttable_enabled_impl, - build_setting = config.bool(flag = True), -) - # Dummy rule to expose select() copts to aspects ############################## UpbProtoLibraryCoptsInfo = provider( @@ -235,9 +212,6 @@ def _compile_upb_protos(ctx, generator, proto_info, proto_sources): srcs = [_generate_output_file(ctx, name, ext + ".c") for name in proto_sources] hdrs = [_generate_output_file(ctx, name, ext + ".h") for name in proto_sources] transitive_sets = proto_info.transitive_descriptor_sets.to_list() - fasttable_enabled = (hasattr(ctx.attr, "_fasttable_enabled") and - ctx.attr._fasttable_enabled[_FastTableEnabledInfo].enabled) - codegen_params = "fasttable:" if fasttable_enabled else "" ctx.actions.run( inputs = depset( direct = [proto_info.direct_descriptor_set], @@ -247,7 +221,7 @@ def _compile_upb_protos(ctx, generator, proto_info, proto_sources): outputs = srcs + hdrs, executable = ctx.executable._protoc, arguments = [ - "--" + generator + "_out=" + codegen_params + _get_real_root(ctx, srcs[0]), + "--" + generator + "_out=" + _get_real_root(ctx, srcs[0]), "--plugin=protoc-gen-" + generator + "=" + tool.path, "--descriptor_set_in=" + ctx.configuration.host_path_separator.join([f.path for f in transitive_sets]), ] + diff --git a/cmake/make_cmakelists.py b/cmake/make_cmakelists.py index 47bf85b738..6d2c374ee1 100755 --- a/cmake/make_cmakelists.py +++ b/cmake/make_cmakelists.py @@ -197,6 +197,9 @@ class BuildFileFunctions(object): def package_group(self, **kwargs): pass + def bool_flag(self, **kwargs): + pass + class WorkspaceFileFunctions(object): def __init__(self, converter): diff --git a/upb/port/def.inc b/upb/port/def.inc index b507b18769..b23b406992 100644 --- a/upb/port/def.inc +++ b/upb/port/def.inc @@ -243,8 +243,8 @@ #endif /* UPB_FASTTABLE_INIT() allows protos compiled for fasttable to gracefully - * degrade to non-fasttable if we are using UPB_TRY_ENABLE_FASTTABLE. */ -#if !UPB_FASTTABLE && defined(UPB_TRY_ENABLE_FASTTABLE) + * degrade to non-fasttable if the runtime or platform do not support it. */ +#if !UPB_FASTTABLE #define UPB_FASTTABLE_INIT(...) #else #define UPB_FASTTABLE_INIT(...) __VA_ARGS__ diff --git a/upbc/protoc-gen-upb.cc b/upbc/protoc-gen-upb.cc index 4c27f53233..3c3987d62f 100644 --- a/upbc/protoc-gen-upb.cc +++ b/upbc/protoc-gen-upb.cc @@ -1182,7 +1182,7 @@ void WriteMessageField(const upb_MiniTableField* field64, // Writes a single message into a .upb.c source file. void WriteMessage(const protobuf::Descriptor* message, const FileLayout& layout, - Output& output, bool fasttable_enabled) { + Output& output) { std::string msg_name = ToCIdent(message->full_name()); std::string fields_array_ref = "NULL"; std::string submsgs_array_ref = "NULL"; @@ -1225,9 +1225,7 @@ void WriteMessage(const protobuf::Descriptor* message, const FileLayout& layout, std::vector table; uint8_t table_mask = -1; - if (fasttable_enabled) { - table = FastDecodeTable(message, layout); - } + table = FastDecodeTable(message, layout); if (table.size() > 1) { assert((table.size() & (table.size() - 1)) == 0); @@ -1256,7 +1254,7 @@ void WriteMessage(const protobuf::Descriptor* message, const FileLayout& layout, output(" {0x$1, &$0},\n", ent.first, absl::StrCat(absl::Hex(ent.second, absl::kZeroPad16))); } - output(" }),\n"); + output(" })\n"); } output("};\n\n"); } @@ -1310,15 +1308,14 @@ int WriteEnums(const FileLayout& layout, Output& output) { return this_file_enums.size(); } -int WriteMessages(const FileLayout& layout, Output& output, - bool fasttable_enabled) { +int WriteMessages(const FileLayout& layout, Output& output) { const protobuf::FileDescriptor* file = layout.descriptor(); std::vector file_messages = SortedMessages(file); if (file_messages.empty()) return 0; for (auto message : file_messages) { - WriteMessage(message, layout, output, fasttable_enabled); + WriteMessage(message, layout, output); } output("static const upb_MiniTable *$0[$1] = {\n", kMessagesInit, @@ -1383,8 +1380,7 @@ int WriteExtensions(const FileLayout& layout, Output& output) { } // Writes a .upb.cc source file. -void WriteSource(const FileLayout& layout, Output& output, - bool fasttable_enabled) { +void WriteSource(const FileLayout& layout, Output& output) { const protobuf::FileDescriptor* file = layout.descriptor(); EmitFileWarning(file, output); @@ -1405,7 +1401,7 @@ void WriteSource(const FileLayout& layout, Output& output, "#include \"upb/port/def.inc\"\n" "\n"); - int msg_count = WriteMessages(layout, output, fasttable_enabled); + int msg_count = WriteMessages(layout, output); int ext_count = WriteExtensions(layout, output); int enum_count = WriteEnums(layout, output); @@ -1436,17 +1432,12 @@ bool Generator::Generate(const protobuf::FileDescriptor* file, const std::string& parameter, protoc::GeneratorContext* context, std::string* error) const { - bool fasttable_enabled = false; std::vector> params; google::protobuf::compiler::ParseGeneratorParameter(parameter, ¶ms); for (const auto& pair : params) { - if (pair.first == "fasttable") { - fasttable_enabled = true; - } else { - *error = "Unknown parameter: " + pair.first; - return false; - } + *error = "Unknown parameter: " + pair.first; + return false; } FileLayout layout(file); @@ -1459,7 +1450,7 @@ bool Generator::Generate(const protobuf::FileDescriptor* file, std::unique_ptr c_output_stream( context->Open(SourceFilename(file))); Output c_output(c_output_stream.get()); - WriteSource(layout, c_output, fasttable_enabled); + WriteSource(layout, c_output); return true; }