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

# v8のソースコードダウンロード用の環境整備

`v８`のソースコードは`git`で管理されているが、`git`コマンドを利用してソースコード取得するのではなく、依存するライブラリ一式含めて用意してくれう`gclient`コマンドを利用してソースコードを取得する。

そこでまずは [gclient をオリジナルのドキュメントを参照](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up)して用意する

### リファレンス
[v8オリジナルドキュメント](https://v8.dev/docs/source-code)はx86を前提
[Arm64でClangでv8をコンパイル](https://blog.sqreen.com/how-we-built-v8-natively-on-arm/)した記録
[Arm64はGccでコンパイル](https://bugs.chromium.org/p/v8/issues/detail?id=6458#c7)したほうが良いという記録

# ビルド環境
| | |
|:--:|:---|
|PC| M1 MacBook Pro 2021 (Apple M1 Pro) |
|VM| UTM v3.0.4|
|OS| Ubuntu20.04|

# ソースコードをダウンロード

```console
$ mkdir ~work/v8
$ cd ~work/v8
$ fetch v8
$ gclient sync
```


# ARM用向け変更一覧
- `gn`を`x64`から`arm64`に置き換え（`DEPS`ファイル書き換えして `gclient sync`)
- システム側の`clang`を利用　(`gn`の引数に渡す)
- `clang`の`chromeプラグイン`を利用しない設定に変更　(`gn`の引数に渡す)
- `target_cpu`, `v8_target_cpu` を `"arm64"` に設定　(`gn`の引数に渡す)


```console
"$ git diff DEPS
```

```python:
diff --git a/DEPS b/DEPS
index 0ae8dd94f2..9d76ef568d 100644
--- a/DEPS
+++ b/DEPS
@@ -91,7 +91,7 @@ deps = {
   'buildtools/linux64': {
     'packages': [
       {
-        'package': 'gn/gn/linux-amd64',
+        'package': 'gn/gn/linux-arm64',
         'version': Var('gn_version'),
       }
     ],
```

```console
$ gclient sync
$ cd v8
$ gn gen out/Default --args='is_debug=false target_cpu="arm64" v8_target_cpu="arm64" clang_base_path="/lib/llvm-14" clang_use_chrome_plugins=false'
```

# コンパイル

```console
$ cat out/Default/args.gn 
is_debug = false
target_cpu = "arm64"
v8_target_cpu = "arm64"
clang_base_path = "/lib/llvm-14"
clang_use_chrome_plugins = false

$ ninja -C out/Default
ninja: Entering directory `out/Default/'
[3156/3156] STAMP obj/test/v8_optimize_for_size.stamp

$ tools/run-tests.py --outdir out/Default/
Build found: /home/rai/work/v8/v8/out/Default/
>>> Autodetected:
pointer_compression
pointer_compression_shared_cage
webassembly
>>> Running tests for arm64.release
>>> Running with test processors
[02:08|%  94|+ 19324|-   0]: Done                                             
>>> 20488 base tests produced 19324 (94%) non-filtered tests
>>> 19324 tests ran
```

# v8 のテスト
[Testing the V8 JavaScript Engine](https://medium.com/compilers/testing-the-v8-javascript-engine-cbda7d9272e6)

テストの種類
- benchmarks — Standard performance tuning benchmarks.
- test262 — Conformance tests against the ECMAScript specification.
- mjsunit — Unit tests written in JavaScript.
- cctest/u nittests— C++ unit tests for internal V8 classes.
- fuzzer — Input fuzzer tests providing invalid input, possibly crashing V8.
- intl — Tests for Internationalization features of ECMAScript.
- message — Validates error messages produced by invalid JavaScript code.
- webkit — Test cases borrowed from the WebKit JavaScript Engine.
- mozilla —Test cases borrowed from the Mozilla JavaScript Engine.
- wasm-js — Validation of WebAssembly, using the JavaScript API.
- wasm-api-tests — Validation of WebAssembly, using the C++ API.
- wasm-spec-tests — Conformance to the WebAssembly specification.
- inspector — Validates the V8 inspector interface (for debugging)
- debugger — Validates the built-in debugger command.

### Conformanceテストの実行
エラー発生なし

```console
$ tools/run-tests.py --outdir out/Default test262
Build found: /home/rai/work/v8/v8/out/Default
>>> Autodetected:
pointer_compression
pointer_compression_shared_cage
webassembly
>>> Running tests for arm64.release
>>> Running with test processors
[07:30|% 161|+ 86442|-   0]: Done                                             
>>> 53646 base tests produced 86442 (161%) non-filtered tests
>>> 86442 tests ran
```

### ベンチマークテストの実行
エラー発生なし

```console
$ tools/run-tests.py --outdir out/Default benchmarks
Build found: /home/rai/work/v8/v8/out/Default
>>> Autodetected:
pointer_compression
pointer_compression_shared_cage
webassembly
>>> Running tests for arm64.release
>>> Running with test processors
[00:06|% 100|+  55|-   0]: Done                                               
>>> 55 base tests produced 55 (100%) non-filtered tests
>>> 55 tests ran
```