Repository navigation
Build morph::morph as a shared library (MORPH_BUILD_SHARED) - #1125
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Yaraslaut
force-pushed
the
feat/shared-library
branch
from
November 16, 2026 21:28
dd26871 to
a2adfd7
Compare
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
-DMORPH_BUILD_SHARED=ONbuildsmorph::morphas a shared library (default OFF; the static build is unchanged).CXX_VISIBILITY_PRESET hiddenandVISIBILITY_INLINES_HIDDEN ON, so a missingMORPH_APIis a link error on Linux too.MORPH_APIadded toAppRoot, the only class with out-of-line members that was unmarked. Every other symbol the link needed was already marked.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.dlland 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 /wd4275on MSVC. Installed shared libraries carry$ORIGIN(@loader_pathon Apple), so libmorph finds core-cpp's libraries beside it.install(TARGETS morph)gainsLIBRARYandRUNTIMEdestinations.clang-shared-debugin the Linux matrix;cl-shared-debugandclangcl-shared-debugin the Windows matrix (build + test);scripts/check_install_export.sh --sharedin the install-export job. The script asserts the installed target really isSHARED IMPORTED(andSTATICotherwise), 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 nosrc/TU includes. Each one below is moved intosrc/ui/process_state.cppand exported (declaration + docs stay in the header withMORPH_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.hppentropyandws_handshake.hppgen(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), andconststatics.Because these are now out of line, the compile-check probes that do not link
morph::morphlink a static copy ofprocess_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
clang-shared-debug,cl-shared-debug,clangcl-shared-debug, the sanitizer legs andcheck_install_export.sh --shared.MORPH_APIfromcanonicalJson; the hidden-visibility shared build failed withundefined reference to morph::ui::detail::canonicalJson[abi:cxx11](morph::ui::Value const&). Restored.CORE_CPP_BUILD_SHARED OFFstops configure with the new message.dlopen()of the installedlibmorph.soby absolute path fails without$ORIGIN(libcore-cpp-net.so.0.22: cannot open shared object file) and succeeds with it.morph_duplicate_model_idfails to link under ASan with 8 undefined sanitizer references; with it, it links and passes.ResultsColumnclang-cl error and passes for all other exported classes.morph_tui,morph_qt_quick,morph_clientandmorph_qt_implstay static; sharedmorphlinked 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 ofthrow *state.error; same type, same message./wd4251 /wd4275are PUBLIC onmorphfor MSVC so consumers of the exported classes do not trip/WX.Closes #1118
🤖 Generated with Claude Code
https://claude.ai/code/session_01No1Nzo5wbYPDDynGBphgqj