move to Preview
[hiphop-php.git] / hhvm.nix
blob64410b415fb7d80029982f6eea4af2b2f725f039
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 , git
20 , glog
21 , gmp
22 , gperf
23 , gperftools
24 , hostPlatform
25 , icu
26 , imagemagick6
27 , jemalloc
28 , lastModifiedDate
29 , lib
30 , libcap
31 , libdwarf
32 , libedit
33 , libelf
34 , libevent
35 , libgccjit
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
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
123       brotli
124       bzip2
125       curl
126       double-conversion
127       editline
128       expat
129       fmt
130       freetype
131       fribidi
132       gd
133       gdb
134       gettext
135       git
136       glog
137       gmp
138       gperf
139       gperftools
140       icu
141       imagemagick6
142       jemalloc
143       libdwarf
144       libedit
145       libelf
146       libevent
147       libgccjit
148       libkrb5
149       libmcrypt
150       libmemcached
151       libpng
152       libsodium
153       libunwind
154       libvpx
155       libxml2
156       libxslt
157       libzip
158       lz4
159       oniguruma
160       openldap
161       openssl
162       pcre
163       perl
164       re2
165       re2c
166       sqlite
167       tbb
168       tzdata
169       unzip
170       zlib
171       zstd
172     ]
173     ++ lib.optionals hostPlatform.isLinux [
174       libcap
175       linux-pam
176       numactl
177       uwimap
178     ]
179     ++ lib.optionals hostPlatform.isMacOS [
180       darwin.apple_sdk.frameworks.CoreFoundation
181       darwin.apple_sdk.frameworks.CoreServices
182     ];
184   NIX_CFLAGS_COMPILE =
185     [
186       "-DFOLLY_MOBILE=0"
187     ]
188     ++ lib.optionals stdenv.cc.isClang [
189       # Workaround for dtoa.0.3.2
190       "-Wno-error=unused-command-line-argument"
191     ];
193   CMAKE_INIT_CACHE =
194     let
195       # Use writeTextDir instead of writeTextFile as a workaround of https://github.com/xtruder/nix-devcontainer/issues/9
196       dir = writeTextDir "init-cache.cmake"
197         ''
198           set(CAN_USE_SYSTEM_ZSTD ON CACHE BOOL "Use system zstd" FORCE)
199           set(HAVE_SYSTEM_TZDATA_PREFIX "${tzdata}/share/zoneinfo" CACHE PATH "The zoneinfo directory" FORCE)
200           set(HAVE_SYSTEM_TZDATA ON CACHE BOOL "Use system zoneinfo" FORCE)
201           set(MYSQL_UNIX_SOCK_ADDR "/run/mysqld/mysqld.sock" CACHE FILEPATH "The MySQL unix socket" FORCE)
202           set(CARGO_EXECUTABLE "${rustNightly.cargo}/bin/cargo" CACHE FILEPATH "The nightly cargo" FORCE)
203           set(RUSTC_EXECUTABLE "${rustNightly.rust}/bin/rustc" CACHE FILEPATH "The nightly rustc" FORCE)
204           ${
205             lib.optionalString hostPlatform.isMacOS ''
206               set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Targeting macOS version" FORCE)
207             ''
208           }
209         '';
210     in
211     dir + "/init-cache.cmake";
213   cmakeFlags = [ "-C" CMAKE_INIT_CACHE ];
215   prePatch = ''
216     patchShebangs .
217   '';
219   preBuild =
220     ''
221       set -e
222       make \
223         -f third-party/proxygen/CMakeFiles/bundled_proxygen.dir/build.make \
224         third-party/proxygen/bundled_proxygen-prefix/src/bundled_proxygen-stamp/bundled_proxygen-patch
225       patchShebangs \
226         third-party/proxygen/bundled_proxygen-prefix/src/bundled_proxygen
227     '';
229   doCheck = true;
231   checkPhase =
232     ''
233       set -ex
234       runHook preCheck
235       export HHVM_BIN="$PWD/hphp/hhvm/hhvm"
236       (cd ${./.} && "$HHVM_BIN" hphp/test/run.php quick)
237       runHook postCheck
238     '';
240   meta = {
241     description = "High-performance JIT compiler for PHP/Hack";
242     platforms = [
243       "x86_64-darwin"
244       "x86_64-linux"
245     ];
246     homepage = "https://hhvm.com";
247     license = [
248       lib.licenses.php301
249       {
250         spdxId = "Zend-2.0";
251         fullName = "Zend License v2.0";
252         url = "https://www.zend.com/sites/zend/files/pdfs/2_00.txt";
253       }
254     ];
255     maintainers = [{
256       email = "hhvm-oss@fb.com";
257       github = "hhvm";
258       githubId = 4553654;
259       name = "HHVM/Hack Open Source";
260     }];
261   };