feat: 一条依赖 + 一行 build.mcpp —— codegen 工具链由本包交给用户 - #3
Merged
Conversation
使用者此前要写四条依赖,并且要知道「gRPC 的代码生成需要 protobuf 的 protoc」。
那是**本包**的知识,不是用户的。
[dependencies.grpc]
grpc = { version = "1.83.0", features = ["codegen"] }
import mcpp; import grpcgen;
int main() { return grpcgen::generate_all() ? 0 : 1; }
两处引擎能力使它成立(mcpp 2026.8.6.2):
* `reexport = true` —— `[feature-deps.codegen]` 把 protoc、grpc_cpp_plugin
与 grpcgen 规则模块交给**消费者**。codegen 默认关闭:protoc 会拖进 libprotoc
约 157 个额外 TU,只链接 gRPC 的项目不该为它付钱。
* `rerun_if_changed_glob` —— `generate_all()` 才是安全的。在此之前扫目录**结构性
不安全**:新增一个 .proto 不改变任何已声明文件的哈希,程序不重跑,新文件静默
不生成。这正是本仓库当初选择显式列表的原因。
examples/greeter 保留 path 依赖(它要测的是工作树,而 feature 里写的是索引
版本),但同样改用 generate_all(),于是 glob 路径在本仓库 CI 里有覆盖;一条
依赖的形态由已发布索引验证。
MCPP_VERSION 下限 2026.8.5.2 → 2026.8.6.2。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
需要 mcpp 2026.8.6.2(已发布)。
使用者侧
后三条依赖此前全是为了 codegen,并且要求用户知道「gRPC 的代码生成需要 protobuf 的 protoc」——那是本包的知识。新增一个
.proto现在只是往proto/里放一个文件,没有需要同步维护的清单。靠什么成立
两处引擎能力,都在 mcpp 2026.8.6.2(mcpp#359):
reexport = true——[feature-deps.codegen]把 protoc、grpc_cpp_plugin 与 grpcgen 规则模块交给消费者。默认关闭:protoc 会拖进 libprotoc 约 157 个额外 TU,只链接 gRPC 的项目不该为它付钱。rerun_if_changed_glob——generate_all()才是安全的。在此之前扫目录结构性不安全:新增一个.proto不改变任何已声明文件的哈希,build.mcpp 不重跑,新文件静默不生成(实测Finished dev in 0.01s、产物 0 个)。这正是本仓库当初选择显式列表的原因。顺带,
[feature-deps.codegen]往已经无条件声明的compat.protobuf那条边上追加tools+reexport,这在 mcpp 侧也是本次才成立的(此前try_emplace会把 feature 的 spec 整个丢掉)。挪到无条件条目上不可行——那会让每个 grpc 消费者都构建 protoc。本仓库内的验证
examples/greeter保留 path 依赖(它要测的是工作树,而 feature 里写的是索引版本),但同样改用generate_all(),于是 glob 路径在本仓库 CI 里有覆盖。已在本机跑通:然后往
proto/里丢一个extra.proto、不改 build.mcpp 一个字,重新构建即产出extra.pb.cc/.h与extra.grpc.pb.cc/.h并编进目标。一条依赖的形态由已发布索引验证(见下)。
其他
generate()的入参从initializer_list<const char*>改为vector<string>,generate_all()复用它;两者都会为嵌套.proto建好输出子目录——protoc 会按相对路径写,但不建中间目录,平铺的proto/从不暴露这一点。MCPP_VERSION下限 2026.8.5.2 → 2026.8.6.2。合入后
发
v1.83.0-3,mcpp-index 三个描述符换 url + sha256,并新增tests/examples/grpc-codegen成员——它是唯一能证明「reexport真的经由已发布索引到达消费者」的地方,顺便让grpc-module里那句「gRPC's codegen needs host tools mcpp cannot hand a consumer」不再过时。