From 1c749d54d7e6799db69ad88781aec44c0d4250a7 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 24 Aug 2026 10:41:04 -0700 Subject: [PATCH] Re-enable FastTable for non-opt builds. PiperOrigin-RevId: 969943256 --- cmake/installed_include_golden.txt | 3 + upb/BUILD | 94 +++++++++++++++++++++++++++--- upb/bazel/copts.bzl | 6 +- upb/mini_table/BUILD | 13 ++--- upb/port/BUILD | 3 +- 5 files changed, 100 insertions(+), 19 deletions(-) diff --git a/cmake/installed_include_golden.txt b/cmake/installed_include_golden.txt index 2579cfcc8c..a59abb9ec1 100644 --- a/cmake/installed_include_golden.txt +++ b/cmake/installed_include_golden.txt @@ -245,6 +245,9 @@ upb/wire/byte_size.h upb/wire/decode.h upb/wire/decode_fast/combinations.h upb/wire/decode_fast/data.h +upb/wire/decode_fast/dispatch.h +upb/wire/decode_fast/field_parsers.h +upb/wire/decode_fast/function_array.h upb/wire/decode_fast/select.h upb/wire/encode.h upb/wire/encode_extension.h diff --git a/upb/BUILD b/upb/BUILD index ae7e72af26..8d38a106d5 100644 --- a/upb/BUILD +++ b/upb/BUILD @@ -6,7 +6,7 @@ # https://developers.google.com/open-source/licenses/bsd load("@bazel_skylib//lib:selects.bzl", "selects") -load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") +load("@bazel_skylib//rules:common_settings.bzl", "string_flag") load("@rules_cc//cc:defs.bzl", "cc_library") load("@rules_python//python:defs.bzl", "py_binary") load("//upb/bazel:copts.bzl", "UPB_DEFAULT_COPTS", "UPB_DEFAULT_FEATURES") @@ -45,28 +45,95 @@ config_setting( visibility = UPB_CONFIG_VISIBILITY, ) -bool_flag( +# FastTable flag definition + enablement rules. +# FastTable will only enable for builds targeting 64bit. +# If not explicitly specified, FastTable will enable by default for non-opt builds. +string_flag( name = "fasttable_enabled", - build_setting_default = False, + build_setting_default = "auto", scope = "universal", + values = [ + "true", + "false", + "auto", + "True", + "False", + "Auto", + ], visibility = UPB_CONFIG_VISIBILITY, ) config_setting( - name = "fasttable_enabled_setting_flag", + name = "fasttable_enabled_true", flag_values = {"//upb:fasttable_enabled": "true"}, - visibility = UPB_CONFIG_VISIBILITY, +) + +config_setting( + name = "fasttable_enabled_True_cap", + flag_values = {"//upb:fasttable_enabled": "True"}, ) selects.config_setting_group( - name = "fasttable_enabled_setting", - match_all = [ - ":fasttable_enabled_setting_flag", - ":any_64bit", + name = "fasttable_enabled_explicit_true", + match_any = [ + ":fasttable_enabled_true", + ":fasttable_enabled_True_cap", ], visibility = UPB_CONFIG_VISIBILITY, ) +config_setting( + name = "fasttable_enabled_auto", + flag_values = {"//upb:fasttable_enabled": "auto"}, +) + +config_setting( + name = "fasttable_enabled_Auto_cap", + flag_values = {"//upb:fasttable_enabled": "Auto"}, +) + +selects.config_setting_group( + name = "fasttable_enabled_is_auto", + match_any = [ + ":fasttable_enabled_auto", + ":fasttable_enabled_Auto_cap", + ], +) + +config_setting( + name = "dbg_mode", + values = {"compilation_mode": "dbg"}, +) + +config_setting( + name = "fastbuild_mode", + values = {"compilation_mode": "fastbuild"}, +) + +selects.config_setting_group( + name = "non_opt_build", + match_any = [ + ":dbg_mode", + ":fastbuild_mode", + ], +) + +selects.config_setting_group( + name = "fasttable_enabled_default_active", + match_all = [ + ":fasttable_enabled_is_auto", + ":non_opt_build", + ], +) + +selects.config_setting_group( + name = "fasttable_enabled_active", + match_any = [ + ":fasttable_enabled_explicit_true", + ":fasttable_enabled_default_active", + ], +) + selects.config_setting_group( name = "any_64bit", match_any = [ @@ -83,6 +150,15 @@ selects.config_setting_group( visibility = UPB_CONFIG_VISIBILITY, ) +selects.config_setting_group( + name = "fasttable_enabled_setting", + match_all = [ + ":fasttable_enabled_active", + ":any_64bit", + ], + visibility = UPB_CONFIG_VISIBILITY, +) + upb_proto_library_copts( name = "upb_proto_library_copts", copts = UPB_DEFAULT_COPTS, diff --git a/upb/bazel/copts.bzl b/upb/bazel/copts.bzl index dfbf84c2de..4a2593dfbc 100644 --- a/upb/bazel/copts.bzl +++ b/upb/bazel/copts.bzl @@ -44,7 +44,8 @@ UPB_DEFAULT_CPPOPTS = select({ "//upb:windows": [], "//conditions:default": _DEFAULT_CPPOPTS, }) + select({ - "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_explicit_true": ["-DUPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_setting": ["-DUPB_TRY_ENABLE_FASTTABLE"], "//conditions:default": [], }) @@ -52,7 +53,8 @@ UPB_DEFAULT_COPTS = select({ "//upb:windows": [], "//conditions:default": _DEFAULT_COPTS, }) + select({ - "//upb:fasttable_enabled_setting": ["-DUPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_explicit_true": ["-DUPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_setting": ["-DUPB_TRY_ENABLE_FASTTABLE"], "//conditions:default": [], }) diff --git a/upb/mini_table/BUILD b/upb/mini_table/BUILD index abde5108b3..e5c27b8445 100644 --- a/upb/mini_table/BUILD +++ b/upb/mini_table/BUILD @@ -230,18 +230,17 @@ cc_binary( # separate tests and use configuration-aware genrules to ensure each test # only performs real validation when its configuration is active. # -# We move the generator binary to "srcs" so that it is built in the target -# configuration (not the exec configuration), ensuring it correctly receives -# the fasttable enablement flag. +# Generator binary is in tools so it is built for the host (exec configuration) +# to support cross-compilation (e.g. darwin_x86_64). genrule( name = "debug_string_test_txt_gen", srcs = select({ - "//upb:fasttable_enabled_setting": ["debug_string_test.txt"], + "//upb:fasttable_enabled_explicit_true": ["debug_string_test.txt"], "//conditions:default": [], }), outs = ["generated/debug_string_test.txt"], cmd = select({ - "//upb:fasttable_enabled_setting": "cp $(location debug_string_test.txt) $@", + "//upb:fasttable_enabled_explicit_true": "cp $(location debug_string_test.txt) $@", "//conditions:default": "$(location :debug_string_test_generate) > $@", }), tools = [":debug_string_test_generate"], @@ -250,12 +249,12 @@ genrule( genrule( name = "debug_string_test_fasttable_txt_gen", srcs = select({ - "//upb:fasttable_enabled_setting": [], + "//upb:fasttable_enabled_explicit_true": [], "//conditions:default": ["debug_string_test.fasttable.txt"], }), outs = ["generated/debug_string_test.fasttable.txt"], cmd = select({ - "//upb:fasttable_enabled_setting": "$(location :debug_string_test_generate) > $@", + "//upb:fasttable_enabled_explicit_true": "$(location :debug_string_test_generate) > $@", "//conditions:default": "cp $(location debug_string_test.fasttable.txt) $@", }), tools = [":debug_string_test_generate"], diff --git a/upb/port/BUILD b/upb/port/BUILD index 5e068b50be..e8fad9e41f 100644 --- a/upb/port/BUILD +++ b/upb/port/BUILD @@ -22,7 +22,8 @@ cc_library( ], copts = UPB_DEFAULT_COPTS, defines = select({ - "//upb:fasttable_enabled_setting": ["UPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_explicit_true": ["UPB_ENABLE_FASTTABLE"], + "//upb:fasttable_enabled_setting": ["UPB_TRY_ENABLE_FASTTABLE"], "//conditions:default": [], }), features = UPB_DEFAULT_FEATURES,