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