Connect schematizer
[hiphop-php.git] / hhvm.nix
blobc52f708caa384afc1042081680908cd7d691add0
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_20210528
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 , writeTextFile
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_20210528
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_TOOLCHAIN_FILE = writeTextFile {
218     name = "toolchain.cmake";
219     text = ''
220       set(ENABLE_SYSTEM_LOCALE_ARCHIVE ON CACHE BOOL "Use system locale archive as the default LOCALE_ARCHIVE for nix patched glibc" FORCE)
221       set(CAN_USE_SYSTEM_ZSTD ON CACHE BOOL "Use system zstd" FORCE)
222       set(HAVE_SYSTEM_TZDATA_PREFIX "${tzdata}/share/zoneinfo" CACHE PATH "The zoneinfo directory" FORCE)
223       set(HAVE_SYSTEM_TZDATA ON CACHE BOOL "Use system zoneinfo" FORCE)
224       set(MYSQL_UNIX_SOCK_ADDR "/run/mysqld/mysqld.sock" CACHE FILEPATH "The MySQL unix socket" FORCE)
225       set(CARGO_EXECUTABLE "${rustNightly.cargo}/bin/cargo" CACHE FILEPATH "The nightly cargo" FORCE)
226       set(RUSTC_EXECUTABLE "${rustNightly.rust}/bin/rustc" CACHE FILEPATH "The nightly rustc" FORCE)
227       set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "Enable verbose output from Makefile builds" FORCE)
228       ${
229         lib.optionalString hostPlatform.isMacOS ''
230           set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Targeting macOS version" FORCE)
231         ''
232       }
233     '';
234   };
236   prePatch = ''
237     patchShebangs .
238   '';
240   preBuild =
241     ''
242       set -e
243       make \
244         -f third-party/proxygen/CMakeFiles/bundled_proxygen.dir/build.make \
245         third-party/proxygen/bundled_proxygen-prefix/src/bundled_proxygen-stamp/bundled_proxygen-patch
246       patchShebangs \
247         third-party/proxygen/bundled_proxygen-prefix/src/bundled_proxygen
248     '';
250   doCheck = true;
252   checkPhase =
253     ''
254       set -e
255       runHook preCheck
256       export HHVM_BIN="$PWD/hphp/hhvm/hhvm"
257       (cd ${./.} && "$HHVM_BIN" hphp/test/run.php quick)
258       runHook postCheck
259     '';
261   meta = {
262     description = "High-performance JIT compiler for PHP/Hack";
263     platforms = [
264       "x86_64-darwin"
265       "x86_64-linux"
266     ];
267     homepage = "https://hhvm.com";
268     license = [
269       lib.licenses.php301
270       {
271         spdxId = "Zend-2.0";
272         fullName = "Zend License v2.0";
273         url = "https://www.zend.com/sites/zend/files/pdfs/2_00.txt";
274       }
275     ];
276     maintainers = [{
277       email = "hhvm-oss@fb.com";
278       github = "hhvm";
279       githubId = 4553654;
280       name = "HHVM/Hack Open Source";
281     }];
282   };