1{ stdenv, lib, fetchgit, fetchFromGitHub
2, gn, ninja, python3, glib, pkg-config, icu
3, xcbuild, darwin
4, fetchpatch
5, llvmPackages
6, symlinkJoin
7}:
8
9# Use update.sh to update all checksums.
10
11let
12 version = "9.7.106.18";
13 v8Src = fetchgit {
14 url = "https://chromium.googlesource.com/v8/v8";
15 rev = version;
16 sha256 = "0cb3w733w1xn6zq9dsr43nx6llcg9hrmb2dkxairarj9c0igpzyh";
17 };
18
19 git_url = "https://chromium.googlesource.com";
20
21 # This data is from the DEPS file in the root of a V8 checkout.
22 deps = {
23 "base/trace_event/common" = fetchgit {
24 url = "${git_url}/chromium/src/base/trace_event/common.git";
25 rev = "7f36dbc19d31e2aad895c60261ca8f726442bfbb";
26 sha256 = "01b2fhbxznqbakxv42ivrzg6w8l7i9yrd9nf72d6p5xx9dm993j4";
27 };
28 "build" = fetchgit {
29 url = "${git_url}/chromium/src/build.git";
30 rev = "cf325916d58a194a935c26a56fcf6b525d1e2bf4";
31 sha256 = "1ix4h1cpx9bvgln8590xh7lllhsd9w1hd5k9l1gx5yxxrmywd3s4";
32 };
33 "third_party/googletest/src" = fetchgit {
34 url = "${git_url}/external/github.com/google/googletest.git";
35 rev = "16f637fbf4ffc3f7a01fa4eceb7906634565242f";
36 sha256 = "11012k3c3mxzdwcw2iparr9lrckafpyhqzclsj26hmfbgbdi0rrh";
37 };
38 "third_party/icu" = fetchgit {
39 url = "${git_url}/chromium/deps/icu.git";
40 rev = "eedbaf76e49d28465d9119b10c30b82906e606ff";
41 sha256 = "0mppvx7wf9zlqjsfaa1cf06brh1fjb6nmiib0lhbb9hd55mqjdjj";
42 };
43 "third_party/zlib" = fetchgit {
44 url = "${git_url}/chromium/src/third_party/zlib.git";
45 rev = "6da1d53b97c89b07e47714d88cab61f1ce003c68";
46 sha256 = "0v7ylmbwfwv6w6wp29qdf77kjjnfr2xzin08n0v1yvbhs01h5ppy";
47 };
48 "third_party/jinja2" = fetchgit {
49 url = "${git_url}/chromium/src/third_party/jinja2.git";
50 rev = "ee69aa00ee8536f61db6a451f3858745cf587de6";
51 sha256 = "1fsnd5h0gisfp8bdsfd81kk5v4mkqf8z368c7qlm1qcwc4ri4x7a";
52 };
53 "third_party/markupsafe" = fetchgit {
54 url = "${git_url}/chromium/src/third_party/markupsafe.git";
55 rev = "1b882ef6372b58bfd55a3285f37ed801be9137cd";
56 sha256 = "1jnjidbh03lhfaawimkjxbprmsgz4snr0jl06630dyd41zkdw5kr";
57 };
58 };
59
60 # See `gn_version` in DEPS.
61 gnSrc = fetchgit {
62 url = "https://gn.googlesource.com/gn";
63 rev = "8926696a4186279489cc2b8d768533e61bba73d7";
64 sha256 = "1084lnyb0a1khbgjvak05fcx6jy973wqvsf77n0alxjys18sg2yk";
65 };
66
67 myGn = gn.overrideAttrs (oldAttrs: {
68 version = "for-v8";
69 src = gnSrc;
70 });
71
72in
73
74stdenv.mkDerivation rec {
75 pname = "v8";
76 inherit version;
77
78 doCheck = true;
79
80 patches = [
81 ./darwin.patch
82 ];
83
84 src = v8Src;
85
86 postUnpack = ''
87 ${lib.concatStringsSep "\n" (
88 lib.mapAttrsToList (n: v: ''
89 mkdir -p $sourceRoot/${n}
90 cp -r ${v}/* $sourceRoot/${n}
91 '') deps)}
92 chmod u+w -R .
93 '';
94
95 postPatch = ''
96 ${lib.optionalString stdenv.isAarch64 ''
97 substituteInPlace build/toolchain/linux/BUILD.gn \
98 --replace 'toolprefix = "aarch64-linux-gnu-"' 'toolprefix = ""'
99 ''}
100 ${lib.optionalString stdenv.isDarwin ''
101 substituteInPlace build/config/compiler/compiler.gni \
102 --replace 'strip_absolute_paths_from_debug_symbols = true' \
103 'strip_absolute_paths_from_debug_symbols = false'
104 substituteInPlace build/config/compiler/BUILD.gn \
105 --replace 'current_toolchain == host_toolchain || !use_xcode_clang' \
106 'false'
107 ''}
108 ${lib.optionalString (stdenv.isDarwin && stdenv.isx86_64) ''
109 substituteInPlace build/config/compiler/BUILD.gn \
110 --replace "-Wl,-fatal_warnings" ""
111 ''}
112 touch build/config/gclient_args.gni
113 sed '1i#include <utility>' -i src/heap/cppgc/prefinalizer-handler.h # gcc12
114 '';
115
116 llvmCcAndBintools = symlinkJoin { name = "llvmCcAndBintools"; paths = [ stdenv.cc llvmPackages.llvm ]; };
117
118 gnFlags = [
119 "use_custom_libcxx=false"
120 "is_clang=${lib.boolToString stdenv.cc.isClang}"
121 "use_sysroot=false"
122 # "use_system_icu=true"
123 "clang_use_chrome_plugins=false"
124 "is_component_build=false"
125 "v8_use_external_startup_data=false"
126 "v8_monolithic=true"
127 "is_debug=true"
128 "is_official_build=false"
129 "treat_warnings_as_errors=false"
130 "v8_enable_i18n_support=true"
131 "use_gold=false"
132 # ''custom_toolchain="//build/toolchain/linux/unbundle:default"''
133 ''host_toolchain="//build/toolchain/linux/unbundle:default"''
134 ''v8_snapshot_toolchain="//build/toolchain/linux/unbundle:default"''
135 ] ++ lib.optional stdenv.cc.isClang ''clang_base_path="${llvmCcAndBintools}"''
136 ++ lib.optional stdenv.isDarwin ''use_lld=false'';
137
138 env.NIX_CFLAGS_COMPILE = "-O2";
139 FORCE_MAC_SDK_MIN = stdenv.targetPlatform.sdkVer or "10.12";
140
141 nativeBuildInputs = [
142 myGn
143 ninja
144 pkg-config
145 python3
146 ] ++ lib.optionals stdenv.isDarwin [
147 xcbuild
148 llvmPackages.llvm
149 python3.pkgs.setuptools
150 ];
151 buildInputs = [ glib icu ];
152
153 ninjaFlags = [ ":d8" "v8_monolith" ];
154
155 enableParallelBuilding = true;
156
157 installPhase = ''
158 install -D d8 $out/bin/d8
159 install -D -m644 obj/libv8_monolith.a $out/lib/libv8.a
160 install -D -m644 icudtl.dat $out/share/v8/icudtl.dat
161 ln -s libv8.a $out/lib/libv8_monolith.a
162 cp -r ../../include $out
163
164 mkdir -p $out/lib/pkgconfig
165 cat > $out/lib/pkgconfig/v8.pc << EOF
166 Name: v8
167 Description: V8 JavaScript Engine
168 Version: ${version}
169 Libs: -L$out/lib -lv8 -pthread
170 Cflags: -I$out/include
171 EOF
172 '';
173
174 meta = with lib; {
175 homepage = "https://v8.dev/";
176 description = "Google's open source JavaScript engine";
177 maintainers = with maintainers; [ cstrahan proglodyte matthewbauer ];
178 platforms = platforms.unix;
179 license = licenses.bsd3;
180 };
181}