Difference between revisions of "Compiling Mozc"

From Fcitx
Jump to navigation Jump to search
(Created page with "Fcitx maintains a fork of mozc that contains the support for [https://github.com/google/mozc/ Mozc]. Building mozc can be very tricky because it uses uncommon build system on...")
 
 
(One intermediate revision by the same user not shown)
Line 4: Line 4:
  
 
= Build Mozc with 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 <code>git submodule update --init --recursive</code>.
 +
 +
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 <code>bazel clean; bazel shutdown</code>.
 +
 
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.
 
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.
 
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 [https://github.com/bazelbuild/bazel/issues/14260 an issue] that always require android NDK even if it is not used. It need to workaround by commenting out the <code>android_ndk_repository</code> line in WORKSPACE.bazel.
+
If you are using bazel 5.0.0, you will hit [https://github.com/bazelbuild/bazel/issues/14260 an issue] that always require android NDK even if it is not used. It need to workaround by commenting out the <code>android_ndk_repository</code> line in WORKSPACE.bazel (Maybe android_sdk_repository if you have error relevant to it).
  
 
  <pre>cd src # Need to run the bazel command under src/
 
  <pre>cd src # Need to run the bazel command under src/
Line 24: Line 28:
 
You'll need to put those files to the corresponding places:
 
You'll need to put those files to the corresponding places:
  
<code>bazel-bin/unix/fcitx5/fcitx5-mozc.so</code> to <code>FCITX_PREFIX/lib/fcitx5/</code>
+
<code>bazel-bin/unix/fcitx5/fcitx5-mozc.so</code> to <code>FCITX_PREFIX/lib/fcitx5/</code> (For Debian/Ubuntu it should be <code>PREFIX/lib/[arch]/fcitx5</code>, e.g. <code>PREFIX/lib/x86_64-linux-gnu/fcitx5</code>).
  
 
<code>bazel-bin/server/mozc_server</code> to <code>/usr/lib/mozc</code>
 
<code>bazel-bin/server/mozc_server</code> to <code>/usr/lib/mozc</code>

Latest revision as of 02:17, 29 March 2022

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/fcitx5:fcitx5-mozc.so server:mozc_server gui/tool:mozc_tool

The command above will generate following files required by mozc:

bazel-bin/unix/fcitx5/fcitx5-mozc.so
bazel-bin/server/mozc_server
bazel-bin/gui/tool/mozc_tool

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

bazel-bin/unix/fcitx5/fcitx5-mozc.so to FCITX_PREFIX/lib/fcitx5/ (For Debian/Ubuntu it should be PREFIX/lib/[arch]/fcitx5, e.g. PREFIX/lib/x86_64-linux-gnu/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
../scripts/build_fcitx5
../scripts/install_server
../scripts/install_fcitx5

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.