Skip to content

build(static): generate plugin module references for static linking#1173

Merged
lotem merged 1 commit into
rime:masterfrom
black-desk:generate-plugin-references
Jun 8, 2026
Merged

build(static): generate plugin module references for static linking#1173
lotem merged 1 commit into
rime:masterfrom
black-desk:generate-plugin-references

Conversation

@black-desk

Copy link
Copy Markdown
Contributor

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

  • Done

Manual test

  • Done

Code Review

  1. Unit and manual test pass
  2. GitHub Action CI pass
  3. At least one contributor reviews and votes
  4. Can be merged clean without conflicts
  5. PR will be merged by rebase upstream base

Additional Info

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.
@lotem

lotem commented Jun 8, 2026

Copy link
Copy Markdown
Member

強大。學習!

@lotem lotem merged commit cbf363b into rime:master Jun 8, 2026
10 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.

2 participants