Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ jobs:
# Release legs build without running tests and are the slowest jobs in
# the workflow, so pull requests get the two debug legs, which build
# and test, and master pushes add the release legs.
preset: ${{ fromJSON(github.event_name == 'pull_request' && '["cl-debug", "clangcl-debug"]' || '["cl-debug", "cl-release", "clangcl-debug", "clangcl-release"]') }}
# The shared-library legs build and test morph::morph as a DLL.
preset: ${{ fromJSON(github.event_name == 'pull_request' && '["cl-debug", "clangcl-debug", "cl-shared-debug", "clangcl-shared-debug"]' || '["cl-debug", "cl-release", "clangcl-debug", "clangcl-release", "cl-shared-debug", "clangcl-shared-debug"]') }}
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -219,7 +220,7 @@ jobs:
run: cmake --build --preset ${{ matrix.preset }}

- name: Test
if: matrix.preset == 'cl-debug' || matrix.preset == 'clangcl-debug'
if: endsWith(matrix.preset, '-debug')
run: ctest --preset ${{ matrix.preset }}

# Picks a self-hosted lastrada-docker runner for the Linux legs when one is
Expand Down Expand Up @@ -314,7 +315,9 @@ jobs:
matrix:
# No gcc-debug leg: linux-qt configures gcc-debug with Qt on and runs
# the whole suite, which covers everything a plain gcc-debug leg would.
preset: [gcc-release, clang-debug, clang-release]
# clang-shared-debug builds morph::morph as a shared library with its
# symbols hidden by default, so an unexported symbol is a link error.
preset: [gcc-release, clang-debug, clang-release, clang-shared-debug]
steps:
- uses: actions/checkout@v4

Expand Down Expand Up @@ -2405,6 +2408,15 @@ jobs:
CXX: g++-15
run: bash scripts/check_install_export.sh

# The same check with morph::morph built as a shared library: the
# installed package must carry the shared target and a consumer must
# link and run against it.
- name: Install morph as a shared library and build a consumer against the prefix
env:
CC: gcc-15
CXX: g++-15
run: bash scripts/check_install_export.sh --shared

# ── The master compiler cache ─────────────────────────────────────────
# Merges the entries every Linux job used on this push into the one cache
# entry all jobs restore, then deletes every older sccache entry. Runs after
Expand Down
90 changes: 80 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,32 @@ if(CMAKE_GENERATOR MATCHES "Ninja" AND MORPH_LINK_JOBS GREATER 0)
endif()

option(MORPH_BUILD_TESTS "Build tests" ON)
option(MORPH_BUILD_SHARED "Build morph::morph as a shared library (MORPH_API marks what it exports; symbols are hidden by default)" OFF)
# A shared morph links a shared core-cpp (CORE_CPP_BUILD_SHARED): core-cpp keeps
# process and thread state of its own, such as the current executor, and a
# static copy in both libmorph and the executable would be two. Static
# libraries this tree links into the shared morph are position-independent.
if(MORPH_BUILD_SHARED)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Windows finds a DLL only beside the executable (or on PATH), and a test
# binary also runs at build time, to list its cases. One flat directory for
# every executable, morph.dll and core-cpp's DLLs is what makes both work.
if(WIN32 AND NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
endif()
# An installed libmorph needs core-cpp's libraries, and each of those needs
# the others; all are installed into one directory. A search path relative
# to the library itself finds them wherever the prefix lands, instead of
# relying on the program's own search path, which the loader does not apply
# to a library's dependencies.
if(NOT DEFINED CMAKE_INSTALL_RPATH)
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path")
elseif(UNIX)
set(CMAKE_INSTALL_RPATH "$ORIGIN")
endif()
endif()
endif()
option(MORPH_BUILD_EXAMPLES "Build examples" ON)
option(MORPH_BUILD_BANK_EXAMPLE "Build the SQLite/Lightweight bank example (heavy deps)" OFF)
option(MORPH_BUILD_HMAC_EXAMPLES "Build vetted-HMAC adapter examples (libsodium/OpenSSL, heavy deps)" OFF)
Expand Down Expand Up @@ -350,7 +376,7 @@ endif()
# is off while morph installs: CMake leaves an excluded subdirectory's install
# rules out of the parent's install, so `cmake --install` would install
# morph's package without the core-cpp package it depends on.
set(MORPH_CORE_CPP_VERSION 0.21)
set(MORPH_CORE_CPP_VERSION 0.22)
option(MORPH_INSTALL "Generate morph's install and export rules" ${PROJECT_IS_TOP_LEVEL})
if(NOT DEFINED AF_SANITIZER)
find_package(core-cpp ${MORPH_CORE_CPP_VERSION} CONFIG QUIET)
Expand All @@ -369,17 +395,36 @@ if(NOT core-cpp_FOUND)
CPMAddPackage(
NAME core-cpp
GITHUB_REPOSITORY contour-terminal/core-cpp
GIT_TAG v0.21.0
VERSION 0.21.0
GIT_TAG v0.22.0
VERSION 0.22.0
SYSTEM YES
EXCLUDE_FROM_ALL ${_morph_core_cpp_exclude_from_all}
OPTIONS "CORE_CPP_TESTING OFF" "CORE_CPP_BUILD_EXAMPLES OFF"
"CORE_CPP_WITH_TUI ${MORPH_BUILD_TUI}" "CORE_CPP_WITH_IMAGES OFF"
"CORE_CPP_WITH_TLS OFF" "CORE_CPP_WITH_SYSTEMD OFF" "CORE_CPP_FETCH_DEPS OFF"
"CORE_CPP_INSTALL ${MORPH_INSTALL}")
"CORE_CPP_INSTALL ${MORPH_INSTALL}" "CORE_CPP_BUILD_SHARED ${MORPH_BUILD_SHARED}")
unset(_morph_core_cpp_exclude_from_all)
endif()

# A shared morph needs a shared core-cpp, and one found installed may be static.
# Linked anyway, libmorph and the executable would each carry core-cpp's state,
# and an executor scope one of them enters would be invisible to the other.
if(MORPH_BUILD_SHARED)
get_target_property(_morph_core_cpp_type core::base TYPE)
if(NOT _morph_core_cpp_type STREQUAL "SHARED_LIBRARY")
if(core-cpp_FOUND)
set(_morph_core_cpp_from "the installed one at ${core-cpp_DIR}")
else()
set(_morph_core_cpp_from "the one fetched into this build")
endif()
message(FATAL_ERROR
"MORPH_BUILD_SHARED=ON needs a shared core-cpp, but ${_morph_core_cpp_from} is ${_morph_core_cpp_type}. "
"Install a core-cpp built with CORE_CPP_BUILD_SHARED=ON, or take it off CMAKE_PREFIX_PATH so morph "
"fetches one.")
endif()
unset(_morph_core_cpp_type)
endif()

# A core-cpp found installed brings whatever modules it was built with. One
# built with CORE_CPP_WITH_TUI=OFF has no core::tui, and morph::tui would fail
# much later, at link time, naming a target nobody created.
Expand Down Expand Up @@ -419,11 +464,17 @@ if(NOT WIN32 AND NOT EMSCRIPTEN)
endif()

# ── Library target ───────────────────────────────────────────────────────────
# A static library: the templates and the macro-sensitive core headers stay in
# headers, and what does not depend on a consumer's configuration is compiled
# once, in src/ui.
# Static by default, shared with MORPH_BUILD_SHARED: the templates and the
# macro-sensitive core headers stay in headers, and what does not depend on a
# consumer's configuration is compiled once, in src/ui.
include(GenerateExportHeader)
add_library(morph STATIC
if(MORPH_BUILD_SHARED)
set(_morph_library_type SHARED)
else()
set(_morph_library_type STATIC)
endif()
add_library(morph ${_morph_library_type}
src/ui/process_state.cpp
src/ui/document.cpp
src/ui/expression.cpp
src/ui/interpreter.cpp
Expand Down Expand Up @@ -467,13 +518,30 @@ endif()

# MORPH_API marks what a consumer calls into the compiled library. A static
# build defines MORPH_STATIC_DEFINE for the library and its consumers, which
# makes the macro empty.
# makes the macro empty. A shared build hides every symbol that MORPH_API does
# not mark, on every platform, so a missing mark is a link error on Linux too
# and not only on Windows.
generate_export_header(morph
BASE_NAME MORPH
EXPORT_MACRO_NAME MORPH_API
EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/generated/morph/export.hpp"
)
target_compile_definitions(morph PUBLIC MORPH_STATIC_DEFINE)
if(MORPH_BUILD_SHARED)
set_target_properties(morph PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)
if(MSVC)
# C4251 and C4275 fire on an exported class whose member or base is a
# standard-library type. Those types are header-defined and compiled
# identically on both sides under one toolchain version, which is the
# only combination a DLL and its consumer are supported in, so the
# warning reports nothing actionable.
target_compile_options(morph PUBLIC /wd4251 /wd4275)
endif()
else()
target_compile_definitions(morph PUBLIC MORPH_STATIC_DEFINE)
endif()
apply_warnings(morph)
# Every consumer of this archive carries an AF_SANITIZER block of its own, which is what makes instrumenting a static
# library safe: the link options are PRIVATE and do not propagate out of a static library.
Expand Down Expand Up @@ -1323,6 +1391,8 @@ if(MORPH_INSTALL)
FILE_SET morph_detail_headers DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILE_SET morph_generated_headers DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)

# Optional components ship only when this configuration actually created
Expand Down
27 changes: 27 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@
"binaryDir": "${sourceDir}/build/clangcl-release",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
},
{
"name": "cl-shared-debug",
"displayName": "Debug, morph as a shared library (MSVC)",
"inherits": "cl-debug",
"binaryDir": "${sourceDir}/build/cl-shared-debug",
"cacheVariables": { "MORPH_BUILD_SHARED": "ON" }
},
{
"name": "clangcl-shared-debug",
"displayName": "Debug, morph as a shared library (clang-cl)",
"inherits": "clangcl-debug",
"binaryDir": "${sourceDir}/build/clangcl-shared-debug",
"cacheVariables": { "MORPH_BUILD_SHARED": "ON" }
},
{
"name": "windows-everything",
"displayName": "Every optional feature (clang-cl release, Windows)",
Expand Down Expand Up @@ -143,6 +157,13 @@
"binaryDir": "${sourceDir}/build/clang-release",
"cacheVariables": { "CMAKE_BUILD_TYPE": "Release" }
},
{
"name": "clang-shared-debug",
"displayName": "Debug, morph as a shared library (Clang, Linux)",
"inherits": "clang-debug",
"binaryDir": "${sourceDir}/build/clang-shared-debug",
"cacheVariables": { "MORPH_BUILD_SHARED": "ON" }
},
{
"name": "linux-everything",
"displayName": "Every optional feature (Clang release, Linux)",
Expand Down Expand Up @@ -212,11 +233,14 @@
{ "name": "cl-qt-release", "configurePreset": "cl-qt-release", "jobs": 0 },
{ "name": "clangcl-debug", "configurePreset": "clangcl-debug", "jobs": 0 },
{ "name": "clangcl-release", "configurePreset": "clangcl-release", "jobs": 0 },
{ "name": "cl-shared-debug", "configurePreset": "cl-shared-debug", "jobs": 0 },
{ "name": "clangcl-shared-debug", "configurePreset": "clangcl-shared-debug", "jobs": 0 },
{ "name": "windows-everything", "configurePreset": "windows-everything", "jobs": 0 },
{ "name": "gcc-debug", "configurePreset": "gcc-debug", "jobs": 0 },
{ "name": "gcc-release", "configurePreset": "gcc-release", "jobs": 0 },
{ "name": "clang-debug", "configurePreset": "clang-debug", "jobs": 0 },
{ "name": "clang-release", "configurePreset": "clang-release", "jobs": 0 },
{ "name": "clang-shared-debug", "configurePreset": "clang-shared-debug", "jobs": 0 },
{ "name": "linux-everything", "configurePreset": "linux-everything", "jobs": 0 },
{ "name": "clang-asan", "configurePreset": "clang-asan", "jobs": 0 },
{ "name": "clang-tsan", "configurePreset": "clang-tsan", "jobs": 0 },
Expand All @@ -235,11 +259,14 @@
{ "name": "cl-qt-debug", "configurePreset": "cl-qt-debug", "inherits": "base-test" },
{ "name": "cl-qt-release", "configurePreset": "cl-qt-release", "inherits": "base-test" },
{ "name": "clangcl-debug", "configurePreset": "clangcl-debug", "inherits": "base-test" },
{ "name": "cl-shared-debug", "configurePreset": "cl-shared-debug", "inherits": "base-test" },
{ "name": "clangcl-shared-debug", "configurePreset": "clangcl-shared-debug", "inherits": "base-test" },
{ "name": "windows-everything","configurePreset": "windows-everything","inherits": "base-test" },
{ "name": "gcc-debug", "configurePreset": "gcc-debug", "inherits": "base-test" },
{ "name": "gcc-release", "configurePreset": "gcc-release", "inherits": "base-test" },
{ "name": "clang-debug", "configurePreset": "clang-debug", "inherits": "base-test" },
{ "name": "clang-release", "configurePreset": "clang-release", "inherits": "base-test" },
{ "name": "clang-shared-debug", "configurePreset": "clang-shared-debug", "inherits": "base-test" },
{ "name": "linux-everything", "configurePreset": "linux-everything", "inherits": "base-test" },
{
"name": "clang-asan",
Expand Down
2 changes: 1 addition & 1 deletion docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

`morph` is a typed, asynchronous bridge between a GUI thread and business-object models. Models may live in-process (local mode) or in a remote server process (remote mode). The GUI code is identical in both cases — only the backend implementation changes.

The core library, `morph::morph`, is a compiled static library (C++23, namespace `morph`); its templates and the macro-sensitive core headers stay in headers. It depends on Glaze for JSON reflection and on [core-cpp](https://github.com/contour-terminal/core-cpp) for its event-loop timers, base64 and wakeup primitive; core-cpp's `core::base`, `core::net` and `core::platform` are static libraries, so a project that links `morph::morph` also builds those. The optional parts are separate targets, and some are compiled: the Qt integration (`morph::qt`), the terminal frontend (`morph::tui`), the Qt Quick frontend (`morph::qt_quick`) and the generic client (`morph::client`) are static libraries with sources under `src/`.
The core library, `morph::morph`, is a compiled library (C++23, namespace `morph`), static by default and shared with `MORPH_BUILD_SHARED=ON`; its templates and the macro-sensitive core headers stay in headers. It depends on Glaze for JSON reflection and on [core-cpp](https://github.com/contour-terminal/core-cpp) for its event-loop timers, base64 and wakeup primitive; core-cpp's `core::base`, `core::net` and `core::platform` are static libraries, so a project that links `morph::morph` also builds those. The optional parts are separate targets, and some are compiled: the Qt integration (`morph::qt`), the terminal frontend (`morph::tui`), the Qt Quick frontend (`morph::qt_quick`) and the generic client (`morph::client`) are static libraries with sources under `src/`.

> **New to morph?** `docs/GETTING-STARTED.md` is the step-by-step tutorial that
> comes before this document: it builds one small app end to end
Expand Down
18 changes: 16 additions & 2 deletions docs/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
- **[Glaze](https://github.com/stephenberry/glaze) 7.4** for JSON reflection,
found with `find_package` (for example from the `vcpkg.json` manifest) or
fetched through CPM.
- **[core-cpp](https://github.com/contour-terminal/core-cpp) 0.21**, fetched
- **[core-cpp](https://github.com/contour-terminal/core-cpp) 0.22**, fetched
through CPM. morph's timers run on its event loop, coroutines build on its
`Task<T>`, and `morph::net` takes its base64 and wakeup primitive from it.
`morph::morph` is a static library (templates and the macro-sensitive core
`morph::morph` is a static library by default, or a shared one with
`MORPH_BUILD_SHARED=ON` (templates and the macro-sensitive core
headers stay in headers), and `core::base`, `core::net` and
`core::platform` are static libraries too, so a project that links
`morph::morph` builds them too.
Expand Down Expand Up @@ -43,6 +44,7 @@ need `VCPKG_ROOT` set.
| Option | Default | What it builds |
|---|---|---|
| `MORPH_BUILD_TESTS` | `ON` | The unit tests |
| `MORPH_BUILD_SHARED` | `OFF` | Build `morph::morph` as a shared library. Every symbol is hidden unless `MORPH_API` marks it, on every platform; see below |
| `MORPH_BUILD_EXAMPLES` | `ON` | The dependency-free examples (forms, concepts, gallery, LIMS gallery); the generic client when a frontend is on |
| `MORPH_BUILD_CLIENT` | `ON` | `morph::client`, the generic client's source and shell |
| `MORPH_BUILD_QT` | `OFF` | The Qt 6 WebSocket transport and executor |
Expand Down Expand Up @@ -123,6 +125,18 @@ next to morph's.
target. `MORPH_INSTALL` defaults to `PROJECT_IS_TOP_LEVEL`, so a vendored morph
adds nothing to your project's install.

### Building morph as a shared library

`-DMORPH_BUILD_SHARED=ON` builds `morph::morph` as a shared library (`libmorph.so`, `morph.dll`). The library is
compiled with hidden symbol visibility, so what a consumer can call is exactly what `MORPH_API`
(`<morph/export.hpp>`) marks, on Linux and Windows alike. The process-wide state that header code reaches through a
function (the registries, the logger, the thread-local dispatch slots) is defined in the library, so the library and
the executable share one copy. core-cpp is built shared too (`CORE_CPP_BUILD_SHARED`), for the same reason: it keeps
process and thread state of its own, such as the current executor. A configure that finds an installed static core-cpp
stops and says so. On Windows every executable, `morph.dll` and core-cpp's DLLs go to `<build>/bin`, because Windows loads a DLL only from beside the
executable. `find_package(morph CONFIG)` works in both modes; an installed shared `morph` is found with its
`libmorph.so` or `morph.dll`.

### A bare include path (not supported)

`-I<repo>/include` is not enough: morph::morph is a compiled static library, and
Expand Down
8 changes: 2 additions & 6 deletions include/morph/core/bridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <exception>
#include <functional>
#include <memory>
#include <morph/export.hpp>
#include <mutex>
#include <optional>
#include <stdexcept>
Expand Down Expand Up @@ -139,7 +140,7 @@ class ActionExecuteRegistry {

/// @brief Returns the process-level singleton registry.
/// @return Reference to the singleton `ActionExecuteRegistry`.
static ActionExecuteRegistry& instance();
MORPH_API static ActionExecuteRegistry& instance();

private:
// The stored key: the registry owns its ids, because nothing else outlives
Expand Down Expand Up @@ -206,11 +207,6 @@ class ActionExecuteRegistry {
std::unordered_map<Key, std::type_index, KeyHash, KeyEqual> _types;
};

inline ActionExecuteRegistry& ActionExecuteRegistry::instance() {
static ActionExecuteRegistry inst;
return inst;
}

} // namespace morph::bridge

namespace morph::model::detail {
Expand Down
6 changes: 2 additions & 4 deletions include/morph/core/detail/owner_probe.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cassert>
#include <core/async/IExecutor.hpp>
#include <cstdio>
#include <morph/export.hpp>

/// @file
/// @brief The check every loop-owned body makes on entry: "am I on my owner?"
Expand All @@ -28,10 +29,7 @@ using OwnerProbe = void (*)(char const* site, ::core::async::IExecutor const& ow

/// @brief The installed probe, or null.
/// @return The process-wide probe slot.
[[nodiscard]] inline std::atomic<OwnerProbe>& ownerProbe() noexcept {
static std::atomic<OwnerProbe> probe{nullptr};
return probe;
}
[[nodiscard]] MORPH_API std::atomic<OwnerProbe>& ownerProbe() noexcept;

/// @brief Records that @p site is running a body that must run on @p owner.
///
Expand Down
Loading
Loading