Skip to content

Project Build Process

Archie Liu edited this page Jul 13, 2023 · 1 revision

RIME Engine

[WASM librime Source Code](https://github.com/FydeOS/librime-wasm)

Before delving into the building process, make sure you've installed the Emscripten toolchain. The official documentation provides a reliable guide on how to do so. Additionally, ensure that the system has the cmake, automake, and libtool tools. Debian and Ubuntu users can use the apt package manager to install these: apt install automake libtool cmake.

Building the Engine

The construction of the RIME engine consists of three primary stages: dependencies, RIME plugins, and the general build. These stages are executed by three scripts located in the wasm-builder directory. The entire process is automated and doesn't require manual intervention.

Follow these instructions to install the dependencies using wasm-builder/dep/build-all:

  1. Download and unpack the following libraries: boost, yaml-cpp, marisa, OpenCC, and glog. The five libraries will be automatically cross-compiled and installed in the Emscripten's virtual sysroot.
  2. The build-all script initially calls the fetch-source script to download and extract the source code. Subsequently, it calls the build script for each library to construct them individually.

For downloading the RIME plugin source code, utilize wasm-builder/download-plugins. The RIME Ice and Jidian Wubi input schemes utilize Lua script plugins and the Octogram syntax plugin. These plugins need to be downloaded into the plugins directory of the librime source. They will be auto-compiled into the RIME engine.

In the first two steps, all downloaded files are stored in the wasm-builder/dl-cache directory. This directory is cached by GitLab CI, which prevents redundant downloads during future builds.

For executing the entire build process, use wasm-builder/build-wasm. This script leverages CMake to construct the RIME engine. When compiling librime under Emscripten, it requires additional parameters for successful compilation and operation, which are passed to CMake within the script.

Upon completion of the build, the generated usable files will be located in the cmake-build-wasm/bin directory: rime_emscripten.js and rime_emscripten.wasm. All the compiled libraries during this process are static link libraries (despite their .so extension). Ultimately, all dependencies are statically linked into the wasm file, negating the need for additional dependencies.

At FydeOS, the RIME engine building process is automated by GitLab CI. If there's no need to modify the RIME engine itself, you can download the pre-built JavaScript (js) and WebAssembly (wasm) files from the FydeOS GitLab CI Jobs page when building plugins.

Extension

[Source Code](https://github.com/FydeOS/fydeRhythm)

The latest version of the plugin utilizes modern web front-end development tools along with the Plasmo framework, which is specifically designed for browser plugins. This framework uses parcel internally to bundle all source files. The project employs pnpm for dependency management, hence, pnpm must be installed prior to compilation. We recommend using Node.js version v18, as older versions may cause compilation errors.

Building the Extension

During the previous step of compiling librime, the emsdk_env script from the Emscripten SDK was executed. If you didn't switch shells at that point, Node.js would use the bundled version of emsdk, v14, instead of the system installed version. This older Node.js version may result in build process failure. Hence, it's recommended not to compile the plugin in the emsdk environment. You can verify the current Node.js version by running "node --version".

To proceed:

  1. Execute "pnpm install" to install all dependencies.
  2. Move the rime_emscripten.js file you compiled in the previous librime step into the plugin's background directory. Also, place the rime_emscripten.wasm file in the plugin's assets directory.
  3. Run "pnpm build" to build the plugin in the build/chrome-mv3-prod directory.
  4. Copy the inputview (virtual keyboard) directory from the source root to the build/chrome-mv3-prod directory.
  5. Use "google-chrome --pack-extension" to package the chrome-mv3-prod directory into a crx extension.