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