summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflarembo <[email protected]>2025-09-13 20:00:32 +0300
committerflarembo <[email protected]>2025-09-13 20:15:47 +0300
commit03549e7e60cafdc096db6ba38e329a9af7fc56e0 (patch)
treedccfaeb8b33247a071768f6b673a09af49f59e69
parent6fd09c255b992c1419140f9ed8af5adb21253c36 (diff)
Build proto library with optimize for X selected from ya.make
commit_hash:b50b1b3d3590a8b3bbf2e323e05883492f0f5f73
-rw-r--r--build/conf/proto.conf25
-rw-r--r--build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json8
-rw-r--r--build/ymake.core.conf10
-rw-r--r--contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp38
4 files changed, 60 insertions, 21 deletions
diff --git a/build/conf/proto.conf b/build/conf/proto.conf
index b05ad615143..dead9dd70e0 100644
--- a/build/conf/proto.conf
+++ b/build/conf/proto.conf
@@ -7,6 +7,7 @@ when ($PYTHON2 == "yes") {
PY_PROTOC=${PROTOC_OLD}
}
JAVA_PROTOC=${JAVA_PROTOC_RESOURCE_GLOBAL}/bin/protoc
+PROTO_LAYOUT=
when ($OPENSOURCE_REPLACE_PROTOBUF) {
PROTOC_STYLEGUIDE_OUT=
@@ -15,7 +16,7 @@ when ($OPENSOURCE_REPLACE_PROTOBUF) {
DEFAULT_PROTOC_TOOLS=
}
otherwise {
- PROTOC_STYLEGUIDE_OUT=--cpp_styleguide_out=$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE
+ PROTOC_STYLEGUIDE_OUT=--cpp_styleguide_out=${PROTO_LAYOUT}:$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE
PROTOC_PLUGIN_STYLEGUIDE=--plugin=protoc-gen-cpp_styleguide=${tool:"contrib/tools/protoc/plugins/cpp_styleguide"}
PROTOBUF_INCLUDE_PATH=${ARCADIA_ROOT}/contrib/libs/protobuf/src
PROTOBUF_OLD_PATH=${ARCADIA_ROOT}/contrib/libs/protobuf_old/src
@@ -74,6 +75,28 @@ macro CPP_PROTOLIBS_DEBUG_INFO() {
SET(NO_DEBUGINFO $CPP_PROTO_NO_DBGINFO)
}
+# tag:proto
+### @usage: SELECT_PROTO_LAYOUT(PROTO_LAYOUT)
+###
+### Select proto layout for generation. Options repeated options from generator.cc (optimize for)
+macro SELECT_PROTO_LAYOUT(PROTO_LAYOUT) {
+ select ($PROTO_LAYOUT) {
+ "speed" ? {
+ }
+ "code_size" ? {
+ }
+ "lite" ? {
+ }
+ "lite_implicit_weak_fields" ? {
+ }
+ default ? {
+ _OK = no
+ }
+ }
+ ASSERT(_OK SELECT_PROTO_LAYOUT macro can be used only with parametrs from proto generator.cc. Used `$PROTO_LAYOUT`.)
+ PROTO_LAYOUT=$PROTO_LAYOUT
+}
+
# tag:internal
### @usage: _ORDER_ADDINCL([BUILD ...] [SOURCE ...] Args...) # internal
###
diff --git a/build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json b/build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json
index 5d58384e1f5..e3b34857db8 100644
--- a/build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json
+++ b/build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json
@@ -1,16 +1,16 @@
{
"by_platform": {
"darwin": {
- "uri": "sbr:7041923114"
+ "uri": "sbr:9712256178"
},
"darwin-arm64": {
- "uri": "sbr:7041925436"
+ "uri": "sbr:9712256812"
},
"linux": {
- "uri": "sbr:7041926554"
+ "uri": "sbr:9712256953"
},
"win32": {
- "uri": "sbr:7041924289"
+ "uri": "sbr:9712256619"
}
}
}
diff --git a/build/ymake.core.conf b/build/ymake.core.conf
index a9a32ea0bac..8d5b63f0039 100644
--- a/build/ymake.core.conf
+++ b/build/ymake.core.conf
@@ -603,7 +603,7 @@ module _BASE_UNIT: _BARE_UNIT {
PEERDIR_TAGS=CPP_PROTO CPP_PROTO_FROM_SCHEMA CPP_FBS CPP_ROS CPP_MLAUNCH CPP_PY3_MLAUNCH H_IDL PY3 PY3_NATIVE YQL_UDF_STATIC __EMPTY__ RESOURCE_LIB DLL_LIB
_CPP_PROTO_WRAPPER_BASE=$YMAKE_PYTHON3 ${input:"build/scripts/cpp_proto_wrapper.py"}
- _CPP_PROTO_CMDLINE_BASE=${cwd;rootdir;input:File} $PROTOC -I=./$PROTO_NAMESPACE -I=$ARCADIA_ROOT/$PROTO_NAMESPACE ${pre=-I=:_PROTO__INCLUDE} -I=$ARCADIA_BUILD_ROOT -I=$PROTOBUF_INCLUDE_PATH --cpp_out=${CPP_PROTO_PLUGINS}$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE $_PROTOC_FLAGS $PROTOC_STYLEGUIDE_OUT $PROTOC_PLUGIN_STYLEGUIDE ${hide:PROTO_FAKEID} ${rootrel;input:File}
+ _CPP_PROTO_CMDLINE_BASE=${cwd;rootdir;input:File} $PROTOC -I=./$PROTO_NAMESPACE -I=$ARCADIA_ROOT/$PROTO_NAMESPACE ${pre=-I=:_PROTO__INCLUDE} -I=$ARCADIA_BUILD_ROOT -I=$PROTOBUF_INCLUDE_PATH --cpp_out=${CPP_PROTO_PLUGINS}:$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE $_PROTOC_FLAGS $PROTOC_STYLEGUIDE_OUT $PROTOC_PLUGIN_STYLEGUIDE ${hide:PROTO_FAKEID} ${rootrel;input:File}
CPP_PROTO_CMDLINE=$_CPP_PROTO_WRAPPER_BASE --outputs $CPP_PROTO_OUTS -- $_CPP_PROTO_CMDLINE_BASE
CPP_PROTO_OUTS+=${norel;output;suf=.pb.cc;nopath;noext:File} ${main;norel;output;suf=.pb.h;nopath;noext:File}
CPP_PROTO_OUTS_SEM+=${hide;main;norel;output;suf=.pb.h;nopath;noext:File}
@@ -649,11 +649,17 @@ module _BASE_UNIT: _BARE_UNIT {
_PROTO_CMDLINE=$_CPP_VANILLA_PROTO_CMDLINE
}
when ($PROTOC_TRANSITIVE_HEADERS == "no") {
- CPP_PROTO_PLUGINS=proto_h=true:${CPP_PROTO_PLUGINS}
+ CPP_PROTO_PLUGINS=proto_h=true${CPP_PROTO_PLUGINS}
CPP_PROTO_OUTS+=${main;norel;output;suf=.deps.pb.h;nopath;noext:File}
CPP_PROTO_OUTS_SEM+=${hide;main;norel;output;suf=.deps.pb.h;nopath;noext:File}
PROTOC_EXTRA_OUTS_SEM=&& protoc_extra_outs .deps.pb.h
}
+ when ($PROTO_LAYOUT != "") {
+ when ($CPP_PROTO_PLUGINS != "") {
+ CPP_PROTO_PLUGINS+=,
+ }
+ CPP_PROTO_PLUGINS+=$PROTO_LAYOUT
+ }
}
SANITIZER_DEFINED=no
diff --git a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp
index 900ec3d64f2..aa85856bc0d 100644
--- a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp
+++ b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp
@@ -49,8 +49,8 @@ namespace NPlugins {
return basename.append(".pb.cc");
}
- bool IsLiteRuntimeMessage(const Descriptor* desc) {
- return desc->file() != NULL && desc->file()->options().optimize_for() == google::protobuf::FileOptions::LITE_RUNTIME;
+ bool IsLiteRuntimeMessage(const Descriptor* desc, bool forceLite) {
+ return forceLite || (desc->file() != NULL && desc->file()->options().optimize_for() == google::protobuf::FileOptions::LITE_RUNTIME);
}
bool IsAutogeneratedNestedType(const Descriptor* desc) {
@@ -579,14 +579,15 @@ namespace NPlugins {
class TMessageExtGenerator {
public:
- TMessageExtGenerator(const Descriptor* descriptor, OutputDirectory* outputDirectory)
+ TMessageExtGenerator(const Descriptor* descriptor, OutputDirectory* outputDirectory, bool forceLite)
: Descriptor_(descriptor)
, Classname_(ClassName(descriptor, false))
, OutputDirectory_(outputDirectory)
+ , forceLite_(forceLite)
{
for (int i = 0; i < descriptor->nested_type_count(); i++) {
if (!IsAutogeneratedNestedType(descriptor->nested_type(i))) {
- NestedGenerators_.emplace_back(descriptor->nested_type(i), OutputDirectory_);
+ NestedGenerators_.emplace_back(descriptor->nested_type(i), OutputDirectory_, forceLite_);
}
}
@@ -691,7 +692,7 @@ namespace NPlugins {
}
TVariables vars;
vars["class"] = ClassName(Descriptor_, false);
- if (!IsLiteRuntimeMessage(Descriptor_)) {
+ if (!IsLiteRuntimeMessage(Descriptor_, forceLite_)) {
printer.Print("TProtoStringType ShortUtf8DebugString() const;\n");
printer.Print("void PrintJSON(IOutputStream&) const override;\n");
@@ -714,7 +715,7 @@ namespace NPlugins {
TVariables vars;
vars["class"] = Classname_;
- if (!IsLiteRuntimeMessage(Descriptor_)) {
+ if (!IsLiteRuntimeMessage(Descriptor_, forceLite_)) {
printer.Print("// Yandex-specific extension\n");
printer.Print(vars, "void $class$::Save(IOutputStream* output) const {\n");
printer.Print(" ::Save(output, static_cast<const ::google::protobuf::Message&>(*this));\n");
@@ -735,7 +736,7 @@ namespace NPlugins {
TVariables vars;
vars["class"] = Classname_;
- if (!IsLiteRuntimeMessage(Descriptor_)) {
+ if (!IsLiteRuntimeMessage(Descriptor_, forceLite_)) {
printer.Print("// Yandex-specific extension\n");
printer.Print(vars, "TProtoStringType $class$::ShortUtf8DebugString() const {\n");
printer.Print(" return ::ShortUtf8DebugString(*this);\n");
@@ -745,7 +746,7 @@ namespace NPlugins {
}
void GenerateJSONImplementation() {
- if (IsLiteRuntimeMessage(Descriptor_)) {
+ if (IsLiteRuntimeMessage(Descriptor_, forceLite_)) {
return;
}
@@ -803,7 +804,7 @@ namespace NPlugins {
std::unique_ptr<io::ZeroCopyOutputStream> output(
OutputDirectory_->OpenForInsert(fileName, scope));
io::Printer printer(output.get(), '$');
- if (!IsLiteRuntimeMessage(Descriptor_)) {
+ if (!IsLiteRuntimeMessage(Descriptor_, forceLite_)) {
printer.Print("// Yandex debug output extension\n");
TVariables vars;
vars["class"] = ClassName(Descriptor_, true);
@@ -846,17 +847,18 @@ namespace NPlugins {
std::vector<TMessageExtGenerator> NestedGenerators_;
std::vector<TExtensionGenerator> ExtensionGenerators_;
std::vector<TOneofGenerator> OneofGenerators_;
+ bool forceLite_;
};
class TFileExtGenerator {
public:
- TFileExtGenerator(const FileDescriptor* file, OutputDirectory* output_directory)
+ TFileExtGenerator(const FileDescriptor* file, OutputDirectory* output_directory, bool forceLite)
: File_(file)
, OutputDirectory_(output_directory)
{
MessageGenerators_.reserve(file->message_type_count());
for (int i = 0; i < file->message_type_count(); i++) {
- MessageGenerators_.emplace_back(file->message_type(i), OutputDirectory_);
+ MessageGenerators_.emplace_back(file->message_type(i), OutputDirectory_, forceLite);
}
}
@@ -904,12 +906,20 @@ namespace NPlugins {
};
bool TCppStyleGuideExtensionGenerator::Generate(const FileDescriptor* file,
- const TProtoStringType&,
+ const TProtoStringType& parameter,
OutputDirectory* outputDirectory,
TProtoStringType*) const {
+ std::vector<std::pair<TProtoStringType, TProtoStringType>> options;
+ ParseGeneratorParameter(parameter, &options);
+ bool forceLite = false;
+ for (const auto& option: options) {
+ if (option.first == "lite") {
+ forceLite = true;
+ break;
+ }
+ }
- TFileExtGenerator fileGenerator(file, outputDirectory);
-
+ TFileExtGenerator fileGenerator(file, outputDirectory, forceLite);
// Generate header.
fileGenerator.GenerateHeaderExtensions();