<commit_before># How to build Mozc in Docker

## Introduction
Docker containers are available to build Mozc binaries for Android JNI library and Linux desktop.

## System Requirements
Currently, only Ubuntu 20.04 is tested to host the Docker container to build Mozc.

* [Dockerfile](https://github.com/google/mozc/blob/master/docker/ubuntu20.04/Dockerfile) for Ubuntu 20.04

## Set up Ubuntu 20.04 Docker container

```
curl -O https://raw.githubusercontent.com/google/mozc/master/docker/ubuntu20.04/Dockerfile
sudo docker build --rm -t $USER/mozc_ubuntu20.04 .
sudo docker run --interactive --tty --rm $USER/mozc_ubuntu20.04
```

### Hint
Don't forget to rebuild Docker container when Dockerfile is updated.

-----

## Build Mozc for Linux Desktop

```
bazel build package --config oss_linux -c opt
```

`package` is an alias to build:
* //server:mozc_server
* //gui/tool:mozc_tool
* //renderer:mozc_renderer
* //unix/ibus:ibus_mozc
* //unix:icons
* //unix/emacs:mozc_emacs_helper

### Install paths

| build path   | install path |
| ------------ | ------------ |
| bazel-bin/server/mozc_server           | /usr/lib/mozc/mozc_server |
| bazel-bin/gui/tool/mozc_tool           | /usr/lib/mozc/mozc_tool |
| bazel-bin/renderer/mozc_renderer       | /usr/lib/mozc/mozc_renderer |
| bazel-bin/unix/ibus/ibus_mozc          | /usr/lib/ibus-mozc/ibus-engine-mozc |
| bazel-bin/unix/ibus/mozc.xml           | /usr/share/ibus/component/mozc.xml |
| bazel-bin/unix/emacs/mozc_emacs_helper | /usr/bin/mozc_emacs_helper |

Also, unzip bazel-bin/unix/icons.zip into /usr/share/ibus-mozc/.

### Unittests

```
bazel test ... --config oss_linux -c dbg -- -net/... -third_party/...
```
<commit_msg>Add more instructions about Docker build.<commit_after># How to build Mozc in Docker

## Introduction
Docker containers are available to build Mozc binaries for Android JNI library and Linux desktop.

## System Requirements
Currently, only Ubuntu 20.04 is tested to host the Docker container to build Mozc.

* [Dockerfile](https://github.com/google/mozc/blob/master/docker/ubuntu20.04/Dockerfile) for Ubuntu 20.04

## Build in Docker

### Set up Ubuntu 20.04 Docker container

```
curl -O https://raw.githubusercontent.com/google/mozc/master/docker/ubuntu20.04/Dockerfile
docker build --rm -tag mozc_ubuntu20.04 .
docker create --interactive --tty --name mozc_build mozc_ubuntu20.04
```

You may need to execute `docker` with `sudo` (e.g. `sudo docker build ...`).

Notes
* `mozc_ubuntu20.04` is a Docker image name (customizable).
* `mozc_build` is a Docker contaniner name (customizable).
* Don't forget to rebuild Docker container when Dockerfile is updated.


### Build Mozc in Docker container

```
docker start mozc_build
docker exec mozc_build bazel build package --config oss_linux -c opt
```

Notes
* You might want to execute `docker stop` after `docker exec`.
* `mozc_build` is the Docker contaniner name created in the above section.


### Copy Mozc binaries from Docker container to host

```
docker cp mozc_build:/home/mozc_builder/work/mozc/src/bazel-bin/server/mozc_server .
docker cp mozc_build:/home/mozc_builder/work/mozc/src/bazel-bin/unix/ibus/ibus_mozc .
...
```

See [Install paths](#install-paths) below for more information about
the build and install paths.

Notes
* You might want to execute `docker stop` after copying.
* `mozc_build` is the Docker contaniner name created in the above section.

-----

## Build Mozc for Linux Desktop

```
bazel build package --config oss_linux -c opt
```

Note: You might want to execute `docker start --interactive mozc_build`
to enter the docker container before the above command.

`package` is an alias to build:
* //server:mozc_server
* //gui/tool:mozc_tool
* //renderer:mozc_renderer
* //unix/ibus:ibus_mozc
* //unix:icons
* //unix/emacs:mozc_emacs_helper

### Install paths

| build path   | install path |
| ------------ | ------------ |
| bazel-bin/server/mozc_server           | /usr/lib/mozc/mozc_server |
| bazel-bin/gui/tool/mozc_tool           | /usr/lib/mozc/mozc_tool |
| bazel-bin/renderer/mozc_renderer       | /usr/lib/mozc/mozc_renderer |
| bazel-bin/unix/ibus/ibus_mozc          | /usr/lib/ibus-mozc/ibus-engine-mozc |
| bazel-bin/unix/ibus/mozc.xml           | /usr/share/ibus/component/mozc.xml |
| bazel-bin/unix/emacs/mozc_emacs_helper | /usr/bin/mozc_emacs_helper |

Also, unzip bazel-bin/unix/icons.zip into /usr/share/ibus-mozc/.

### Unittests

```
bazel test ... --config oss_linux -c dbg -- -net/... -third_party/...
```

{'fraction_non_alphanumeric': 0.13803067348299622, 'fraction_numerical': 0.013336296954878863, 'mean_word_length': 3.326923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2106463', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1536, 'n_words': 404}