Open7

DockerでV8のソースコードをビルドして実行する

tommy34tommy34

Dockerfile

FROM ubuntu:24.04

ENV TZ=Asia/Tokyo
ENV PATH=/depot_tools:$PATH

RUN ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && echo ${TZ} > /etc/timezone && \
  sed -i 's@archive.ubuntu.com@ftp.jaist.ac.jp/pub/Linux@g' /etc/apt/sources.list && \
  echo "bind 'set bell-style none'" >> .bashrc && \
  apt-get update && \
  apt-get install --no-install-recommends -y git wget curl python3 lsb-release \
    xz-utils libglib2.0-dev ca-certificates cloc && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/* && \
  git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

WORKDIR /depot_tools

RUN update_depot_tools && \
  fetch v8

WORKDIR /depot_tools/v8

RUN tools/dev/gm.py x64.release
tommy34tommy34
$ docker --version
Docker version 24.0.5, build ced0996
un
$ uname -a
Linux MyComputer 5.15.133.1-microsoft-standard-WSL2 #1 SMP Thu Oct 5 21:02:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
tommy34tommy34

コンテナのビルド

docker build -t v8 .
[+] Building 3632.1s (10/10) FINISHED                                         docker:default
 => [internal] load .dockerignore                                                       1.8s
 => => transferring context: 2B                                                         0.1s
 => [internal] load build definition from Dockerfile                                    1.3s
 => => transferring dockerfile: 742B                                                    0.2s
 => [internal] load metadata for docker.io/library/ubuntu:24.04                         0.0s
 => [1/6] FROM docker.io/library/ubuntu:24.04                                           0.0s
 => CACHED [2/6] RUN ln -snf /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && echo Asi  0.0s
 => CACHED [3/6] WORKDIR /depot_tools                                                   0.0s
 => [4/6] RUN update_depot_tools &&   fetch v8                                       2132.1s
 => [5/6] WORKDIR /depot_tools/v8                                                       1.4s
 => [6/6] RUN tools/dev/gm.py x64.release                                            1333.6s
 => exporting to image                                                                161.0s
 => => exporting layers                                                               160.7s
 => => writing image sha256:9fd9fb1e69fcad3a84b46101d99e4d111051039d5ae17018dbea6f6bf7  0.1s
 => => naming to docker.io/library/v8                                                   0.2s

What's Next?
  View summary of image vulnerabilities and recommendations → docker scout quickview
tommy34tommy34

https://v8.dev/docs/d8
https://gist.github.com/kevincennis/0cd2138c78a07412ef21

ビルドしたV8が実行できることを確認できる
d8はV8の開発用のシェルです

$ docker run -it --rm --name v8_container v8 bash
root@c3c824421702:/depot_tools/v8# ls
AUTHORS             INTL_OWNERS         PRESUBMIT.py  build_overrides      samples
BUILD.bazel         LICENSE             README.md     buildtools           src
BUILD.gn            LICENSE.fdlibm      RISCV_OWNERS  codereview.settings  test
CODE_OF_CONDUCT.md  LICENSE.strongtalk  S390_OWNERS   custom_deps          testing
COMMON_OWNERS       LICENSE.v8          WATCHLISTS    docs                 third_party
DEPS                LOONG_OWNERS        WORKSPACE     gni                  tools
DIR_METADATA        MIPS_OWNERS         base          include
ENG_REVIEW_OWNERS   OWNERS              bazel         infra
INFRA_OWNERS        PPC_OWNERS          build         out
root@c3c824421702:/depot_tools/v8# ls out
x64.release
root@c3c824421702:/depot_tools/v8# ls out/x64.release/
args.gn            bytecode_builtins_list_generator  icudtl.dat         toolchain.ninja
build.ninja        d8                                mksnapshot         torque
build.ninja.d      gen                               obj                v8_build_config.json
build.ninja.stamp  gen-regexp-special-case           snapshot_blob.bin  v8_features.json
root@c3c824421702:/depot_tools/v8# ./out/x64.release/d8
V8 version 12.3.0 (candidate)
d8> 1 + 1
2
d8> 1 + 1
2
d8> console.log("hello world")
hello world
undefined
d8> quit()
root@c3c824421702:/depot_tools/v8# cat <<EOF > test.js
> let a = 1;
> var b = 2;
> const c = 3;
> console.log(a + b + c);
> EOF
root@c3c824421702:/depot_tools/v8# ./out/x64.release/d8 test.js
6
root@c3c824421702:/depot_tools/v8#
tommy34tommy34

ソースコードの行数は約1400万行

root@c3c824421702:/depot_tools/v8# cloc --exclude-dir=build --exclude-dir=out .
  136818 text files.
  105802 unique files.
   35071 files ignored.

2 errors:
Line count, exceeded timeout:  ./test/benchmarks/data/sunspider/string-unpack-code.js
Line count, exceeded timeout:  ./test/webkit/fast/js/regexp-stack-overflow.js

github.com/AlDanial/cloc v 1.98  T=472.91 s (223.7 files/s, 40095.5 lines/s)
---------------------------------------------------------------------------------------
Language                             files          blank        comment           code
---------------------------------------------------------------------------------------
Text                                  4613          49923              0        3982561
C++                                  13669         445234         447470        3181943
JavaScript                           66094         697978        1416565        2715029
C/C++ Header                         11877         462022         803210        2362147
Python                                3095         125669         201135         473373
WebAssembly                            302          10510           3957         185692
JSON                                   360             81              0         171605
C                                      214          24354          20842         155632
Java                                   426          15861          28045         102327
CMake                                  973          13475          14062          75483
TypeScript                             508          10469          12692          72404
C#                                     161           6418          12477          55038
Objective-C                             82           7436           6876          51944
Protocol Buffers                       570           9526          25255          48548
Markdown                               339          12348             60          44124
Bourne Shell                           442           5105           6839          30254
HTML                                   123           2972            568          30195
diff                                    63            262          17059          21737
SQL                                    273           1517           7307          20070
XML                                    201           2933            899          19997
Windows Module Definition               10             51              0          19269
Starlark                                65           1335           1702          17200
PHP                                    141           2860           8936          15669
reStructuredText                       344           6882           6269          14105
Perl                                    52           2268           2973          11385
Bazel                                   45            929           1150          10167
CSS                                     25           1059            389           9588
YAML                                   101           1251            396           9413
CSV                                     25              4              0           6762
SCSS                                    47            743            752           5719
make                                    73            914           1007           5442
Ruby                                    29            845            398           5325
Pascal                                  39           1541           6517           4937
Assembly                                15            509           1418           4571
DTD                                      7           1065           4855           4106
m4                                      13            587            146           3828
TOML                                    35             87            289           3595
Bourne Again Shell                      93            663           1023           3319
Logos                                   12            245             16           1822
Maven                                   13             77             37           1480
DOS Batch                               64            353            470           1297
Dockerfile                              18            191            300           1152
Expect                                   9             23             28            675
Rust                                    38            151            273            647
Windows Resource File                    8            115            156            506
Go                                       5             44             36            416
INI                                     15             53              0            374
Lisp                                     4             89            151            353
Swift                                    1             51             58            351
TeX                                      2            119            114            312
Objective-C++                           23            145            281            283
Jinja Template                           8             23             18            265
PowerShell                               4             40             98            248
Korn Shell                               1             39             46            223
Scheme                                   1             13             51            222
vim script                               4             41             72            197
Handlebars                               1              5              0            156
Meson                                    2             24             25            129
MSBuild script                           7             29             16            120
SVG                                      7              0              0            117
Dart                                     2             17              7             93
R                                        1             12             22             79
Ant                                      1              8             15             57
Visual Studio Solution                   1              0              1             53
sed                                      3             11             23             35
XSLT                                     1              5              4             24
ANTLR Grammar                            1             21             18             20
awk                                      1              5              3             17
---------------------------------------------------------------------------------------
SUM:                                105802        1929635        3065877       13966226
---------------------------------------------------------------------------------------