-
Notifications
You must be signed in to change notification settings - Fork 497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support customed cpp_outs and options for plugins in proto_library #1047
Conversation
noanswer
commented
Oct 24, 2024
- Generate customed cpp filenames in proto_library.
- Pass customed options to plugins in proto_library
If you want to generate some cpp code with other suffix names, you can use `cpp_outs` attributes. | ||
The default value is `['.pb']`. For example, if you want to use grpc plugin to generate `rpc_meta_info.pb.cc/h` and `rpc_meta_info.grpc.pb.cc/h`, set `cpp_outs = [".pb', '.grpc.pb']` | ||
|
||
Besides, use `plugin_opts` to pass some options to plugins, like `plugin_opts={"plugin_name":["option1", "option2.."]},`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two attributes are actually belonged to the plugin. Can they be defined as plugin-level attributes ? By this way, they don't need to be written repeatedly for each proto_library call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cpp_outs and plugin_opts would be differnent in differnent targets. The plugin will fragment the original file into multiple pieces based on the size of the proto generated, which the user will specify in different targets, the default is divided into 3 pieces.
Here is the code we will add in BLADE_ROOT:
if get_env("USE_ADTABLE_PLUGIN_FAST_MODE"):
def _register_proto_library_wrapper():
from blade import proto_library_target
from blade import build_rules
def proto_library(*args, **kwargs):
default_opts = ["fast_mode", "sharding_size=3"]
default_cpp_outs = [".pb", ".core.pb", ".controller.pb", ".axu.pb", ".core.1.pb", ".core.2.pb", ".core.3.pb"]
default_applied = False
if "plugins" in kwargs and "adtable_codegen" in kwargs["plugins"]:
if "plugin_opts" not in kwargs:
kwargs["plugin_opts"] = {"adtable_codegen":default_opts}
default_applied = True
elif "adtable_codegen" not in kwargs["plugin_opts"]:
kwargs["plugin_opts"]["adtable_codegen"] = default_opts
default_applied = True
if default_applied:
if "cpp_outs" not in kwargs:
kwargs["cpp_outs"] = []
kwargs["cpp_outs"].extend(default_cpp_outs)
kwargs["cpp_outs"] = list(set(kwargs["cpp_outs"])) # unique
return proto_library_target.proto_library(*args, **kwargs)
build_rules.register_function(proto_library)
_register_proto_library_wrapper()