Skip to content

Build morph::morph as a shared library (MORPH_BUILD_SHARED) - #1125

Merged
Yaraslaut merged 6 commits into
masterfrom
feat/shared-library
Nov 17, 2026
Merged

Yaraslaut merged 6 commits into
masterfrom
feat/shared-library

Conversation

@Yaraslaut

@Yaraslaut Yaraslaut commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

What

-DMORPH_BUILD_SHARED=ON builds morph::morph as a shared library (default OFF; the static build is unchanged).

  • The shared target uses CXX_VISIBILITY_PRESET hidden and VISIBILITY_INLINES_HIDDEN ON, so a missing MORPH_API is a link error on Linux too.
  • MORPH_API added to AppRoot, the only class with out-of-line members that was unmarked. Every other symbol the link needed was already marked.
  • A shared morph links a shared core-cpp (CORE_CPP_BUILD_SHARED, new in core-cpp v0.22.0, which this PR pins); a configure that finds a static core-cpp for a shared morph stops and names it. On Windows every executable, morph.dll and core-cpp's DLLs go to <build>/bin (a DLL loads only from beside the exe, and test binaries also run at build time to list cases). /wd4251 /wd4275 on MSVC. Installed shared libraries carry $ORIGIN (@loader_path on Apple), so libmorph finds core-cpp's libraries beside it.
  • install(TARGETS morph) gains LIBRARY and RUNTIME destinations.
  • CI: clang-shared-debug in the Linux matrix; cl-shared-debug and clangcl-shared-debug in the Windows matrix (build + test); scripts/check_install_export.sh --shared in the install-export job. The script asserts the installed target really is SHARED IMPORTED (and STATIC otherwise), so a mode that silently fell back would fail.

Singletons (the likeliest real defect)

Found with clang's -Wunique-object-duplication (fires in the hidden-visibility library TUs), then a probe TU including every public header (excluding qt/tui/qt_quick/testing) to catch ones no src/ TU includes. Each one below is moved into src/ui/process_state.cpp and exported (declaration + docs stay in the header with MORPH_API); none was left per-module:

ActionExecuteRegistry::instance, ActionGate::overlapCounter, mutableActionResultSlots, mutableActionResultConflicts, defaultRegistry, defaultDispatcher, registrationPhaseFlag, inlineExecutor, ownerProbe, defaultActionLogState, logState, observeState, allowAllAuthorizer, SigningAuthorizer::active, tlsCurrent, tlsOrigin, mutableEffectsRegistry, mutableChangeTimesRegistry, mutableAddedEffectsRegistry, effects::detail::resolved (whole function), mutableRecordRegistry, nowOverrideState, wireClampCounter, screenRegistry, ViewRegistry::instance, defaultPayloadMigrations, tlsIsReplaying.

Left per-module, on purpose: net/detail/ws_frame.hpp entropy and ws_handshake.hpp gen (thread-local random sources; no cross-module meaning), testing/owner_probe_recorder.hpp (test-only, touched only from the executable), per-type template statics (keyed by type, reached from the module that instantiates them), and const statics.

Because these are now out of line, the compile-check probes that do not link morph::morph link a static copy of process_state.cpp (morph_guard_probe_state), and the forms DAG budget compile gets the generated include dir.

core-cpp's own state: fixed upstream

core-cpp keeps process and thread state of its own, above all the current executor (innermostExecutorScope(), an inline thread-local in its headers). With core-cpp static, libmorph and the executable each had a copy: the first shared run had 155 of 4897 tests fail on Linux (noteOwner: "a loop-owned body ran off its owner's thread"), and the Windows shared legs failed 37 tests each the same way.

Fixed in core-cpp rather than worked around here: contour-terminal/core-cpp#102 adds CORE_CPP_BUILD_SHARED (export macros, that state moved out of line), released as core-cpp v0.22.0; morph moved to v0.21.0 first in #1127. The Linux-only force-included visibility header this PR first carried is gone.

Verification

  • CI: green on every leg, including clang-shared-debug, cl-shared-debug, clangcl-shared-debug, the sanitizer legs and check_install_export.sh --shared.
  • Local, Linux, clang-23 Debug, against core-cpp v0.22.0 shared, no visibility header: 4219/4219 passed, no owner assertion.
  • Control (missing mark): removed MORPH_API from canonicalJson; the hidden-visibility shared build failed with undefined reference to morph::ui::detail::canonicalJson[abi:cxx11](morph::ui::Value const&). Restored.
  • Control (static core-cpp): forcing CORE_CPP_BUILD_SHARED OFF stops configure with the new message.
  • Control (install search path): dlopen() of the installed libmorph.so by absolute path fails without $ORIGIN (libcore-cpp-net.so.0.22: cannot open shared object file) and succeeds with it.
  • Control (sanitizer probe): without the fix, morph_duplicate_model_id fails to link under ASan with 8 undefined sanitizer references; with it, it links and passes.
  • Windows DLL special members: a Linux probe forcing every exported class's implicit copy/move/default/destructor reproduced the ResultsColumn clang-cl error and passes for all other exported classes.

morph_tui, morph_qt_quick, morph_client and morph_qt_impl stay static; shared morph linked and passed with them unchanged.

Review notes (done inline)

  • resolved() now rethrows a copy of the stored error (throw EffectsRegistrationError{*state.error}) with NOLINT on the throw rules instead of throw *state.error; same type, same message.
  • /wd4251 /wd4275 are PUBLIC on morph for MSVC so consumers of the exported classes do not trip /WX.

Closes #1118

🤖 Generated with Claude Code

https://claude.ai/code/session_01No1Nzo5wbYPDDynGBphgqj

@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Yaraslaut and others added 5 commits November 16, 2026 21:25
The option (default OFF) builds the library SHARED with hidden symbol
visibility, so an unmarked symbol is an undefined-reference link error on
Linux as well as Windows. MORPH_API now also marks AppRoot, the one class with
out-of-line members that was unmarked.

Process-wide state that header code reached through an inline function
(registries, logger, observability, session and replay thread-locals, the
effects resolution, the screen and view registries, and others) is defined in
src/ui/process_state.cpp and exported, so the library and an executable share
one copy. The compile-check probes that do not link morph::morph link a static
copy of that file.

core-cpp keeps its executor-scope slot as an inline thread-local in a header;
a hidden copy in the library is invisible to the executable's event loop. On
non-Windows platforms the library declares it with default visibility so the
dynamic linker merges the two. Windows has no such merge.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01No1Nzo5wbYPDDynGBphgqj
Adds the clang-shared-debug, cl-shared-debug and clangcl-shared-debug presets
and a leg for each in the existing Linux and Windows matrices, a --shared mode
for the install/export consumer check with a guard that the installed target
really is shared, and the LIBRARY/RUNTIME install destinations.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01No1Nzo5wbYPDDynGBphgqj
The exported singleton accessors were declared twice -- a forward
declaration and a second one after the class -- which GCC rejects under
-Werror=redundant-decls and MSVC rejects as a linkage mismatch when only
one of the two carries MORPH_API. Each is now declared once, exported.

Screen's defaulted constructor is now defined in interpreter.cpp: an
exported class emits its inline members in every module, and that
constructor destroys a unique_ptr<Mounted> on a throw, which clang-cl
cannot instantiate where Mounted is incomplete.

Moves the coverage allowlist line hints to where the edits left them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01No1Nzo5wbYPDDynGBphgqj
An exported class emits every implicit member in the DLL, including a
copy constructor and copy assignment for ResultsColumn, whose rows hold
unique_ptrs and cannot be copied. The struct is private to ShellFrame and
used only inside the library, so it needs no export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01No1Nzo5wbYPDDynGBphgqj
core-cpp 0.22 builds shared with CORE_CPP_BUILD_SHARED, and a shared morph
now asks for it. core-cpp keeps process and thread state of its own -- the
current executor above all -- and a static copy linked into both libmorph and
the executable is two copies, so a scope one image enters is invisible to the
other. That is what failed 37 tests on the Windows shared legs; on Linux a
force-included header merged the one slot that showed up, which a shared
core-cpp makes unnecessary, so it is gone.

A configure that finds a static core-cpp for a shared morph stops and says
which one it found, rather than building two copies of its state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01No1Nzo5wbYPDDynGBphgqj
…heir own

An installed libmorph needs core-cpp's libraries, and they need each other;
all land in one directory. The loader does not apply a program's search path
to a library's dependencies, so a consumer whose binary did not itself record
every core-cpp library failed to start with libcore-cpp-base.so.0.22 not
found. A shared build now installs with $ORIGIN (@loader_path on Apple).
When the consumer binary of the install check does not run, the check prints
each object's NEEDED and RUNPATH entries, which is where a loader failure's
cause is.

On a sanitizer leg morph_duplicate_model_id links core-cpp's instrumented
code through the probes' copy of process_state.cpp, so it is instrumented
like the other probes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01No1Nzo5wbYPDDynGBphgqj
@Yaraslaut
Yaraslaut merged commit d7fc33c into master Nov 17, 2026
34 checks passed
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.

ui: interpreter.hpp costs 1.8 GB per translation unit, header-only, so hosted CI runs out of memory

1 participant