Skip to content

feat: feature-gated dep sources + mcpp add --dev — fix #168 gtest_main (v0.0.65)#169

Merged
Sunrisepeak merged 2 commits into
mainfrom
feat/gtest-main-feature-and-add-dev
Jun 25, 2026
Merged

feat: feature-gated dep sources + mcpp add --dev — fix #168 gtest_main (v0.0.65)#169
Sunrisepeak merged 2 commits into
mainfrom
feat/gtest-main-feature-and-add-dev

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Fixes #168mcpp add gtest + mcpp buildgtest_main.o : error LNK2005: main already defined.

根因

gtest 作为常规依赖时,其 gtest_main.cc(自带 main)被内联进应用,与应用 main 冲突。

方案:通用「feature 门控源」(非 gtest 特例)

  • 依赖描述符可声明 [mcpp].features.<名>.sources;被某 feature 列出的源默认不编译/链接,仅 dep = { version, features=["名"] } 请求时纳入。
  • gtest 描述符(mcpp-index, 已合入 feat(gtest): gate gtest_main behind 'main' feature (mcpp #168) mcpplibs/mcpp-index#45)把 gtest_main.cc 归入 main feature → 默认 gtest = "1.15.2" 只链框架(不撞 main);features=["main"] 显式开启。
  • 复用既有 feature 激活;新增「feature→源」作用(manifest.cppm synthesize + prepare.cppm)。
  • 门控仅 build 模式(!includeDevDeps);mcpp test 的 dev 依赖 main 检测(0.0.64)不变 → 两轨解耦。
  • 兼容:描述符把 gtest_main.cc 同时留在 base sources → 旧 mcpp(不认 features)行为不变(实测 0.0.64 mcpp test 仍正常)。

新增

  • mcpp add --dev <pkg> → 写 [dev-dependencies](原缺失)。

测试 / 其它

本机验证

24+ 单测 + e2e 78(dev 轨回归)+ e2e 79(src 轨)全绿;#168 场景 build 不再链 gtest_main。

🤖 Generated with Claude Code

…st_main)

#168: gtest as a regular dependency injected gtest_main.o (its own main) into a
`mcpp build` app, colliding with the app's main (LNK2005 / duplicate symbol).

Generic fix — feature-gated sources:
- A dependency descriptor may declare `[mcpp].features.<name>.sources`; a source
  listed there is EXCLUDED from the default build and only compiled/linked when
  that feature is active for the dep (`dep = { version, features=["name"] }`).
- gtest descriptor (mcpp-index) puts gtest_main.cc behind the `main` feature →
  default `gtest = "1.15.2"` links framework only (no main collision); opt in
  with `features=["main"]`. Reuses the existing feature activation; new effect
  is "feature → sources" (manifest.cppm synthesize + prepare.cppm).
- Gating applies only in build mode (!includeDevDeps); `mcpp test` keeps the
  dev-dependency main-detection track (0.0.64) unchanged — the two tracks stay
  decoupled. Descriptor keeps gtest_main.cc in base `sources` too, so OLD mcpp
  (ignores `features`) is unaffected (verified).

mcpp add --dev <pkg> → writes [dev-dependencies] (was missing).

- unit: SynthesizeFromXpkgLua.FeatureGatedSources
- e2e:  79_gtest_regular_dep_feature_main.sh (#168 sentinel + opt-in + add --dev)
- release.yml: default xlings 0.4.58 -> 0.4.60 (cache key bumped)
- bump 0.0.64 -> 0.0.65
- design: .agents/docs/2026-06-25-gtest-main-feature-and-add-dev-design.md
…printf

macOS BSD find lacks -printf → nj came back empty → false 'gtest-all not linked'.
Functionality was fine (78 passed, build succeeded). Use find | xargs ls -t.
@Sunrisepeak Sunrisepeak merged commit 0f96b82 into main Jun 25, 2026
5 checks passed
@Sunrisepeak Sunrisepeak deleted the feat/gtest-main-feature-and-add-dev branch June 25, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

在mcpp.toml的[dependences]添加gtest依赖时,gtest_main与程序入口main函数冲突问题

1 participant