Skip to content

Commit 191cc4a

Browse files
committed
refactor(tests): 一个条件写一次 —— cfg(linux)+cfg(macos) 合成 cfg(unix)
两个 grpc 成员各有一对逐字相同的 [target.'cfg(linux)'] 与 [target.'cfg(macos)'] 段。它们表达的是**一个**事实——compat.openssl 没有 windows xpm 条目,所以 gRPC 在 windows 之外都可解析——一个事实 写两遍,就是下一次只改一处的机会。 mcpp 的谓词语言本来就够用:any()/all()/not() 加 unix 别名 (family == "unix",见 src/build/prepare.cppm 的 match_alias)。 本机核验:cfg(unix) 下 grpc-codegen 照常解析出 c-ares/openssl/re2/zlib。
1 parent c2745be commit 191cc4a

2 files changed

Lines changed: 14 additions & 17 deletions

File tree

tests/examples/grpc-codegen/mcpp.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@
2828
name = "grpc-codegen-tests"
2929
version = "0.1.0"
3030

31-
[target.'cfg(linux)'.dependencies.grpc]
31+
# `cfg(unix)`, not one block per OS: the condition is "everywhere gRPC
32+
# resolves", and what excludes windows is compat.openssl having no xpm entry
33+
# there — a single fact, so a single predicate. mcpp evaluates `unix` as
34+
# family == "unix" (src/build/prepare.cppm, alongside any()/all()/not()).
35+
[target.'cfg(unix)'.dependencies.grpc]
3236
grpc = { version = "1.83.0", features = ["codegen"] }
3337

34-
[target.'cfg(linux)'.build]
35-
cxxflags = ["-DHAVE_GRPC=1"]
36-
37-
[target.'cfg(macos)'.dependencies.grpc]
38-
grpc = { version = "1.83.0", features = ["codegen"] }
39-
40-
[target.'cfg(macos)'.build]
38+
[target.'cfg(unix)'.build]
4139
cxxflags = ["-DHAVE_GRPC=1"]
4240

4341
# windows carries the RULE but not gRPC itself, so build.mcpp compiles (its

tests/examples/grpc-module/mcpp.toml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,19 @@
1818
name = "grpc-module-tests"
1919
version = "0.1.0"
2020

21-
# linux + macOS only: the package has no windows xpm entry (its compat.openssl
21+
# unix only: the package has no windows xpm entry (its compat.openssl
2222
# dependency has none yet), so on windows this member carries no dependency at
2323
# all and the test compiles to a no-op main() — the same shape
2424
# tests/examples/openssl uses for the same underlying reason.
25-
[target.'cfg(linux)'.dependencies.grpc]
26-
grpc = "1.83.0"
27-
28-
[target.'cfg(linux)'.build]
29-
cxxflags = ["-DHAVE_GRPC=1"]
30-
31-
[target.'cfg(macos)'.dependencies.grpc]
25+
#
26+
# One `cfg(unix)` rather than a linux block and an identical macos block: the
27+
# condition is a single fact ("gRPC resolves everywhere except windows"), so it
28+
# should be written once. mcpp evaluates `unix` as family == "unix"
29+
# (src/build/prepare.cppm, alongside any()/all()/not()).
30+
[target.'cfg(unix)'.dependencies.grpc]
3231
grpc = "1.83.0"
3332

34-
[target.'cfg(macos)'.build]
33+
[target.'cfg(unix)'.build]
3534
cxxflags = ["-DHAVE_GRPC=1"]
3635

3736
[indices]

0 commit comments

Comments
 (0)