From 43415fca4c689348e9c7f143db96811ba69a9761 Mon Sep 17 00:00:00 2001 From: sunrisepeak Date: Thu, 25 Jun 2026 13:29:56 +0800 Subject: [PATCH] feat(gtest): gate gtest_main.cc behind 'main' feature (mcpp #168) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gtest_main.cc provides its own main(); linked by default it collides with a consumer's own main (e.g. app via mcpp add gtest + mcpp build → LNK2005). Gate it behind the 'main' feature: kept in base sources (old mcpp ignores features → no regression) AND listed under features.main.sources so new mcpp (>=0.0.65) excludes it by default and includes it only with gtest = { version=..., features=["main"] }. mcpp test's dev-dep main detection is unaffected (gating is build-mode only). --- pkgs/c/compat.gtest.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/c/compat.gtest.lua b/pkgs/c/compat.gtest.lua index 40631d2..37e0e57 100644 --- a/pkgs/c/compat.gtest.lua +++ b/pkgs/c/compat.gtest.lua @@ -53,6 +53,18 @@ package = { "*/googletest", }, targets = { ["gtest"] = { kind = "lib" } }, + -- gtest_main.cc provides its own main(); it must NOT be linked by + -- default (it would collide with a binary's own main, e.g. an app via + -- `mcpp add gtest` + `mcpp build`, or a test that writes its own main). + -- It is listed BOTH in `sources` (so OLD mcpp, which ignores `features`, + -- keeps today's behavior — no regression) AND here under the `main` + -- feature: NEW mcpp treats a feature-listed source as gated → excluded + -- by default, included only when `features = ["main"]` is requested on + -- the gtest dependency. See + -- mcpp .agents/docs/2026-06-25-gtest-main-feature-and-add-dev-design.md. + features = { + ["main"] = { sources = { "*/googletest/src/gtest_main.cc" } }, + }, deps = { }, }, }