Compiling Mozc

From Fcitx
Revision as of 22:28, 28 March 2022 by Weng Xuetian (talk | contribs)
Jump to navigation Jump to search

Fcitx maintains a fork of mozc that contains the support for Mozc.

Building mozc can be very tricky because it uses uncommon build system on the Linux. The old one is gyp and the new one is bazel.

Build Mozc with bazel

If you clone the code from git repository, make sure you also fetch all the submodule. You can do this by git submodule update --init --recursive.

Sometimes you may need to restart bazel to reload certain data (e.g. you already run bazel before you get all submodule), you can do bazel clean; bazel shutdown.

While the command to build fcitx with bazel is simple, making bazel to locate the correct dependencies can be tricky, because the path of dependencies are all hard coded in the bazel's config file under src/. You are likely need to adjust QT_BASE_PATH if you are not building it under debian.

BUILD.fcitx5.bazel and WORKSPACE.bazel may also need to be updated to match your path. If you need custom prefix, the mozc server path also needs to be adjusted in config.bzl accordingly.

If you are using bazel 5.0.0, you will hit an issue that always require android NDK even if it is not used. It need to workaround by commenting out the android_ndk_repository line in WORKSPACE.bazel (Maybe android_sdk_repository if you have error relevant to it).

cd src # Need to run the bazel command under src/
# Build 3 target: mozc_server, qt based GUI tool and fcitx5's plugin.
bazel build -c opt --copt=-fPIC  --config oss_linux  unix/ server:mozc_server gui/tool:mozc_tool

The command above will generate following files required by mozc:


You'll need to put those files to the corresponding places:

bazel-bin/unix/fcitx5/ to FCITX_PREFIX/lib/fcitx5/

bazel-bin/server/mozc_server to /usr/lib/mozc

bazel-bin/gui/tool/mozc_tool to /usr/lib/mozc

../scripts/install_fcitx5_bazel and ../scripts/install_server_bazel can be used to help you as a reference on what needs to be done.

Build Mozc with gyp

This method may be deprecated any time depending on the upstream. In fcitx/mozc repository, there are some scripts that helps to build it with gyp. As for now, it does not support python 3.10. Another issue is that it will also use libc++ to build, which is not an option if fcitx5 links to stdc++.

cd src/
# Set this environment variable if you want Release build: _bldtype=Release
GYP_DEFINES="use_fcitx=0 use_libibus=0" ../scripts/configure # Pass --server_dir if you want a different mozc server directory.
sed "/stdlib=libc++/d;/-lc++/d" -i gyp/common.gypi

The default path used by the script is assuming /usr as prefix, please adjust by set PREFIX environment variable if you want a custom prefix, or just do the installation manually.