Skip to content

refactor: introduce app_common static library for app-layer glue - #1006

Open
hsheng27120 wants to merge 1 commit into
Snapmaker:build_platform_engineeringfrom
hsheng27120:app-common-static-lib
Open

hsheng27120 wants to merge 1 commit into
Snapmaker:build_platform_engineeringfrom
hsheng27120:app-common-static-lib

Conversation

@hsheng27120

Copy link
Copy Markdown

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 the Snapmaker_Orca import library to link against the GUI library.

Root cause: N/A (build/layout refactor, not a bug fix).

Fix:

  • New src/app_common/ static library: moves SentryWrapper (from src/sentry_wrapper/), bury_point (from src/bury_cfg/), and BaseException/StackWalker (from src/dev-utils/) under one target; common_func.cpp is compiled there too because SentryWrapper.obj references common:: symbols needed by libslic3r_gui's closure.
  • Phase-1 shadow library: the production targets (Snapmaker_Orca DLL/exe and the Windows shim) still compile the same sources directly, so runtime behavior is unchanged; the new library initially serves libslic3r_gui and its downstream only.
  • Three-state BURY_API (import-from-dll / dllexport / plain) so references no longer default to dllimport and require an import library. The shim keeps its existing BURY_EXPORTS local bury-point copy (see the MESA/opengl32 loader note in src/CMakeLists.txt), so its runtime design is untouched.
  • ~25 GUI/desktop files updated to the new app_common/... include path; app_common linked into libslic3r_gui.

Why this is safe / Compatibility:

  • The shim still compiles bury_point.cpp locally with BURY_EXPORTS and does not statically depend on Snapmaker_Orca.dll — the MESA software-OpenGL fallback design is preserved.
  • With the default (plain) BURY_API, references bind to same-image definitions, which is semantically equivalent to the previous dllimport usage within each image.
  • Removed macros (BP_LOCAL_SERVER_ERR_CODE and a duplicate BP_LOCAL_SERVER define) have no remaining users; two stale comments about include resolution were corrected.
  • Snapmaker_Orca_app_gui, Snapmaker_Orca DLL, and libslic3r_gui link and resolve cleanly with both the direct glue objects and the app_common archive 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: the app_common target definition, the shim section (kept upstream's local-bury design), and target_link_libraries(libslic3r_gui app_common) (plain signature, matching this target's existing style).
  • Include-path resolution: quoted includes relative to src/-rooted headers plus app_common's PUBLIC include dir propagating through libslic3r_gui.

Screenshots/Recordings/Graphs

N/A (no UI change)

Tests

  • Build: Windows x64, VS 2022 (MSVC 19.44), Release — PASS. Verified targets: configure (GUI=ON, SENTRY=ON), app_common, libslic3r_gui (incremental rebuild of the 25 include-updated files), Snapmaker_Orca.dll link (no duplicate symbols), snapmaker-orca.exe shim link (BURY_EXPORTS path). CMake configure also verified clean on this PR branch against build_platform_engineering.
  • Automated tests: libslic3r_tests [SSWCPProtocol] — PASS (77 assertions in 10 test cases), headless (SLIC3R_GUI=OFF) configuration.
  • CI: NOT AVAILABLE (expected to run on this PR).
  • Manual verification:
    1. Configure + build with default options (SLIC3R_GUI=ON) — Expected: configures and links all targets; Actual: PASS on Windows.
  • Not verified: Linux/macOS build configurations (no environment available; CI will cover); GUI runtime launch and Sentry/bury runtime behavior (no runtime code changes intended; phase-1 keeps production compile units identical).

@zhangzhend0ng zhangzhend0ng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):

  1. [Must fix] BURY_API's BURY_IMPORT_FROM_DLL state is defined nowhere in the tree, and its comment misattributes usage to the Windows shim (which actually compiles bury_point.cpp locally with BURY_EXPORTS). Remove the dead state or fix the comment. → inline on src/app_common/bury_point.hpp
  2. [Project standard] New comments in src/app_common/bury_point.hpp, 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 English. Please translate.

Verified clean

  • Macro removals safe: BP_LOCAL_SERVER was 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 in HttpServer.cpp; BP_LOCAL_SERVER_ERR_CODE has zero remaining users.
  • No stale references: no remaining sentry_wrapper/, bury_cfg/, dev-utils/BaseException|StackWalker includes anywhere (src/tests/sandboxes); include casing is exact — the stackwalker.h → StackWalker.h change fixes a latent case-sensitivity trap.
  • Target scoping: app_common and libslic3r_gui are both behind SLIC3R_GUI; encoding_check is defined before first use; tests/slic3rutils links libslic3r_gui under a TARGET libslic3r_gui guard, so usage requirements propagate to exactly the consumers this PR unblocks.
  • Plain-signature link is correct: libslic3r_gui's existing target_link_libraries calls are all plain; CMake forbids mixing signatures on one target, so the keyword-less target_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-lib lacks the refactor_ prefix per workflow conventions.

Comment thread src/app_common/bury_point.hpp Outdated
Comment on lines 7 to 19
// 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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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_DLL and 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.

Comment thread src/CMakeLists.txt
# 阶段 1(影子库):生产目标 Snapmaker_Orca(DLL/exe)与 Windows shim 仍直接编译同源文件,
# 运行时行为零变化;本库先只服务 libslic3r_gui 及其下游。
# -----------------------------------------------------------------------
add_library(app_common STATIC

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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>
@hsheng27120
hsheng27120 force-pushed the app-common-static-lib branch from 943fc38 to 6f53f41 Compare October 13, 2026 10:49
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.

2 participants