Repository navigation
refactor: introduce app_common static library for app-layer glue - #1006
hsheng27120 wants to merge 1 commit into
Conversation
zhangzhend0ng
left a comment
There was a problem hiding this comment.
Review verdict: Request changes
The build-graph refactor is sound overall — direction, symbol-closure semantics, and the compatibility claims all check out on inspection. Two items to address before merge (details inline):
- [Must fix]
BURY_API'sBURY_IMPORT_FROM_DLLstate is defined nowhere in the tree, and its comment misattributes usage to the Windows shim (which actually compilesbury_point.cpplocally withBURY_EXPORTS). Remove the dead state or fix the comment. → inline onsrc/app_common/bury_point.hpp - [Project standard] New comments in
src/app_common/bury_point.hpp, theapp_commonblock ofsrc/CMakeLists.txt, and the link block ofsrc/slic3r/CMakeLists.txtare in Chinese; the project coding standard requires English. Please translate.
Verified clean
- Macro removals safe:
BP_LOCAL_SERVERwas defined twice in the old header; this PR removes only the duplicate. The kept define (app_common/bury_point.hpp:56) still serves the 4 uses inHttpServer.cpp;BP_LOCAL_SERVER_ERR_CODEhas zero remaining users. - No stale references: no remaining
sentry_wrapper/,bury_cfg/,dev-utils/BaseException|StackWalkerincludes anywhere (src/tests/sandboxes); include casing is exact — thestackwalker.h→StackWalker.hchange fixes a latent case-sensitivity trap. - Target scoping:
app_commonandlibslic3r_guiare both behindSLIC3R_GUI;encoding_checkis defined before first use;tests/slic3rutilslinkslibslic3r_guiunder aTARGET libslic3r_guiguard, so usage requirements propagate to exactly the consumers this PR unblocks. - Plain-signature link is correct:
libslic3r_gui's existingtarget_link_librariescalls are all plain; CMake forbids mixing signatures on one target, so the keyword-lesstarget_link_libraries(libslic3r_gui app_common)is the required form here. - Linkage equivalence: DLL keeps its dllexport bury/sentry copy (state host), shim keeps its local copy (MESA/opengl32 fallback design untouched), non-Windows exe unchanged (
extern). Plain references binding to same-image definitions is semantically equivalent to the previous per-image dllimport usage; lazy archive extraction avoids duplicate symbols — author-verified on MSVC Release, and GNU ld/ld64 share the same lazy semantics.
Merge gates
- Linux/macOS builds not yet exercised (explicitly declared in the description — thanks). CI must be green on all platforms before merge.
- Advisory inline: add a phase-2 TODO for retiring the shadow-library double compilation.
- For the record, no action needed: branch name
app-common-static-liblacks therefactor_prefix per workflow conventions.
| // BURY_API 三态: | ||
| // BURY_IMPORT_FROM_DLL —— 仅 Windows exe shim:状态宿主是 Snapmaker_Orca.dll,必须跨镜像读写; | ||
| // BURY_EXPORTS —— 直接编入 Snapmaker_Orca.dll 的形态,导出 bury 符号供 shim 导入; | ||
| // 默认(空) —— app_common 静态库及其它一切 TU:普通符号引用,可绑定同镜像内任意声明形态的定义。 | ||
| // 默认值刻意不再是 dllimport:后者会让引用退化为 __imp_ 形式,强制消费者必须提供导入库。 | ||
| #ifdef _WIN32 | ||
| #ifdef BURY_EXPORTS | ||
| #ifdef BURY_IMPORT_FROM_DLL | ||
| #define BURY_API __declspec(dllimport) | ||
| #elif defined(BURY_EXPORTS) | ||
| #define BURY_API __declspec(dllexport) | ||
| #else | ||
| #define BURY_API __declspec(dllimport) | ||
| #define BURY_API | ||
| #endif |
There was a problem hiding this comment.
[Must fix] BURY_IMPORT_FROM_DLL is dead state and the comment above it is factually wrong.
Grepping the entire tree at this PR head: nothing defines BURY_IMPORT_FROM_DLL — no CMake target, no source file. Meanwhile the comment claims this state is for "仅 Windows exe shim" whose bury state lives in Snapmaker_Orca.dll. But the shim actually compiles app_common/bury_point.cpp locally with BURY_EXPORTS (see src/CMakeLists.txt, shim target) and keeps its own bury state — exactly the MESA/opengl32 design the PR description says is preserved. So today the dllimport branch is unreachable, and the comment misdescribes the shim's linkage.
Please either:
- drop
BURY_IMPORT_FROM_DLLand collapse to two states (BURY_EXPORTS→dllexport, default → plain), rewriting the comment; or - if this state is reserved for a planned future consumer, name that consumer in the comment instead of the shim.
This is linkage-critical machinery — a wrong "who imports what from where" comment is exactly what breaks the next refactor of the shim.
Same block, project standard: the new comments here (and in the app_common block of src/CMakeLists.txt, and the link block of src/slic3r/CMakeLists.txt) are in Chinese. The project coding standard requires no Chinese in source code — please translate to English, which also matches the English style of the surrounding linkage comments.
| # 阶段 1(影子库):生产目标 Snapmaker_Orca(DLL/exe)与 Windows shim 仍直接编译同源文件, | ||
| # 运行时行为零变化;本库先只服务 libslic3r_gui 及其下游。 | ||
| # ----------------------------------------------------------------------- | ||
| add_library(app_common STATIC |
There was a problem hiding this comment.
[Advisory] Phase-1 shadow library: the no-duplicate-symbol outcome depends on link order — please add a phase-2 TODO.
Production targets compile the glue sources directly and link app_common (transitively via libslic3r_gui). This resolves without LNK2005 only because direct objects precede archives on the link line and archive members are extracted lazily. That invariant is implicit — a future --whole-archive, link-line reorder, or source-set drift could surface duplicate-symbol errors.
Suggestion: add a # TODO(phase-2): production targets consume app_common and stop compiling these sources directly next to this target (plus a tracking issue), so the transitional state has an exit.
Minor: target_include_directories(app_common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) exposes all of src/ to every downstream consumer. Acceptable since it matches existing project practice; a follow-up could narrow it.
libslic3r_gui's symbol closure depended on app-layer glue (Sentry wrapper, bury-point state, BaseException/StackWalker) that only the production executable compiled, so downstream consumers (tests, headless tools) needed stub files or the Snapmaker_Orca import lib to link against the GUI library. - New src/app_common/ static library: move SentryWrapper from src/sentry_wrapper/, bury_point from src/bury_cfg/, and BaseException/StackWalker from src/dev-utils/ (phase-1 shadow library: production targets Snapmaker_Orca DLL/exe and the Windows shim still compile the same sources directly, zero runtime change) - Three-state BURY_API (import-from-dll / dllexport / plain) so references no longer default to dllimport and require an import lib - Update ~25 GUI/desktop files to the new "app_common/..." include path; link app_common into libslic3r_gui Verified: libslic3r_tests (Release) builds; [SSWCPProtocol] passes 77 assertions in 10 test cases. GUI/app targets not rebuilt. Co-Authored-By: Claude Code <noreply@anthropic.com>
943fc38 to
6f53f41
Compare
Description
libslic3r_gui's symbol closure depended on app-layer glue (Sentry wrapper, bury-point state,BaseException/StackWalker) that only the production executable compiled, so downstream consumers (tests, headless tools) needed stub files or theSnapmaker_Orcaimport library to link against the GUI library.Root cause: N/A (build/layout refactor, not a bug fix).
Fix:
src/app_common/static library: movesSentryWrapper(fromsrc/sentry_wrapper/),bury_point(fromsrc/bury_cfg/), andBaseException/StackWalker(fromsrc/dev-utils/) under one target;common_func.cppis compiled there too becauseSentryWrapper.objreferencescommon::symbols needed bylibslic3r_gui's closure.Snapmaker_OrcaDLL/exe and the Windows shim) still compile the same sources directly, so runtime behavior is unchanged; the new library initially serveslibslic3r_guiand its downstream only.BURY_API(import-from-dll / dllexport / plain) so references no longer default todllimportand require an import library. The shim keeps its existingBURY_EXPORTSlocal bury-point copy (see the MESA/opengl32 loader note insrc/CMakeLists.txt), so its runtime design is untouched.app_common/...include path;app_commonlinked intolibslic3r_gui.Why this is safe / Compatibility:
bury_point.cpplocally withBURY_EXPORTSand does not statically depend onSnapmaker_Orca.dll— the MESA software-OpenGL fallback design is preserved.BURY_API, references bind to same-image definitions, which is semantically equivalent to the previous dllimport usage within each image.BP_LOCAL_SERVER_ERR_CODEand a duplicateBP_LOCAL_SERVERdefine) have no remaining users; two stale comments about include resolution were corrected.Snapmaker_Orca_app_gui,Snapmaker_OrcaDLL, andlibslic3r_guilink and resolve cleanly with both the direct glue objects and theapp_commonarchive coexisting (no LNK2005 duplicate pulls).Behavior changes: None. Source moves + build graph only; no runtime code path changes (phase-1 shadow library).
Known limits: None.
Reviewer focus:
src/CMakeLists.txt: theapp_commontarget definition, the shim section (kept upstream's local-bury design), andtarget_link_libraries(libslic3r_gui app_common)(plain signature, matching this target's existing style).src/-rooted headers plusapp_common's PUBLIC include dir propagating throughlibslic3r_gui.Screenshots/Recordings/Graphs
N/A (no UI change)
Tests
app_common,libslic3r_gui(incremental rebuild of the 25 include-updated files),Snapmaker_Orca.dlllink (no duplicate symbols),snapmaker-orca.exeshim link (BURY_EXPORTSpath). CMake configure also verified clean on this PR branch againstbuild_platform_engineering.libslic3r_tests[SSWCPProtocol]— PASS (77 assertions in 10 test cases), headless (SLIC3R_GUI=OFF) configuration.SLIC3R_GUI=ON) — Expected: configures and links all targets; Actual: PASS on Windows.