fix(build): 修复 Debug 构建链接失败(托盘守卫 + big-obj) - #906
Conversation
Two independent link failures, both only reachable outside the Release CI matrix, cherry-picked from #845 (the rest of that PR is superseded by the SETMODES architecture). main.cpp held the only three unguarded system_tray:: references in the tree. Since the Windows tray moved to the bundled GUI agent, SUNSHINE_ENABLE_TRAY=ON with SUNSHINE_ENABLE_LEGACY_TRAY=OFF (the default) yields SUNSHINE_TRAY=0, and system_tray.cpp is then an empty translation unit. Release links anyway because `constexpr bool tray_is_enabled = false` lets the optimizer drop the branches before the linker sees them; at -O0 it does not, so the default configuration fails to link. Guard the three sites to match every other call site. The in-process tray is still the live path on Linux (SUNSHINE_TRAY=1 whenever appindicator and libnotify are present), so these calls are kept rather than removed. The #else branch in mainThreadLoop blocks on shutdown_event instead of falling through: run_loop is only ever set by the tray today, but a fall-through would return into main() and tear the host down if that ever changes. confighttp.cpp exceeds the 32767-section COFF limit, where the assembler silently emits a corrupt symbol table and its COMDAT entries (typeinfo, inline members) resolve as undefined. -Wa,-mbig-obj fixes it; the flag is scoped to CXX, and the Windows toolchain is MinGW GCC only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (1)
Summary by CodeRabbit
WalkthroughWindows GNU C++ 构建新增 Changes构建与系统托盘
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cmake/compile_definitions/windows.cmake (1)
21-21: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win按 GCC 编译器类型限定
-Wa,-mbig-obj。
include(${CMAKE_MODULE_PATH}/compile_definitions/windows.cmake)对所有 Windows C++ 配置生效,而该选项是 GNU/MinGW 汇编器选项;MSVC 或clang-cl等编译器会拒绝它并导致构建失败。CUDA 继承路径也会将SUNSHINE_COMPILE_OPTIONS用--compiler-options=...转发到 CUDA 主机编译。只在对已验证支持的 GNU MinGW C++ 编译器添加该选项;例如使用$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wa,-mbig-obj>,或先在工具链中限制 Windows 构建为 GCC/MinGW。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmake/compile_definitions/windows.cmake` at line 21, 仅在 GNU/MinGW C++ 编译器下向 SUNSHINE_COMPILE_OPTIONS 添加 -Wa,-mbig-obj;使用基于 COMPILE_LANG_AND_ID 的生成器表达式或等效编译器条件,确保 MSVC、clang-cl 及 CUDA 主机编译转发路径不会接收到该选项。Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cmake/compile_definitions/windows.cmake`:
- Line 21: 仅在 GNU/MinGW C++ 编译器下向 SUNSHINE_COMPILE_OPTIONS 添加 -Wa,-mbig-obj;使用基于
COMPILE_LANG_AND_ID 的生成器表达式或等效编译器条件,确保 MSVC、clang-cl 及 CUDA 主机编译转发路径不会接收到该选项。
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 889e67a8-980d-47ab-b6c4-ea236f09c654
📒 Files selected for processing (2)
cmake/compile_definitions/windows.cmakesrc/main.cpp
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
- GitHub Check: Windows
🧰 Additional context used
📓 Path-based instructions (2)
cmake/**
⚙️ CodeRabbit configuration file
cmake/**: CMake 构建系统文件。审查跨平台兼容性、现代 CMake 实践。
Files:
cmake/compile_definitions/windows.cmake
src/**/*.{cpp,c,h}
⚙️ CodeRabbit configuration file
src/**/*.{cpp,c,h}: Sunshine 核心 C++ 源码,自托管游戏串流服务器。审查要点:内存安全、 线程安全、RAII 资源管理、安全漏洞。注意预处理宏控制的平台相关代码。
Files:
src/main.cpp
🔇 Additional comments (3)
src/main.cpp (3)
108-113: LGTM!
134-141: LGTM!
489-503: 🎯 Functional Correctness请补充跨平台全量构建验证。
该条件编译会在
SUNSHINE_TRAY < 1时移除全部托盘初始化代码。请确认 Linux 等非 Windows 目标在启用托盘时定义SUNSHINE_TRAY=1,禁用时定义为0。然后补充 Windows MSYS2 UCRT64 Debug 全量构建和 Linux 全量构建,并验证退出流程可以正常完成。
clang only warns about an unknown -Wno-*, but rejects an unknown -Wa, argument outright, so the flag would hard-fail a clang-based MinGW build (MSYS2 CLANG64) where the adjacent GCC-only warning flags survive. Gate it on the compiler ID. Uses a plain if() rather than a COMPILE_LANG_AND_ID generator expression: cmake/targets/common.cmake wraps every SUNSHINE_COMPILE_OPTIONS entry as --compiler-options=<flag> when CUDA_INHERIT_COMPILE_OPTIONS is on (the default), so a genex in that list would degrade to a bare --compiler-options= for CUDA translation units. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
已按 review 门控 原意见的两条理由核实后都不成立MSVC / clang-cl: CUDA 主机编译转发: 但门控确实该做,理由是另一个实测 clang 对两类未知 flag 的处理是不对称的: 所以相邻的 为什么没用
|
概述
从 #845 摘出两处独立的构建修复。#845 的主体(VDD 模式 XML 缓存)在当前 SETMODES 架构下已无收益且有回归风险,建议单独关掉,本 PR 不含那部分。
两处问题都只在 Release CI 矩阵之外触发,所以 CI 一直是绿的。
变更内容
1.
main.cpp托盘守卫main.cpp的 3 处system_tray::引用是全仓库仅剩的未加守卫的调用点——vdd_utils、stream、process、pairing、audio、tray_state,以及main.cpp自己的end_tray()两处,全都有#if defined SUNSHINE_TRAY && SUNSHINE_TRAY >= 1。托盘统一到 GUI agent 之后,Windows 默认配置是
SUNSHINE_ENABLE_TRAY=ON+SUNSHINE_ENABLE_LEGACY_TRAY=OFF(见cmake/prep/options.cmake),推导出SUNSHINE_TRAY=0/SUNSHINE_GUI_TRAY=1。此时src/tray/system_tray.cpp整个文件体被#if SUNSHINE_TRAY >= 1包住,是个空编译单元,不产生任何符号。Release 能链接过只是因为
constexpr bool tray_is_enabled = false让优化器在链接器看到之前就删掉了分支;-O0不删,于是默认配置的 Debug 构建链接失败。2.
-Wa,-mbig-objconfighttp.cpp等模板密集编译单元超过 COFF 32767 段上限,汇编器静默写坏 COMDAT 符号表,Debug 链接报大量 typeinfo/内联符号未定义。设计取舍
为什么加守卫而不是删掉这几行。 托盘统一到 GUI agent 是 Windows-only 的。Linux 上
cmake/compile_definitions/linux.cmake在 appindicator + libnotify 存在时仍设SUNSHINE_TRAY=1,mainThreadLoop里的process_tray_events()就是 Linux 托盘的事件泵,init_tray()也是活代码。删掉会直接破坏 Linux。tray_state.cpp的tray_owner()返回core/gui/disabled三态,也印证三种配置都还在支持范围内。mainThreadLoop的#else分支为什么阻塞而不是留空。run_loop目前只由托盘条件置位,所以SUNSHINE_TRAY=0时那段不可达。但如果只写#if/#endif,将来一旦有别的 main-thread 特性把run_loop置真,函数会直接返回到main()并立刻走完整个关闭流程。#else里shutdown_event->view()保持了阻塞语义。[[maybe_unused]]。 加守卫后tray_is_enabled在 Windows +SUNSHINE_TRAY=0下失去唯一读者(mainThreadLoop里那处在#ifndef _WIN32内)。GCC 的-Wunused-const-variable在 C++ 下不随-Wall开启,所以现网 msys2 GCC 不会报;但 clang 会,BUILD_WERROR=ON时是 error。加[[maybe_unused]]以免依赖编译器特定的告警行为。测试
未做完整构建验证——本地无 cmake/ninja 环境,且 CI 只跑 Release(问题本身不在 Release 中出现)。已验证的部分:
mainThreadLoop/ 托盘初始化两段连同预处理条件抽成独立编译单元,在SUNSHINE_TRAY×_WIN32四种组合下用-Wall -Wno-sign-compare -Werror(项目实际告警配置)全部通过system_tray::引用,确认改后无遗漏的未守卫调用点-Wa,-mbig-obj经cmake/targets/common.cmake只作用于COMPILE_LANGUAGE:CXX;windows.cmake无 MSVC/clang-cl 分支,CI 用 msys2 ucrt64 GCC,与文件内既有的 GCC 专用 flag 一致需要 reviewer 补的验证:Windows Debug(MSYS2 UCRT64)默认配置全量重编译 + 链接,以及一次 Linux 构建确认托盘仍正常。
🤖 Generated with Claude Code