build(static): generate plugin module references for static linking#1173
Merged
Conversation
librime already uses rime_declare_module_dependencies() in rime_api.cc to keep core modules (core, dict, gears, levers) alive when building as a static library. Each core module has a rime_require_module_*() function that is called from rime_declare_module_dependencies(), which resides in the same object file as RimeSetup() and other always-used API functions. This ensures the linker pulls in those modules rather than discarding them as unused. However, this mechanism was not applied to external plugins merged into the static library via BUILD_MERGED_PLUGINS=ON (the default). Plugin modules also register via rime_require_module_*() functions, but nothing references them, so the linker may discard their .o files along with any __attribute__((constructor)) registration code. Extend the existing mechanism by reusing the RIME_EXTRA_MODULES define (already set by CMake for plugin module registration in setup.cc) to also generate rime_require_module_*() calls for each plugin. The format of RIME_EXTRA_MODULES is changed from the old ,Q(name) string concatenation to a Boost.PP sequence (name1)(name2)..., which is then expanded by BOOST_PP_SEQ_FOR_EACH in both setup.cc (stringified for module registration) and rime_api.cc (token-pasted for extern declarations and function calls). This eliminates the old Q(x) #x macro in favor of Boost.PP, and consolidates the CMake compile definition into a single target_compile_definitions() call. When no plugins are present, RIME_EXTRA_MODULES is defined as empty. Both setup.cc and rime_api.cc guard the Boost.PP usage with #ifdef checks, so the empty define has no effect.
Member
|
強大。學習! |
lotem
approved these changes
Jun 8, 2026
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.
Pull request
Feature
librime already uses rime_declare_module_dependencies() in rime_api.cc
to keep core modules (core, dict, gears, levers) alive when building
as a static library. Each core module has a rime_require_module_*()
function that is called from rime_declare_module_dependencies(), which
resides in the same object file as RimeSetup() and other always-used
API functions. This ensures the linker pulls in those modules rather
than discarding them as unused.
However, this mechanism was not applied to external plugins merged
into the static library via BUILD_MERGED_PLUGINS=ON (the default).
Plugin modules also register via rime_require_module_*() functions,
but nothing references them, so the linker may discard their .o files
along with any attribute((constructor)) registration code.
Extend the existing mechanism by reusing the RIME_EXTRA_MODULES define
(already set by CMake for plugin module registration in setup.cc) to
also generate rime_require_module_*() calls for each plugin. The
format of RIME_EXTRA_MODULES is changed from the old ,Q(name) string
concatenation to a Boost.PP sequence (name1)(name2)..., which is then
expanded by BOOST_PP_SEQ_FOR_EACH in both setup.cc (stringified for
module registration) and rime_api.cc (token-pasted for extern
declarations and function calls).
This eliminates the old Q(x) #x macro in favor of Boost.PP, and
consolidates the CMake compile definition into a single
target_compile_definitions() call.
When no plugins are present, RIME_EXTRA_MODULES is defined as empty.
Both setup.cc and rime_api.cc guard the Boost.PP usage with #ifdef
checks, so the empty define has no effect.
Unit test
Manual test
Code Review
Additional Info