From 69c0f7a4f3d2608abe4b449d054fd98aecf30be6 Mon Sep 17 00:00:00 2001 From: Jan Kleinert Date: Fri, 2 Oct 2026 11:55:18 +0200 Subject: [PATCH] closes #306 with a no-fix: grunk needs to be linked dynamically. Adds documentation and a cmake safeguard --- CMakeLists.txt | 15 +++++++++++++++ README.md | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b755494..3b448fd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,21 @@ cmake_minimum_required(VERSION 3.15) project(grunk VERSION 0.5.0) set(CMAKE_CXX_STANDARD 17) +# grunk must be consumed as a pre-built dependency via find_package(grunk) - never vendored into +# another project's build via add_subdirectory()/FetchContent_MakeAvailable(). See README.md's +# "Consuming grunk" section for why (a real, previously-confirmed ODR/dispatch bug from having two +# independently-compiled copies of grunk in one process). Fail fast here with an explanation instead +# of the confusing "grunk/version.hpp: No such file or directory" this used to produce deep inside +# recipe.hpp, caused by version.hpp only ever being generated into this project's own binary dir. +if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + message(FATAL_ERROR + "grunk cannot be configured as a CMake subproject (add_subdirectory()/FetchContent). Build " + "and install grunk on its own, then consume it from your project via find_package(grunk). " + "See this repository's README.md, \"Consuming grunk\", for why vendoring/static linking are " + "unsupported by design." + ) +endif() + include(GNUInstallDirs) # grunk_recipe/grunk_plugin (and the umbrella `grunk` target) are built as SHARED diff --git a/README.md b/README.md index 05efb97c..4953ffe5 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,19 @@ int main() { A plugin can just as well be a compiled Lua module (e.g. SWIG-generated) via `grunk::state::load_compiled_plugin`, or plain Lua source via `grunk::state::load_lua_plugin_script`/`load_lua_plugin_file` (or `grunk::plugin::load_script`) - see `grunk/plugin/loader.hpp` for the full native ABI and `grunk/dynamic/state.hpp` for all three `load_*_plugin`/`begin_plugin` methods. +## Consuming grunk + +Build and install grunk, then consume it from a downstream project via `find_package(grunk)` - +**do not** vendor grunk's source into another project via `FetchContent`/`add_subdirectory`, and do not +link it statically. `grunk`/`grunk::recipe`/`grunk::plugin` are deliberately built as `SHARED` libraries +with no option to change that, so that every consumer loaded into one process - native plugins +(`grunk-occt`, `grunk-adolc`, ...), the Python bindings, a GUI - dynamically links the *same* physical +`.so`/`.dylib`/`.dll`. Two independently-compiled copies of grunk loaded into one process is a real, +previously-confirmed hazard: `std::type_index`-keyed dispatch (`grunk::dynamic`'s type/function registry) +silently fails to match across copies, since each gets its own `type_info` identity, producing +wrong-dispatch bugs that are hard to diagnose. Attempting to configure grunk as a CMake subproject fails +fast with an error pointing back here, rather than the confusing missing-header error it used to produce. + ## Documentation [Read the documentation](https://grunk-dev.github.io/grunk/) to learn more.