ARM版Ubuntuで Chromium をコンパイルする

# 概要
### ソースコード取得とビルド
[GoogleのLinux版の手順通り](https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md)に進めていくと`x86`に依存した問題があちこちから出てくるので一つ一つ解決していく


### ビルド環境

|種類| 内容 |
|:--:|:---|
|デバイス| M1 MacBook Pro 2021 (Apple M1 Pro: 高効率8 + 2) |
|VM| UTM v3.0.4　（QEMU)　(GPU support:disable) |
|VM上のOS| Ubuntu20.04|
|割り当てたCPU| 6 core | 
|割り当てたRAM| 16GB |

コンパイル中の状況をみると16GBは使い切っている。もう少し割り当てたほうが早くコンパイルが終わりそうだ
![スクリーンショット 2022-02-23 13.33.59.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1017489/0889a718-9d66-5ce3-52c2-d193738c6386.png)

### コンパイル時間

約5時間

|時間の種類 | かかった時間|説明|
|:--:|:---|:---|
|real|	305m35.239s|指定したコマンドを実行するためにかかった時間|
|user|	1745m29.346s|指定したコマンドを実行するため使用したユーザーCPU時間|
|sys|	81m21.569s|指定したコマンドを実行するために使ったシステムCPU時間|

### ARM版Ubuntuでコンパイルするために修正概要
|修正箇所 | 不具合内容 | 修正内容 |
|:--:|:---|:---|
| install-build-deps.sh | `x８６`のみサポート | `Arm64`に対応 |
| gn | `x８６`版がダウンロードされる | `Arm64`版を利用するように`DEPS`を書き換え |
| ninja | `aarch64`に未対応 | ソースからコンパイルして利用 |
| clang | `x86`版を利用する　|`Arm64`版に設定変更 |
| NodeJS | `x８６`版がダウンロードされる | `Arm64`版で置き換え |
| JDK(JRE) |  `x８６`版がダウンロードされる | `Arm64`版で置き換え |
| clang-format | `x８６`版がダウンロードされる | `Arm64`版で置き換え |
| eu-strip | `x８６`版がダウンロードされる | システムの`Arm64`版で置き換え |
| libxkbcommon-dev | `v1.0.0`以上が必要 | `v1.0.3`版で置き換え |


### 無視した不具合
|不具合箇所 | 不具合内容 | 無視の理由 |
|:--:|:---|:---|
|gclient runhooks | NaCl関連で`AsssertionError` | `NaCl`は無効にするので無視 |
|v8_context_snapshot | `histogram.cc`でエラー | 動作はするので無視 |


# 作業内容
## install-buid-deps.sh の問題解決

:::note alert
install-buid-deps.sh はArm64を未サポートのためエラー発生
:::


```console
$ ./build/install-build-deps.sh
Only x86 architectures are currently supported
```

`x86`依存箇所を解決して`Arm64`で動作させたい
`./build/install-build-deps-aarch64.sh`を作成してそのファイルを修正していく

```console
＄　cp ./build/install-build-deps.sh ./build/install-build-deps-aarch64.sh 
```

最初の修正箇所
`aarch64`を追加して`x86`以外でエラーでストップしないように修正

```bash:install-build-deps-aarch64.sh_117行目
  if ! uname -m | egrep -q "i686|x86_64|aarch64"; then
    echo "Only x86 architectures are currently supported" >&2
    exit
  fi
```

`aarch64`を認識させて実行する

```console
$ bash -x ./build/install-build-deps-aarch64.sh

++ apt-get --just-print install apache2-bin binutils binutils-aarch64-linux-gnu binutils-arm-linux-gnueabihf binutils-mips64el-linux-gnuabi64 binutils-mipsel-linux-gnu bison bzip2 cdbs curl dbus-x11 devscripts dpkg-dev elfutils fakeroot flex git-core gperf lib32stdc++6 libapache2-mod-php7.4 libasound2 libasound2-dev libatk1.0-0 libatspi2.0-0 libatspi2.0-dev libbluetooth-dev libbrlapi0.7 libbrlapi-dev libbz2-1.0 libbz2-dev libc6 libc6-dev libc6-i386 libcairo2 libcairo2-dev libcap2 libcap-dev libcups2 libcups2-dev libcurl4-gnutls-dev libdrm2 libdrm-dev libelf-dev libevdev2 libevdev-dev libexpat1 libffi7 libffi-dev libfontconfig1 libfreetype6 libgbm1 libgbm-dev libglib2.0-0 libglib2.0-dev libglu1-mesa-dev libgtk-3-0 libgtk-3-dev libinput10 libinput-dev libjpeg-dev libkrb5-dev libnspr4 libnspr4-dev libnss3 libnss3-dev libpam0g libpam0g-dev libpango-1.0-0 libpci3 libpci-dev libpcre3 libpixman-1-0 libpng16-16 libpulse0 libpulse-dev libsctp-dev libspeechd2 libspeechd-dev libsqlite3-0 libsqlite3-dev libssl-dev libstdc++6 libudev1 libudev-dev libuuid1 libva-dev libvulkan1 libvulkan-dev libwayland-egl1-mesa libwww-perl libx11-6 libx11-xcb1 libxau6 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxinerama1 libxkbcommon-dev libxrandr2 libxrender1 libxshmfence-dev libxslt1-dev libxss-dev libxt-dev libxtst6 libxtst-dev locales mesa-common-dev openbox p7zip patch perl php7.4-cgi pkg-config python2-dev python-crypto python-is-python2 python-numpy python-openssl python-psutil python-setuptools python-yaml rpm ruby snapcraft subversion uuid-dev wdiff x11-utils xcompmgr xz-utils zip zlib1g
E: Unable to locate package lib32stdc++6
E: Couldn't find any package by regex 'lib32stdc++6'
E: Unable to locate package libc6-i386
```

:::note alert
x86(x64)に依存したパッケージでエラー
:::

`NaCl`関連のようなので`--no-nacl`とし、その他の必要ないパッケージも切って実行

```console:install-build-deps-aarch64.sh
$ bash -x ./build/install-build-deps-aarch64.sh --no-arm --no-chromeos-fonts --no-nacl --no-backwards-compatible 2> ../error2

++ apt-get --just-print install apache2-bin binutils binutils-aarch64-linux-gnu binutils-arm-linux-gnueabihf binutils-mips64el-linux-gnuabi64 binutils-mipsel-linux-gnu bison bzip2 cdbs curl dbus-x11 devscripts dpkg-dev elfutils fakeroot flex git-core gperf lib32stdc++6 libapache2-mod-php7.4 libasound2 libasound2-dev libatk1.0-0 libatspi2.0-0 libatspi2.0-dev libbluetooth-dev libbrlapi0.7 libbrlapi-dev libbz2-1.0 libbz2-dev libc6 libc6-dev libc6-i386 libcairo2 libcairo2-dev libcap2 libcap-dev libcups2 libcups2-dev libcurl4-gnutls-dev libdrm2 libdrm-dev libelf-dev libevdev2 libevdev-dev libexpat1 libffi7 libffi-dev libfontconfig1 libfreetype6 libgbm1 libgbm-dev libglib2.0-0 libglib2.0-dev libglu1-mesa-dev libgtk-3-0 libgtk-3-dev libinput10 libinput-dev libjpeg-dev libkrb5-dev libnspr4 libnspr4-dev libnss3 libnss3-dev libpam0g libpam0g-dev libpango-1.0-0 libpci3 libpci-dev libpcre3 libpixman-1-0 libpng16-16 libpulse0 libpulse-dev libsctp-dev libspeechd2 libspeechd-dev libsqlite3-0 libsqlite3-dev libssl-dev libstdc++6 libudev1 libudev-dev libuuid1 libva-dev libvulkan1 libvulkan-dev libwayland-egl1-mesa libwww-perl libx11-6 libx11-xcb1 libxau6 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxdmcp6 libxext6 libxfixes3 libxi6 libxinerama1 libxkbcommon-dev libxrandr2 libxrender1 libxshmfence-dev libxslt1-dev libxss-dev libxt-dev libxtst6 libxtst-dev locales mesa-common-dev openbox p7zip patch perl php7.4-cgi pkg-config python2-dev python-crypto python-is-python2 python-numpy python-openssl python-psutil python-setuptools python-yaml rpm ruby snapcraft subversion uuid-dev wdiff x11-utils xcompmgr xz-utils zip zlib1g
E: Unable to locate package lib32stdc++6
E: Couldn't find any package by regex 'lib32stdc++6'
E: Unable to locate package libc6-i386
```

同じパッケージでエラーが発生
`64bit`か否かのチェックはしているが`x64`か`Arm64`の確認をしておらずエラーになる
真面目に修正するのが面倒なのでとりあえず動けば良いという方針で修正

```bash:./build/install-build-deps-aarch64.sh_Line223
# if file -L /sbin/init | grep -q 'ELF 64-bit'; then
if 0; then
```

これでどうにか動作するようになった

```console:install-build-deps-aarch64.sh
$ bash -x ./build/install-build-deps-aarch64.sh --no-arm --no-chromeos-fonts --no-nacl --no-backwards-compatible
```

修正ファイルの差分

```diff:install-build-deps.sh
$ diff -u ./build/install-build-deps.sh ./build/install-build-deps-aarch64.sh
--- ./build/install-build-deps.sh	2022-02-17 15:01:03.989997756 +0000
+++ ./build/install-build-deps-aarch64.sh	2022-02-18 08:54:27.433185436 +0000
@@ -114,7 +114,7 @@
     exit 1
   fi
 
-  if ! uname -m | egrep -q "i686|x86_64"; then
+  if ! uname -m | egrep -q "i686|x86_64|aarch64"; then
     echo "Only x86 architectures are currently supported" >&2
     exit
   fi
@@ -220,16 +220,16 @@
 
 # 64-bit systems need a minimum set of 32-bit compat packages for the pre-built
 # NaCl binaries.
-if file -L /sbin/init | grep -q 'ELF 64-bit'; then
-  dev_list="${dev_list} libc6-i386 lib32stdc++6"
-
+# if file -L /sbin/init | grep -q 'ELF 64-bit'; then
+#  dev_list="${dev_list} libc6-i386 lib32stdc++6"
+#
   # lib32gcc-s1 used to be called lib32gcc1 in older distros.
-  if package_exists lib32gcc-s1; then
-    dev_list="${dev_list} lib32gcc-s1"
-  elif package_exists lib32gcc1; then
-    dev_list="${dev_list} lib32gcc1"
-  fi
-fi
+#  if package_exists lib32gcc-s1; then
+#    dev_list="${dev_list} lib32gcc-s1"
+#  elif package_exists lib32gcc1; then
+#    dev_list="${dev_list} lib32gcc1"
+#  fi
+# fi
 
 # Run-time libraries required by chromeos only
 chromeos_lib_list="libpulse0 libbz2-1.0"
@@ -659,6 +659,10 @@
        sort -u | sort -r -s -t: -k2 | tr "\n" " "
 )"
 
+echo "${dev_list} ${lib_list} ${dbg_list} ${lib32_list} ${arm_list}" \
+       "${nacl_list}" ${filtered_backwards_compatible_list} | tr " " "\n" | \
+       sort -u | sort -r -s -t: -k2 | tr "\n" " "
+
 if [ 1 -eq "${do_quick_check-0}" ] ; then
   if ! missing_packages="$(dpkg-query -W -f ' ' ${packages} 2>&1)"; then
     # Distinguish between packages that actually aren't available to the

```

### gclient runhooks の問題は無視

```console:gclient
$ gclient runhooks
Hook 'vpython -vpython-spec src/.vpython -vpython-tool install' took 14.78 secs
Hook 'vpython3 -vpython-spec src/.vpython3 -vpython-tool install' took 23.38 secs
Running hooks:   5% ( 7/121) nacltools                     
________ running 'python3 src/build/download_nacl_toolchains.py --mode nacl_core_sdk sync --extract' in '/home/rai/work/chromium'
Traceback (most recent call last):
  File "src/build/download_nacl_toolchains.py", line 56, in <module>
    sys.exit(Main(sys.argv[1:]))
  File "src/build/download_nacl_toolchains.py", line 52, in Main
    return package_version.main(args)
  File "/home/rai/work/chromium/src/native_client/build/package_version/package_version.py", line 1290, in main
    arguments = ParseArgs(args)
  File "/home/rai/work/chromium/src/native_client/build/package_version/package_version.py", line 1118, in ParseArgs
    host_arch = pynacl.platform.GetArch3264()
  File "/home/rai/work/chromium/src/native_client/pynacl/platform.py", line 133, in GetArch3264
    assert machine in ARCH3264_DICT, "Unrecognized arch machine: %s" % machine
AssertionError: Unrecognized arch machine: aarch64
Error: Command 'python3 src/build/download_nacl_toolchains.py --mode nacl_core_sdk sync --extract' returned non-zero exit status 1 in /home/rai/work/chromium
Traceback (most recent call last):
  File "src/build/download_nacl_toolchains.py", line 56, in <module>
    sys.exit(Main(sys.argv[1:]))
  File "src/build/download_nacl_toolchains.py", line 52, in Main
    return package_version.main(args)
  File "/home/rai/work/chromium/src/native_client/build/package_version/package_version.py", line 1290, in main
    arguments = ParseArgs(args)
  File "/home/rai/work/chromium/src/native_client/build/package_version/package_version.py", line 1118, in ParseArgs
    host_arch = pynacl.platform.GetArch3264()
  File "/home/rai/work/chromium/src/native_client/pynacl/platform.py", line 133, in GetArch3264
    assert machine in ARCH3264_DICT, "Unrecognized arch machine: %s" % machine
AssertionError: Unrecognized arch machine: aarch64
```

`aarch64`に未対応だとのエラーがでているが、`AssertionError`であり`NaCl`関係のエラーのようだ。今回は`NaCl`を `disable` すれば良いだろうということで`AssertionError`を無視して進める。


## gn の問題解決
:::note alert
gnはx86実行形式ファイルのためエラーとなる
:::


```console:gn
$ gn gen out/Default
Traceback (most recent call last):
  File "/home/rai/depot_tools/gn.py", line 74, in <module>
    sys.exit(main(sys.argv))
  File "/home/rai/depot_tools/gn.py", line 69, in main
    return subprocess.call([gn_path] + args[1:])
  File "/usr/lib/python3.8/subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/home/rai/work/chromium/src/buildtools/linux64/gn'

$ file /home/rai/work/chromium/src/buildtools/linux64/gn 
/home/rai/work/chromium/src/buildtools/linux64/gn: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[xxHash]=8e3face38c436111, with debug_info, not stripped
```

`gn`はリポジトリに最初から存在しているわけではなく、`gclient sync`でダウンロードしてきている。
`Arm64版`をどこからか調達して置き換えたい

`Google`で`gn linux-arm64`を検索しダウンロード先を見つける

:::note info
https://chrome-infra-packages.appspot.com/p/gn/gn/linux-arm64/+/
:::

`DEPS`ファイルを修正 (`DEPS`ファイルは `chromium/src` に存在)

```diff:DEPS
$ git diff DEPS
diff --git a/DEPS b/DEPS
index bfa84e162e..1ff9312431 100644
--- a/DEPS
+++ b/DEPS
@@ -463,7 +463,7 @@ deps = {
   'src/buildtools/linux64': {
     'packages': [
       {
-        'package': 'gn/gn/linux-amd64',
+        'package': 'gn/gn/linux-arm64',
         'version': Var('gn_version'),
       }
     ],
```

ダウンロードするバイナリを`Arm64版`へ変更する

```console:gn_from_x64_to_arm64
$ mv ./buildtools/linux64/gn ./buildtools/linux64/gn.old
$ gclient sync
$ file ./buildtools/linux64/gn
./buildtools/linux64/gn: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[xxHash]=bca2f2f50b449b21, with debug_info, not stripped
```

gn を実行

```console:gn
$ gn gen out/Default --args='is_debug=false symbol_level=0 enable_nacl=false blink_symbol_level=0 v8_symbol_level=0 target_cpu="arm64" v8_target_cpu="arm64"'
```

:::note info
必要のない機能を切りターゲットCPUをArm64に設定
:::

# ninja の問題解決
:::note alert
autoninjaはaarch64をサポートしていない
:::

エラーで`ninja`のインストール方法を表示する
指示通りに`ninja`をコンパイルしてインストールする

```console:autoninja
$ autoninja -C out/Default unit_tests
Unknown architecture (aarch64) -- unable to run ninja.
No prebuilt ninja binary was found for this system.
Try building your own binary by doing:
  cd ~
  git clone https://github.com/ninja-build/ninja.git -b v1.8.2
  cd ninja && ./configure.py --bootstrap
Then add ~/ninja/ to your PATH.
```
:::note info
インストールしたninjaのパスをdepot_toolsより優先する形でPATHを設定すること
:::


## clang の問題解決
:::note alert
Chromium付属のclangがx86実行形式のためエラーとなる
:::

```console:ninja
$ ninja -C out/Default chrome
/bin/sh: 1: ../../third_party/llvm-build/Release+Asserts/bin/clang++: Exec format error
```

### `Ubuntu`の`clang`を利用するように変更

変更方法は[Chromiumのclang設定のページ](https://chromium.googlesource.com/chromium/src/+/HEAD/docs/clang.md#Using-gcc-on-Linux)を確認

```console:install_Ubuntu_clang
$ sudo apt install clang
$ gn gen out/Default --args='is_debug=false symbol_level=0 enable_nacl=false blink_symbol_level=0 v8_symbol_level=0 target_cpu="arm64" clang_base_path="/usr" clang_use_chrome_plugins=false is_component_build=true'
```

### `Ubuntu`の`clang`でコンパイル
```console:ninja
$ ninja -C out/Default chrome
```

:::note alert
clang が -ffile-compilation-dir を未サポート
:::
Ubuntu20.10で標準インストールの`clang`はバージョン10
`-ffile-compilation-dir`のサポートはバージョン14以上

### 最新の`clang`をインストール
[llvmのページ](https://apt.llvm.org/)に従って最新の`clang`をインストールする

```console:install_clang-14
$ sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
```

### `clang-14`を使ってコンパイルを再開

```console:clang-14
$ gn gen out/Default --args='is_debug=false symbol_level=0 enable_nacl=false blink_symbol_level=0 v8_symbol_level=0 target_cpu="arm64" clang_base_path="/lib/llvm-14" clang_use_chrome_plugins=false is_component_build=true v8_target_cpu="arm64"'
Done. Made 16853 targets from 2969 files in 1746ms

$ cat out/Default/args.gn 
is_debug = false
symbol_level = 0
enable_nacl = false
blink_symbol_level = 0
v8_symbol_level = 0
target_cpu = "arm64"
clang_base_path = "/lib/llvm-14"
clang_use_chrome_plugins = false
is_component_build = true
v8_target_cpu = "arm64"

$ ninja -C out/Default chrome
```

## NodeJSの問題を解決する
:::note alert
NodeJSがx86実行形式のためエラーとなる
:::

```console
OSError: [Errno 8] Exec format error: '/home/rai/work/chromium/src/out/Default/../../third_party/node/linux/node-linux-x64/bin/node'
[1636/86441] ACTION //chrome/browser/metrics:expired_histograms_array(//build/toolchain/linux:clang_arm64)
ninja: build stopped: subcommand failed.
```

### NodeJSをArm64版で置き換え 
ダウンロードサイト: https://nodejs.org/ja/download/
![名称未設定.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1017489/89259305-08dd-ff53-32fb-9e9a337dad8b.png)

:::note info
~Download にarm64版を保存
:::


```console
$ cd ~Download
$ unxz node-v16.14.0-linux-arm64.tar.xz
$ tar xvf node-v16.14.0-linux-arm64.tar 
$ file ./node-v16.14.0-linux-arm64/bin/node 
./node-v16.14.0-linux-arm64/bin/node: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=de8279f86fdfbb27665343afb853f036059cc39d, with debug_info, not stripped
```

`NodeJS`を`Arm64版`に置き換える

```console
$ cd ~/work/chromium/src/third_party/node/linux/node-linux-x64/bin
$ mv node node.old
$ ln -s ~/Downloads/node-v16.14.0-linux-arm64/bin/node node
```

## JDKの問題解決
:::note alert
JDKがx86実行形式のためエラーとなる
:::

```console
/bin/sh: 1: /home/rai/work/chromium/src/third_party/closure_compiler/../jdk/current/bin/java: Exec format error

[2063/84644] CXX obj/third_party/angle/angle_common/PackedEnums.o
ninja: build stopped: subcommand failed.
```

`JDK`の説明を読むと`Arm64版`の`JRE`に置き換えてやれば動きそう

```text:third_party/jdk/README.chromium
How to update:
For the `jdk` directory:
1. Find the specific version you want to update from
   https://wiki.openjdk.java.net/display/JDKUpdates/JDK11u#JDK11u-Releases
2. Click the link "[Binaries]" for the specific version.
3. Copy the link address of the asset "OpenJDK11U-jre_x64_linux_<specific_version>.tar.gz"
4. Update the "download_url" and "version" in 3pp/3pp.pb with the desired values.
5. Upload and land the CL.
6. Wait for the 3pp packager (https://ci.chromium.org/p/chromium/builders/ci/3pp-linux-amd64-packager)
   to create the new instance at https://chrome-infra-packages.appspot.com/p/chromium/third_party/jdk/+/
7. Update instance ID in //DEPS

For the `jdk/extras` subdirectory:
1. Find the specific version you want to update from
   https://wiki.openjdk.java.net/display/jdk8u#Main-Releases
2. Click the link "[Binaries]" for the specific version.
3. Copy the link address of the asset "OpenJDK8U-jdk_x64_linux_<specific_version>.tar.gz"
4. Update the "download_url" and "version" in 3pp/3pp.pb with the desired values.
5. Upload and land the CL.
6. Wait for the 3pp packager (https://ci.chromium.org/p/chromium/builders/ci/3pp-linux-amd64-packager)
   to create the new instance at https://chrome-infra-packages.appspot.com/p/chromium/third_party/jdk/extras/+/
7. Update instance ID in //DEPS
```

### JREをArm64版で置き換える

:::note info
GitHubからArm64版のJREを ~/Download にダウンロードする
https://github.com/adoptium/temurin11-binaries/releases/tag/jdk-11.0.14%2B9
OpenJDK11U-jre_aarch64_linux_hotspot_11.0.14_9.tar.gz
:::


```console
$ cd ~Download
$ tar zxvf OpenJDK11U-jre_aarch64_linux_hotspot_11.0.14_9.tar.gz
$ cd ~work/chromium/src/third_party/jdk/current
$ cp -Rf ~/Downloads/jdk-11.0.14+9-jre/* .
```

## clang-format の問題解決
:::note alert
clang-formatがx86実行形式のためエラーとなる
:::
 
```console
OSError: [Errno 8] Exec format error: '/home/rai/work/chromium/src/buildtools/linux64/clang-format'
$ file buildtools/linux64/clang-format
buildtools/linux64/clang-format: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped
```

`src/DEPS`ファイルを確認する 
ハッシュ指定で`clang-format`をダウンロードしてきているようだ

```python:src/DEPS
  # Pull clang-format binaries using checked-in hashes.

  {
    'name': 'clang_format_linux',
    'pattern': '.',
    'condition': 'host_os == "linux"',
    'action': [ 'python3',
                'src/third_party/depot_tools/download_from_google_storage.py',
                '--no_resume',
                '--no_auth',
                '--bucket', 'chromium-clang-format',
                '-s', 'src/buildtools/linux64/clang-format.sha1',
    ],
  },
```

`DEPS`ファイルを書き換えが面倒そうなので直接置き換えた

```console
$ sudo apt-get install clang-format-14
$ cd buildtools/linux64
$ mv clang-format clang-format.old
$ ln -s /lib/llvm-14/bin/clang-14 clang-format
```

## eu-strip の問題解決
:::note alert
eu-stripがx86実行形式のためエラーとなる
:::

```console
OSError: [Errno 8] Exec format error: '../../buildtools/third_party/eu-strip/bin/eu-strip'
[42737/67249] ACTION //v8:run_mksnapshot_default(//build/toolchain/linux:clang_arm64)

$ file buildtools/third_party/eu-strip/bin/eu-strip 
buildtools/third_party/eu-strip/bin/eu-strip: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, stripped
```

`eu-strip`関連のファイルを確認すると`elfutils`に含まれているらしいことが分かる

```bash:buildtools/third_party/eu-strip/build.sh
#!/bin/sh -xe

rm -rf elfutils
git clone git://sourceware.org/git/elfutils.git
cd elfutils
git checkout elfutils-0.170
autoheader
aclocal
autoconf
automake --add-missing
patch -p1 < ../fix-elf-size.patch
mkdir build
cd build
../configure --enable-maintainer-mode
make -j40
gcc -std=gnu99 -Wall -Wshadow -Wunused -Wextra -fgnu89-inline \
  -Wformat=2 -Werror -g -O2 -Wl,-rpath-link,libelf:libdw -Wl,--build-id=none -o eu-strip \
  src/strip.o libebl/libebl.a libelf/libelf.a lib/libeu.a libdw/libdw.a -ldl -lz
./eu-strip -o ../../bin/eu-strip eu-strip
```

`elfutils`なら標準でインストールされいそうなので確認する

```console
$ which eu-strip
/usr/bin/eu-strip
```

`eu-strip`をシステムの`eu-strip`で置き換える

```console
$ cd bin
$ mv eu-strip eu-strip.old
$ ln -s /usr/bin/eu-strip eu-strip
```


## 残りの x86 実行形式のファイルの確認

### src/buildtools

`gn`,`clang-format`と`eu-strip`が解決できていれば大丈夫そうだ

```console:src/buildtools
$ cd ./buildtools
$ for i in `find .`; do file $i | grep x86-64; done
./linux64/clang-format.old: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, stripped
./third_party/eu-strip/bin/eu-strip.old: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, stripped
rai@rai:~/work/ch
```

## v8_context_snapshot_generatorの問題解決

:::note alert
v8_context_snapshot_generator　でエラー発生
:::

```console
//tools/v8_context_snapshot:g...text_snapshot(//build/toolchain/linux:clang_arm64)
FAILED: v8_context_snapshot.bin 
python3 ../../build/gn_run_binary.py ./v8_context_snapshot_generator --output_file=v8_context_snapshot.bin
././v8_context_snapshot_generator: /lib/aarch64-linux-gnu/libxkbcommon.so.0: version `V_1.0.0' not found (required by /home/rai/work/chromium/src/out/Default/libevents_ozone_layout.so)
./v8_context_snapshot_generator failed with exit code 1
```


### libxkbcommon-dev の v1.0.3 を用意
[Ubuntu20.04のlibxkbcommon-devのバージョンが0.10.0](https://packages.ubuntu.com/focal/libxkbcommon0)であることが問題と思われる

```console
$ ls -l /lib/aarch64-linux-gnu/libxkbcommon*
lrwxrwxrwx 1 root root     17 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon.so -> libxkbcommon.so.0
lrwxrwxrwx 1 root root     21 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon.so.0 -> libxkbcommon.so.0.0.0
-rw-r--r-- 1 root root 256344 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon.so.0.0.0
lrwxrwxrwx 1 root root     25 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon-x11.so.0 -> libxkbcommon-x11.so.0.0.0
-rw-r--r-- 1 root root  31464 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon-x11.so.0.0.0
```

[libxkbcommon0(v1.0.3)のソースコード](https://packages.ubuntu.com/hirsute/libxkbcommon0)を[Ubuntuのサイト](https://packages.ubuntu.com/hirsute/libxkbcommon0)からダウンロードする

```console:ファイルの展開
$ cd Downloads/
$ unxz libxkbcommon_1.0.3.orig.tar.xz 
$ tar xvf libxkbcommon_1.0.3.orig.tar 
$ cd libxkbcommon-1.0.3/
```

```console:必要なコマンドやライブラリが不足している場合は適時インストールする
$ sudo apt-get install meson
$ sudo apt-get install cmake
$ sudo apt-get install libxcb-xkb*
$ sudo apt-get install valgrind doxygen
```

```console:libxkbcommonをインストール
$ meson setup build 
$ ninja -C build/
$ ls -l ./build/libxkbcommon*
lrwxrwxrwx 1 rai rai      17 Feb 22 13:23 ./build/libxkbcommon.so -> libxkbcommon.so.0
lrwxrwxrwx 1 rai rai      21 Feb 22 13:23 ./build/libxkbcommon.so.0 -> libxkbcommon.so.0.0.0
-rwxrwxr-x 1 rai rai  693960 Feb 22 13:23 ./build/libxkbcommon.so.0.0.0
-rw-rw-r-- 1 rai rai 1327270 Feb 22 13:23 ./build/libxkbcommon-test-internal.a
-rw-rw-r-- 1 rai rai  220910 Feb 22 13:23 ./build/libxkbcommon-x11-internal.a
lrwxrwxrwx 1 rai rai      21 Feb 22 13:23 ./build/libxkbcommon-x11.so -> libxkbcommon-x11.so.0
lrwxrwxrwx 1 rai rai      25 Feb 22 13:23 ./build/libxkbcommon-x11.so.0 -> libxkbcommon-x11.so.0.0.0
-rwxrwxr-x 1 rai rai  126136 Feb 22 13:23 ./build/libxkbcommon-x11.so.0.0.0
```

```console:システムのlibxkbcommonをv1.0.3にすり替える 
$ sudo mv /lib/aarch64-linux-gnu/libxkbcommon.so.0 /lib/aarch64-linux-gnu/libxkbcommon.so.0.old
$ sudo ln -s /home/rai/Downloads/libxkbcommon-1.0.3/build/libxkbcommon.so.0.0.0 /lib/aarch64-linux-gnu/libxkbcommon.so.0
$ ls -l /lib/aarch64-linux-gnu/libxkbcommon*
lrwxrwxrwx 1 root root     17 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon.so -> libxkbcommon.so.0
lrwxrwxrwx 1 root root     66 Feb 22 13:28 /lib/aarch64-linux-gnu/libxkbcommon.so.0 -> /home/rai/Downloads/libxkbcommon-1.0.3/build/libxkbcommon.so.0.0.0
-rw-r--r-- 1 root root 256344 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon.so.0.0.0
lrwxrwxrwx 1 root root     21 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon.so.0.old -> libxkbcommon.so.0.0.0
lrwxrwxrwx 1 root root     25 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon-x11.so.0 -> libxkbcommon-x11.so.0.0.0
-rw-r--r-- 1 root root  31464 Feb  6  2020 /lib/aarch64-linux-gnu/libxkbcommon-x11.so.0.0.0
```

## 上記の内容を全て適応した後にコンパイル
エラーが１つ発生したが`chrome`の実行バイナリは作成された

```console
$ time ninja -C out/Default
ninja: Entering directory `out/Default'
[85735/86609] ACTION //tools/v8_context_snapshot:g...text_snapshot(//build/toolchain/linux:clang_arm64)
[0223/054106.523178:ERROR:histogram.cc(445)] Histogram: V8.GC.Cycle.CollectionRate.Full.Cpp has bad minimum: 0
[86609/86609] STAMP obj/gn_all.stamp

real	305m35.239s
user	1745m29.346s
sys	81m21.569s
```

# Chromiumの実行

エラーログを吐きつつも実行は可能

```console
$ ./out/Default/chrome
[1839466:1839466:0222/233226.407985:ERROR:power_monitor_device_source_stub.cc(11)] Not implemented reached in virtual bool base::PowerMonitorDeviceSource::IsOnBatteryPower()
[1839466:1839495:0222/233226.621578:ERROR:histogram.cc(445)] Histogram: SimpleCache.Code.IndexNumEntriesOnInit has bad minimum: 0
[1839507:1839507:0222/233226.682671:ERROR:viz_main_impl.cc(188)] Exiting GPU process due to errors during initialization
[1839508:1839541:0222/233226.855055:ERROR:histogram.cc(445)] Histogram: SimpleCache.Http.IndexNumEntriesOnInit has bad minimum: 0
[1839548:1:0222/233226.870357:ERROR:histogram.cc(445)] Histogram: Style.RecalcTime has bad minimum: 0
[1839548:1:0222/233226.871384:ERROR:histogram.cc(445)] Histogram: Style.RebuildLayoutTreeTime has bad minimum: 0
[1839574:1839574:0222/233226.998910:ERROR:viz_main_impl.cc(188)] Exiting GPU process due to errors during initialization
[1839593:1839593:0222/233227.086728:ERROR:sandbox_linux.cc(377)] InitializeSandbox() called with multiple threads in process gpu-process.
[1839593:1839593:0222/233227.102454:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.
[1839466:1839466:0222/233227.106389:ERROR:histogram.cc(445)] Histogram: GPU.AcceleratedSurfaceRefreshRate has bad minimum: 0
[1839548:1:0222/233227.111299:ERROR:histogram.cc(445)] Histogram: DocumentEventTiming.PageHideDuration has bad minimum: 0
[1839548:1:0222/233227.111603:ERROR:histogram.cc(445)] Histogram: DocumentEventTiming.PageVibilityHiddenDuration has bad minimum: 0
[1839548:8:0222/233227.111638:ERROR:command_buffer_proxy_impl.cc(125)] ContextResult::kTransientFailure: Failed to send GpuControl.CreateCommandBuffer.
```

無事Chromiumが起動

![スクリーンショット 2022-02-22 22.30.09.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1017489/9c8b7987-c5e3-c06b-a9f1-5e6374ca14df.png)

YouTubeで動画再生もOK
音声も再生している

![スクリーンショット 2022-02-22 22.54.05.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/1017489/6e703957-9bf7-9b99-c7c1-3bb7af58bc57.png)