Re-enable FastTable for non-opt builds.

PiperOrigin-RevId: 969943256
This commit is contained in:
Protobuf Team Bot 2026-08-24 10:41:04 -07:00 committed by Copybara-Service
parent 2d75af0868
commit 1c749d54d7
5 changed files with 100 additions and 19 deletions

View file

@ -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

View file

@ -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,

View file

@ -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": [],
})

View file

@ -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"],

View file

@ -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,