Print unexpected exception
[hiphop-php.git] / hhvm.nix
blobe7dc79ba6d74d9be1ca21eeb5f105ac172f4c493
1 { bison
2 , boost
3 , brotli
4 , bzip2
5 , cacert
6 , cmake
7 , curl
8 , darwin
9 , double-conversion
10 , editline
11 , expat
12 , flex
13 , fmt_8
14 , freetype
15 , fribidi
16 , gcc-unwrapped
17 , gd
18 , gdb
19 , gettext
20 , gflags
21 , git
22 , glog
23 , gmp
24 , gperf
25 , gperftools
26 , hostPlatform
27 , icu
28 , imagemagick6
29 , jemalloc
30 , lastModifiedDate
31 , lib
32 , libcap
33 , libdwarf
34 , libedit
35 , libelf
36 , libevent
37 , libkrb5
38 , libmcrypt
39 , libmemcached
40 , libpng
41 , libsodium
42 , libunwind
43 , libvpx
44 , libxml2
45 , libxslt
46 , libzip
47 , linux-pam
48 , lz4
49 , numactl
50 , oniguruma
51 , openldap
52 , openssl_1_1
53 , pcre
54 , perl
55 , pkg-config
56 , python3
57 , re2
58 , re2c
59 , rustChannelOf
60 , stdenv
61 , sqlite
62 , tbb
63 , tzdata
64 , unixtools
65 , unzip
66 , uwimap
67 , which
68 , writeTextDir
69 , zlib
70 , zstd
72 let
73   # TODO(https://github.com/NixOS/nixpkgs/pull/193086): Use stdenv.cc.libcxx once it is available
74   isDefaultStdlib =
75     builtins.match ".*-stdlib=\+\+.*" (builtins.readFile "${stdenv.cc}/nix-support/libcxx-ldflags") == null;
76   versionParts =
77     builtins.match
78       ''
79         .*
80         #[[:blank:]]*define[[:blank:]]+HHVM_VERSION_MAJOR[[:blank:]]+([[:digit:]]+)
81         #[[:blank:]]*define[[:blank:]]+HHVM_VERSION_MINOR[[:blank:]]+([[:digit:]]+)
82         #[[:blank:]]*define[[:blank:]]+HHVM_VERSION_PATCH[[:blank:]]+([[:digit:]]+)
83         #[[:blank:]]*define[[:blank:]]+HHVM_VERSION_SUFFIX[[:blank:]]+"([^"]*)"
84         .*
85       ''
86       (builtins.readFile ./hphp/runtime/version.h);
87   makeVersion = major: minor: patch: suffix:
88     if suffix == "-dev" then "${major}.${minor}.${patch}-dev${lastModifiedDate}" else "${major}.${minor}.${patch}";
90   rustNightly = rustChannelOf {
92     # When the date attribute changes, sha256 should be updated accordingly.
93     #
94     # 1. Export your diff to GitHub;
95     # 2. Wait for an error message about sha256 mismatch from the GitHub
96     #    Actions;
97     # 3. Copy the new sha256 from the error message and paste it here;
98     # 4. Submit the diff and export the diff to GitHub, again.
99     # 5. Ensure no error message about sha256 mismatch from the GitHub Actions.
100     sha256 = "wVnIzrnpYGqiCBtc3k55tw4VW8YLA3WZY0mSac+2yl0=";
102     date = "2022-08-11";
103     channel = "nightly";
104   };
106 stdenv.mkDerivation rec {
107   pname = "hhvm";
108   version = builtins.foldl' lib.trivial.id makeVersion versionParts;
109   src = ./.;
110   nativeBuildInputs =
111     [
112       bison
113       cacert
114       cmake
115       flex
116       pkg-config
117       python3
118       unixtools.getconf
119       which
120     ] ++ lib.optionals hostPlatform.isMacOS [
121       # `system_cmds` provides `sysctl`, which is used in hphp/test/run.php on macOS
122       darwin.system_cmds
123     ];
124   buildInputs =
125     [
126       (if isDefaultStdlib then boost else boost.override { inherit stdenv; })
127       brotli
128       bzip2
129       (curl.override { openssl = openssl_1_1; })
130       (
131         if isDefaultStdlib then
132           double-conversion
133         else
134           double-conversion.override { inherit stdenv; }
135       )
136       editline
137       expat
138       (if isDefaultStdlib then fmt_8 else fmt_8.override { inherit stdenv; })
139       freetype
140       fribidi
141       # Workaround for https://github.com/NixOS/nixpkgs/issues/192665
142       gcc-unwrapped.lib
143       gd
144       gdb
145       gettext
146       git
147       (
148         if isDefaultStdlib then
149           glog
150         else
151           (glog.override {
152             inherit stdenv;
153             gflags = gflags.override { inherit stdenv; };
154           }).overrideAttrs
155             (finalAttrs: previousAttrs: {
156               # Workaround for https://github.com/google/glog/issues/709
157               doCheck = !stdenv.cc.isClang;
158             })
159       )
160       gmp
161       (if isDefaultStdlib then gperf else gperf.override { inherit stdenv; })
162       (
163         if isDefaultStdlib then
164           gperftools
165         else
166           gperftools.override { inherit stdenv; }
167       )
168       (if isDefaultStdlib then icu else icu.override { inherit stdenv; })
169       imagemagick6
170       jemalloc
171       libdwarf
172       libedit
173       libelf
174       libevent
175       libkrb5
176       libmcrypt
177       libmemcached
178       libpng
179       libsodium
180       libunwind
181       libvpx
182       libxml2
183       libxslt
184       libzip
185       lz4
186       oniguruma
187       openldap
188       openssl_1_1
189       pcre
190       perl
191       re2
192       re2c
193       sqlite
194       (if isDefaultStdlib then tbb else tbb.override { inherit stdenv; })
195       tzdata
196       unzip
197       zlib
198       zstd
199     ]
200     ++ lib.optionals hostPlatform.isLinux [
201       libcap
202       linux-pam
203       numactl
204       uwimap
205     ]
206     ++ lib.optionals hostPlatform.isMacOS [
207       darwin.apple_sdk.frameworks.CoreFoundation
208       darwin.apple_sdk.frameworks.CoreServices
209     ];
211   NIX_CFLAGS_COMPILE =
212     lib.optionals stdenv.cc.isClang [
213       # Workaround for dtoa.0.3.2
214       "-Wno-error=unused-command-line-argument"
215     ];
217   CMAKE_INIT_CACHE =
218     let
219       # Use writeTextDir instead of writeTextFile as a workaround of https://github.com/xtruder/nix-devcontainer/issues/9
220       dir = writeTextDir "init-cache.cmake"
221         ''
222           set(ENABLE_SYSTEM_LOCALE_ARCHIVE ON CACHE BOOL "Use system locale archive as the default LOCALE_ARCHIVE for nix patched glibc" FORCE)
223           set(CAN_USE_SYSTEM_ZSTD ON CACHE BOOL "Use system zstd" FORCE)
224           set(HAVE_SYSTEM_TZDATA_PREFIX "${tzdata}/share/zoneinfo" CACHE PATH "The zoneinfo directory" FORCE)
225           set(HAVE_SYSTEM_TZDATA ON CACHE BOOL "Use system zoneinfo" FORCE)
226           set(MYSQL_UNIX_SOCK_ADDR "/run/mysqld/mysqld.sock" CACHE FILEPATH "The MySQL unix socket" FORCE)
227           set(CARGO_EXECUTABLE "${rustNightly.cargo}/bin/cargo" CACHE FILEPATH "The nightly cargo" FORCE)
228           set(RUSTC_EXECUTABLE "${rustNightly.rust}/bin/rustc" CACHE FILEPATH "The nightly rustc" FORCE)
229           ${
230             lib.optionalString hostPlatform.isMacOS ''
231               set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Targeting macOS version" FORCE)
232             ''
233           }
234         '';
235     in
236     dir + "/init-cache.cmake";
238   cmakeFlags = [ "-C" CMAKE_INIT_CACHE ];
240   prePatch = ''
241     patchShebangs .
242   '';
244   preBuild =
245     ''
246       set -e
247       make \
248         -f third-party/proxygen/CMakeFiles/bundled_proxygen.dir/build.make \
249         third-party/proxygen/bundled_proxygen-prefix/src/bundled_proxygen-stamp/bundled_proxygen-patch
250       patchShebangs \
251         third-party/proxygen/bundled_proxygen-prefix/src/bundled_proxygen
252     '';
254   doCheck = true;
256   checkPhase =
257     ''
258       set -e
259       runHook preCheck
260       export HHVM_BIN="$PWD/hphp/hhvm/hhvm"
261       (cd ${./.} && "$HHVM_BIN" hphp/test/run.php quick)
262       runHook postCheck
263     '';
265   meta = {
266     description = "High-performance JIT compiler for PHP/Hack";
267     platforms = [
268       "x86_64-darwin"
269       "x86_64-linux"
270     ];
271     homepage = "https://hhvm.com";
272     license = [
273       lib.licenses.php301
274       {
275         spdxId = "Zend-2.0";
276         fullName = "Zend License v2.0";
277         url = "https://www.zend.com/sites/zend/files/pdfs/2_00.txt";
278       }
279     ];
280     maintainers = [{
281       email = "hhvm-oss@fb.com";
282       github = "hhvm";
283       githubId = 4553654;
284       name = "HHVM/Hack Open Source";
285     }];
286   };