|
| 1 | +{ |
| 2 | + stdenv, |
| 3 | + lib, |
| 4 | + fetchgit, |
| 5 | + gn, |
| 6 | + ninja, |
| 7 | + python3, |
| 8 | + glib, |
| 9 | + pkg-config, |
| 10 | + icu, |
| 11 | + xcbuild, |
| 12 | + fetchpatch, |
| 13 | + llvmPackages, |
| 14 | + symlinkJoin, |
| 15 | +}: |
| 16 | + |
| 17 | +# Copied from nixpkgs revision f311b2493888dbf499e769c8015de9b40e4d590d. |
| 18 | + |
| 19 | +let |
| 20 | + version = "9.7.106.18"; |
| 21 | + v8Src = fetchgit { |
| 22 | + url = "https://chromium.googlesource.com/v8/v8"; |
| 23 | + rev = version; |
| 24 | + sha256 = "0cb3w733w1xn6zq9dsr43nx6llcg9hrmb2dkxairarj9c0igpzyh"; |
| 25 | + }; |
| 26 | + |
| 27 | + git_url = "https://chromium.googlesource.com"; |
| 28 | + |
| 29 | + # This data is from the DEPS file in the root of a V8 checkout. |
| 30 | + deps = { |
| 31 | + "base/trace_event/common" = fetchgit { |
| 32 | + url = "${git_url}/chromium/src/base/trace_event/common.git"; |
| 33 | + rev = "7f36dbc19d31e2aad895c60261ca8f726442bfbb"; |
| 34 | + sha256 = "01b2fhbxznqbakxv42ivrzg6w8l7i9yrd9nf72d6p5xx9dm993j4"; |
| 35 | + }; |
| 36 | + "build" = fetchgit { |
| 37 | + url = "${git_url}/chromium/src/build.git"; |
| 38 | + rev = "cf325916d58a194a935c26a56fcf6b525d1e2bf4"; |
| 39 | + sha256 = "1ix4h1cpx9bvgln8590xh7lllhsd9w1hd5k9l1gx5yxxrmywd3s4"; |
| 40 | + }; |
| 41 | + "third_party/googletest/src" = fetchgit { |
| 42 | + url = "${git_url}/external/github.com/google/googletest.git"; |
| 43 | + rev = "16f637fbf4ffc3f7a01fa4eceb7906634565242f"; |
| 44 | + sha256 = "11012k3c3mxzdwcw2iparr9lrckafpyhqzclsj26hmfbgbdi0rrh"; |
| 45 | + }; |
| 46 | + "third_party/icu" = fetchgit { |
| 47 | + url = "${git_url}/chromium/deps/icu.git"; |
| 48 | + rev = "eedbaf76e49d28465d9119b10c30b82906e606ff"; |
| 49 | + sha256 = "0mppvx7wf9zlqjsfaa1cf06brh1fjb6nmiib0lhbb9hd55mqjdjj"; |
| 50 | + }; |
| 51 | + "third_party/zlib" = fetchgit { |
| 52 | + url = "${git_url}/chromium/src/third_party/zlib.git"; |
| 53 | + rev = "6da1d53b97c89b07e47714d88cab61f1ce003c68"; |
| 54 | + sha256 = "0v7ylmbwfwv6w6wp29qdf77kjjnfr2xzin08n0v1yvbhs01h5ppy"; |
| 55 | + }; |
| 56 | + "third_party/jinja2" = fetchgit { |
| 57 | + url = "${git_url}/chromium/src/third_party/jinja2.git"; |
| 58 | + rev = "ee69aa00ee8536f61db6a451f3858745cf587de6"; |
| 59 | + sha256 = "1fsnd5h0gisfp8bdsfd81kk5v4mkqf8z368c7qlm1qcwc4ri4x7a"; |
| 60 | + }; |
| 61 | + "third_party/markupsafe" = fetchgit { |
| 62 | + url = "${git_url}/chromium/src/third_party/markupsafe.git"; |
| 63 | + rev = "1b882ef6372b58bfd55a3285f37ed801be9137cd"; |
| 64 | + sha256 = "1jnjidbh03lhfaawimkjxbprmsgz4snr0jl06630dyd41zkdw5kr"; |
| 65 | + }; |
| 66 | + }; |
| 67 | + |
| 68 | + # See `gn_version` in DEPS. |
| 69 | + gnSrc = fetchgit { |
| 70 | + url = "https://gn.googlesource.com/gn"; |
| 71 | + rev = "8926696a4186279489cc2b8d768533e61bba73d7"; |
| 72 | + sha256 = "1084lnyb0a1khbgjvak05fcx6jy973wqvsf77n0alxjys18sg2yk"; |
| 73 | + }; |
| 74 | + |
| 75 | + myGn = gn.overrideAttrs (oldAttrs: { |
| 76 | + version = "for-v8"; |
| 77 | + src = gnSrc; |
| 78 | + configurePhase = '' |
| 79 | + runHook preConfigure |
| 80 | +
|
| 81 | + python build/gen.py --no-last-commit-position |
| 82 | + cat > out/last_commit_position.h << EOF |
| 83 | + #ifndef OUT_LAST_COMMIT_POSITION_H_ |
| 84 | + #define OUT_LAST_COMMIT_POSITION_H_ |
| 85 | +
|
| 86 | + #define LAST_COMMIT_POSITION_NUM 1942 |
| 87 | + #define LAST_COMMIT_POSITION "1942 (8926696)" |
| 88 | +
|
| 89 | + #endif // OUT_LAST_COMMIT_POSITION_H_ |
| 90 | + EOF |
| 91 | +
|
| 92 | + runHook postConfigure |
| 93 | + ''; |
| 94 | + }); |
| 95 | +in |
| 96 | +stdenv.mkDerivation rec { |
| 97 | + pname = "v8"; |
| 98 | + inherit version; |
| 99 | + |
| 100 | + doCheck = true; |
| 101 | + |
| 102 | + patches = [ |
| 103 | + ./darwin.patch |
| 104 | + |
| 105 | + # gcc-13 build fix for mixxign <cstdint> includes |
| 106 | + (fetchpatch { |
| 107 | + name = "gcc-13.patch"; |
| 108 | + url = "https://chromium.googlesource.com/v8/v8/+/c2792e58035fcbaa16d0cb70998852fbeb5df4cc^!?format=TEXT"; |
| 109 | + decode = "base64 -d"; |
| 110 | + hash = "sha256-hoPAkSaCmzXflPFXaKUwVPLECMpt6N6/8m8mBSTAHbU="; |
| 111 | + }) |
| 112 | + ]; |
| 113 | + |
| 114 | + src = v8Src; |
| 115 | + |
| 116 | + postUnpack = '' |
| 117 | + ${lib.concatStringsSep "\n" ( |
| 118 | + lib.mapAttrsToList (n: v: '' |
| 119 | + mkdir -p $sourceRoot/${n} |
| 120 | + cp -r ${v}/* $sourceRoot/${n} |
| 121 | + '') deps |
| 122 | + )} |
| 123 | + chmod u+w -R . |
| 124 | + ''; |
| 125 | + |
| 126 | + postPatch = '' |
| 127 | + ${lib.optionalString stdenv.hostPlatform.isAarch64 '' |
| 128 | + substituteInPlace build/toolchain/linux/BUILD.gn \ |
| 129 | + --replace 'toolprefix = "aarch64-linux-gnu-"' 'toolprefix = ""' |
| 130 | + ''} |
| 131 | + ${lib.optionalString stdenv.hostPlatform.isDarwin '' |
| 132 | + substituteInPlace build/config/compiler/compiler.gni \ |
| 133 | + --replace 'strip_absolute_paths_from_debug_symbols = true' \ |
| 134 | + 'strip_absolute_paths_from_debug_symbols = false' |
| 135 | + substituteInPlace build/config/compiler/BUILD.gn \ |
| 136 | + --replace 'current_toolchain == host_toolchain || !use_xcode_clang' \ |
| 137 | + 'false' |
| 138 | + ''} |
| 139 | + ${lib.optionalString stdenv.hostPlatform.isDarwin '' |
| 140 | + substituteInPlace build/config/compiler/BUILD.gn \ |
| 141 | + --replace "-Wl,-fatal_warnings" "" |
| 142 | + ''} |
| 143 | + touch build/config/gclient_args.gni |
| 144 | + sed '1i#include <utility>' -i src/heap/cppgc/prefinalizer-handler.h # gcc12 |
| 145 | + ''; |
| 146 | + |
| 147 | + llvmCcAndBintools = symlinkJoin { |
| 148 | + name = "llvmCcAndBintools"; |
| 149 | + paths = [ |
| 150 | + stdenv.cc |
| 151 | + llvmPackages.llvm |
| 152 | + ]; |
| 153 | + }; |
| 154 | + |
| 155 | + gnFlags = [ |
| 156 | + "use_custom_libcxx=false" |
| 157 | + "is_clang=${lib.boolToString stdenv.cc.isClang}" |
| 158 | + "use_sysroot=false" |
| 159 | + # "use_system_icu=true" |
| 160 | + "clang_use_chrome_plugins=false" |
| 161 | + "is_component_build=false" |
| 162 | + "v8_use_external_startup_data=false" |
| 163 | + "v8_monolithic=true" |
| 164 | + "is_debug=true" |
| 165 | + "is_official_build=false" |
| 166 | + "treat_warnings_as_errors=false" |
| 167 | + "v8_enable_i18n_support=true" |
| 168 | + "use_gold=false" |
| 169 | + # ''custom_toolchain="//build/toolchain/linux/unbundle:default"'' |
| 170 | + ''host_toolchain="//build/toolchain/linux/unbundle:default"'' |
| 171 | + ''v8_snapshot_toolchain="//build/toolchain/linux/unbundle:default"'' |
| 172 | + ] |
| 173 | + ++ lib.optional stdenv.cc.isClang ''clang_base_path="${llvmCcAndBintools}"'' |
| 174 | + ++ lib.optional stdenv.hostPlatform.isDarwin "use_lld=false"; |
| 175 | + |
| 176 | + env.NIX_CFLAGS_COMPILE = toString ( |
| 177 | + [ "-O2" ] ++ lib.optionals stdenv.cc.isClang [ "-Wno-error=enum-constexpr-conversion" ] |
| 178 | + ); |
| 179 | + FORCE_MAC_SDK_MIN = stdenv.hostPlatform.sdkVer or "10.12"; |
| 180 | + |
| 181 | + nativeBuildInputs = [ |
| 182 | + myGn |
| 183 | + ninja |
| 184 | + pkg-config |
| 185 | + python3 |
| 186 | + ] |
| 187 | + ++ lib.optionals stdenv.hostPlatform.isDarwin [ |
| 188 | + xcbuild |
| 189 | + llvmPackages.llvm |
| 190 | + python3.pkgs.setuptools |
| 191 | + ]; |
| 192 | + buildInputs = [ |
| 193 | + glib |
| 194 | + icu |
| 195 | + ]; |
| 196 | + |
| 197 | + ninjaFlags = [ |
| 198 | + ":d8" |
| 199 | + "v8_monolith" |
| 200 | + ]; |
| 201 | + |
| 202 | + enableParallelBuilding = true; |
| 203 | + |
| 204 | + installPhase = '' |
| 205 | + install -D d8 $out/bin/d8 |
| 206 | + install -D -m644 obj/libv8_monolith.a $out/lib/libv8.a |
| 207 | + install -D -m644 icudtl.dat $out/share/v8/icudtl.dat |
| 208 | + ln -s libv8.a $out/lib/libv8_monolith.a |
| 209 | + cp -r ../../include $out |
| 210 | +
|
| 211 | + mkdir -p $out/lib/pkgconfig |
| 212 | + cat > $out/lib/pkgconfig/v8.pc << EOF |
| 213 | + Name: v8 |
| 214 | + Description: V8 JavaScript Engine |
| 215 | + Version: ${version} |
| 216 | + Libs: -L$out/lib -lv8 -pthread |
| 217 | + Cflags: -I$out/include |
| 218 | + EOF |
| 219 | + ''; |
| 220 | + |
| 221 | + meta = with lib; { |
| 222 | + homepage = "https://v8.dev/"; |
| 223 | + description = "Google's open source JavaScript engine"; |
| 224 | + mainProgram = "d8"; |
| 225 | + maintainers = with maintainers; [ |
| 226 | + proglodyte |
| 227 | + matthewbauer |
| 228 | + ]; |
| 229 | + platforms = platforms.unix; |
| 230 | + license = licenses.bsd3; |
| 231 | + knownVulnerabilities = [ "Severely outdated with multiple publicly known vulnerabilities" ]; |
| 232 | + }; |
| 233 | +} |
0 commit comments