-
Notifications
You must be signed in to change notification settings - Fork 572
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(sample): migrate sample plugin to new plugin build system
- Loading branch information
Showing
8 changed files
with
146 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# A sample Rime plugin module | ||
|
||
This directory offers a Rime plugin named `rime-sample`. | ||
|
||
## Overview | ||
|
||
Here's how a Rime plugin works: | ||
|
||
A *plugin* can either be linked to librime or be a separate shared library, | ||
corresponding to the `BUILD_MERGED_PLUGINS` cmake option. | ||
|
||
When the shared library is loaded, it registers itself as *module* `sample`. | ||
If otherwise it's built-in, the module will be automatically loaded by default. | ||
|
||
When Rime `initialize`s via API, it loads its default modules or modules | ||
specified by the caller in `RimeTraits::modules`. | ||
|
||
Modules can also be loaded on demand using C++ API `rime::LoadModules()`. | ||
|
||
When the module is loaded, the `rime_sample_initialize()` function is run, | ||
which registers a *component* `trivial_translator`. | ||
|
||
That component is now available for prescription in Rime schema. | ||
It works with the Rime engine in the same way as the built-in translators. | ||
|
||
## Build the sample plugin library | ||
|
||
``` shell | ||
cd librime | ||
cmake . -Bbuild -DBUILD_SAMPLE=ON -DBUILD_SEPARATE_LIBS=ON | ||
cmake --build build --target rime-sample | ||
``` | ||
|
||
This outputs shared library: `build/sample/lib/rime-sample.so` | ||
|
||
The `BUILD_SEPARATE_LIBS=ON` option is not required but builds faster because | ||
`rime-sample` only depends on the core module of librime. | ||
|
||
## Run unit tests | ||
|
||
``` shell | ||
cmake --build build --target sample_test | ||
|
||
# run tests | ||
build/sample/test/sample_test | ||
``` | ||
|
||
## Play with sample_console | ||
|
||
`trivial_translator` converts pinyin to Chinese numbers. | ||
A sample Rime schema is set up in `build/bin/sample.schema.yaml` to utilize | ||
the translator. | ||
|
||
Build the console app and try it with a random number in pinyin: | ||
|
||
``` shell | ||
cmake --build build --target sample_console | ||
|
||
cd build/sample/bin | ||
echo "yibaiershisanwansiqianlingwushiliu" | ./sample_console | ||
``` | ||
|
||
## Build as standard Rime plugin | ||
|
||
Unlike the sample, which is built after specific rules in librime's cmake | ||
script, standard Rime plugins are separate projects that automatically | ||
integrate into librime's build system, without having to modify any source code | ||
and build script. | ||
|
||
To build the sample plugin as standard Rime plugin, link or copy the source code | ||
directory to `plugins/sample` and turn off cmake flag `BUILD_SAMPLE=OFF`. | ||
|
||
The cmake option `BUILD_MERGED_PLUGINS` merges all detected plugins into the | ||
built `rime` library. Set the option off to build each plugin as a standalone | ||
(shared) library. In the latter case, the user needs to explicitly load the | ||
`rime-sample` library and load the `sample` module when `initialize`-ing. |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
aux_source_directory(. SAMPLE_TEST_SRC) | ||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/test) | ||
add_executable(sample_test ${SAMPLE_TEST_SRC}) | ||
target_link_libraries(sample_test rime-sample ${Rime_LIBRARIES} ${GTEST_LIBRARIES}) | ||
add_dependencies(sample_test rime-sample) | ||
|
||
set(SAMPLE_TEST_EXECUTABLE ${EXECUTABLE_OUTPUT_PATH}/sample_test) | ||
add_test(sample_test ${SAMPLE_TEST_EXECUTABLE}) | ||
aux_source_directory(. sample_test_src) | ||
add_executable(sample_test ${sample_test_src}) | ||
target_link_libraries(sample_test | ||
${sample_library} | ||
${rime_library} | ||
${GTEST_LIBRARIES}) | ||
if(BUILD_SHARED_LIBS) | ||
target_compile_definitions(sample_test PRIVATE RIME_IMPORTS) | ||
endif(BUILD_SHARED_LIBS) | ||
|
||
set(sample_test_executable ${EXECUTABLE_OUTPUT_PATH}/sample_test) | ||
add_test(sample_test ${sample_test_executable}) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,15 @@ | ||
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) | ||
set(SAMPLE_CONSOLE_SRC "sample_console.cc") | ||
add_executable(sample_console ${SAMPLE_CONSOLE_SRC}) | ||
target_link_libraries(sample_console rime-sample ${Rime_LIBRARIES}) | ||
add_dependencies(sample_console rime-sample) | ||
|
||
set(sample_console_src "sample_console.cc") | ||
add_executable(sample_console ${sample_console_src}) | ||
target_link_libraries(sample_console | ||
${sample_library} | ||
${rime_library} | ||
${rime_dict_library} | ||
${rime_gears_library} | ||
${rime_levers_library}) | ||
|
||
file(COPY ${PROJECT_SOURCE_DIR}/tools/default.yaml | ||
DESTINATION ${EXECUTABLE_OUTPUT_PATH}) | ||
file(COPY ${PROJECT_SOURCE_DIR}/tools/symbols.yaml | ||
DESTINATION ${EXECUTABLE_OUTPUT_PATH}) | ||
file(COPY ${PROJECT_SOURCE_DIR}/tools/sample.schema.yaml | ||
DESTINATION ${EXECUTABLE_OUTPUT_PATH}) |
Empty file.