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