python3Packages.orjson: Disable failing tests on 32 bit
[NixPkgs.git] / pkgs / development / libraries / v8 / default.nix
blobc3f04eae4ddfbdfdcbfeae7d4d8d2d2d161981b3
1 { stdenv, lib, fetchgit, fetchFromGitHub
2 , gn, ninja, python3, glib, pkg-config, icu
3 , xcbuild, darwin
4 , fetchpatch
5 , llvmPackages
6 , symlinkJoin
7 }:
9 # Use update.sh to update all checksums.
11 let
12   version = "9.7.106.18";
13   v8Src = fetchgit {
14     url = "https://chromium.googlesource.com/v8/v8";
15     rev = version;
16     sha256 = "0cb3w733w1xn6zq9dsr43nx6llcg9hrmb2dkxairarj9c0igpzyh";
17   };
19   git_url = "https://chromium.googlesource.com";
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   };
60   # See `gn_version` in DEPS.
61   gnSrc = fetchgit {
62     url = "https://gn.googlesource.com/gn";
63     rev = "8926696a4186279489cc2b8d768533e61bba73d7";
64     sha256 = "1084lnyb0a1khbgjvak05fcx6jy973wqvsf77n0alxjys18sg2yk";
65   };
67   myGn = gn.overrideAttrs (oldAttrs: {
68     version = "for-v8";
69     src = gnSrc;
70   });
74 stdenv.mkDerivation rec {
75   pname = "v8";
76   inherit version;
78   doCheck = true;
80   patches = [
81     ./darwin.patch
82   ];
84   src = v8Src;
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   '';
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     touch build/config/gclient_args.gni
109   '';
111   llvmCcAndBintools = symlinkJoin { name = "llvmCcAndBintools"; paths = [ stdenv.cc llvmPackages.llvm ]; };
113   gnFlags = [
114     "use_custom_libcxx=false"
115     "is_clang=${lib.boolToString stdenv.cc.isClang}"
116     "use_sysroot=false"
117     # "use_system_icu=true"
118     "clang_use_chrome_plugins=false"
119     "is_component_build=false"
120     "v8_use_external_startup_data=false"
121     "v8_monolithic=true"
122     "is_debug=true"
123     "is_official_build=false"
124     "treat_warnings_as_errors=false"
125     "v8_enable_i18n_support=true"
126     "use_gold=false"
127     # ''custom_toolchain="//build/toolchain/linux/unbundle:default"''
128     ''host_toolchain="//build/toolchain/linux/unbundle:default"''
129     ''v8_snapshot_toolchain="//build/toolchain/linux/unbundle:default"''
130   ] ++ lib.optional stdenv.cc.isClang ''clang_base_path="${llvmCcAndBintools}"''
131   ++ lib.optional stdenv.isDarwin ''use_lld=false'';
133   NIX_CFLAGS_COMPILE = "-O2";
134   FORCE_MAC_SDK_MIN = stdenv.targetPlatform.sdkVer or "10.12";
136   nativeBuildInputs = [
137     myGn
138     ninja
139     pkg-config
140     python3
141   ] ++ lib.optionals stdenv.isDarwin [
142     xcbuild
143     llvmPackages.llvm
144     python3.pkgs.setuptools
145   ];
146   buildInputs = [ glib icu ];
148   ninjaFlags = [ ":d8" "v8_monolith" ];
150   enableParallelBuilding = true;
152   installPhase = ''
153     install -D d8 $out/bin/d8
154     install -D -m644 obj/libv8_monolith.a $out/lib/libv8.a
155     install -D -m644 icudtl.dat $out/share/v8/icudtl.dat
156     ln -s libv8.a $out/lib/libv8_monolith.a
157     cp -r ../../include $out
159     mkdir -p $out/lib/pkgconfig
160     cat > $out/lib/pkgconfig/v8.pc << EOF
161     Name: v8
162     Description: V8 JavaScript Engine
163     Version: ${version}
164     Libs: -L$out/lib -lv8 -pthread
165     Cflags: -I$out/include
166     EOF
167   '';
169   meta = with lib; {
170     description = "Google's open source JavaScript engine";
171     maintainers = with maintainers; [ cstrahan proglodyte matthewbauer ];
172     platforms = platforms.unix;
173     license = licenses.bsd3;
174   };