1{
2 fetchFromGitHub,
3 fetchurl,
4 fetchzip,
5 stdenv,
6 cmake,
7 python3,
8 jdk,
9 git,
10 rsync,
11 lib,
12 ant,
13 ninja,
14 strip-nondeterminism,
15 stripJavaArchivesHook,
16
17 debugBuild ? false,
18
19 glib,
20 nss,
21 nspr,
22 atk,
23 at-spi2-atk,
24 libdrm,
25 libGL,
26 expat,
27 libxcb,
28 libxkbcommon,
29 libX11,
30 libXcomposite,
31 libXdamage,
32 libXext,
33 libXfixes,
34 libXrandr,
35 libgbm,
36 gtk3,
37 pango,
38 cairo,
39 alsa-lib,
40 dbus,
41 at-spi2-core,
42 cups,
43 libxshmfence,
44 udev,
45 boost,
46 thrift,
47}:
48
49let
50 rpath = lib.makeLibraryPath [
51 glib
52 nss
53 nspr
54 atk
55 at-spi2-atk
56 libdrm
57 libGL
58 expat
59 libxcb
60 libxkbcommon
61 libX11
62 libXcomposite
63 libXdamage
64 libXext
65 libXfixes
66 libXrandr
67 libgbm
68 gtk3
69 pango
70 cairo
71 alsa-lib
72 dbus
73 at-spi2-core
74 cups
75 libxshmfence
76 udev
77 ];
78
79 buildType = if debugBuild then "Debug" else "Release";
80 platform =
81 {
82 "aarch64-linux" = "linuxarm64";
83 "x86_64-linux" = "linux64";
84 }
85 .${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
86 arches =
87 {
88 "linuxarm64" = {
89 depsArch = "arm64";
90 projectArch = "arm64";
91 targetArch = "arm64";
92 };
93 "linux64" = {
94 depsArch = "amd64";
95 projectArch = "x86_64";
96 targetArch = "x86_64";
97 };
98 }
99 .${platform};
100 inherit (arches) depsArch projectArch targetArch;
101
102in
103stdenv.mkDerivation rec {
104 pname = "jcef-jetbrains";
105 rev = "7a7b9383b3bf39c850feb0d103c6b829e2f48a6b";
106 # This is the commit number
107 # Currently from the branch: https://github.com/JetBrains/jcef/tree/251
108 # Run `git rev-list --count HEAD`
109 version = "1014";
110
111 nativeBuildInputs = [
112 cmake
113 python3
114 jdk
115 git
116 rsync
117 ant
118 ninja
119 strip-nondeterminism
120 stripJavaArchivesHook
121 ];
122 buildInputs = [
123 boost
124 libX11
125 libXdamage
126 nss
127 nspr
128 thrift
129 ];
130
131 src = fetchFromGitHub {
132 owner = "jetbrains";
133 repo = "jcef";
134 inherit rev;
135 hash = "sha256-ZMxx5mwmsBiUneULHFUDOrJQ8yKuK9bfPz89vN31ql4=";
136 };
137 cef-bin =
138 let
139 # `cef_binary_${CEF_VERSION}_linux64_minimal`, where CEF_VERSION is from $src/CMakeLists.txt
140 name = "cef_binary_122.1.9+gd14e051+chromium-122.0.6261.94_${platform}_minimal";
141 hash =
142 {
143 "linuxarm64" = "sha256-wABtvz0JHitlkkB748I7yr02Oxs5lXvqDfrBAQiKWHU=";
144 "linux64" = "sha256-qlutM0IsE1emcMe/3p7kwMIK7ou1rZGvpUkrSMVPnCc=";
145 }
146 .${platform};
147 urlName = builtins.replaceStrings [ "+" ] [ "%2B" ] name;
148 in
149 fetchzip {
150 url = "https://cef-builds.spotifycdn.com/${urlName}.tar.bz2";
151 inherit name hash;
152 };
153 # Find the hash in tools/buildtools/linux64/clang-format.sha1
154 clang-fmt = fetchurl {
155 url = "https://storage.googleapis.com/chromium-clang-format/dd736afb28430c9782750fc0fd5f0ed497399263";
156 hash = "sha256-4H6FVO9jdZtxH40CSfS+4VESAHgYgYxfCBFSMHdT0hE=";
157 };
158
159 configurePhase = ''
160 runHook preConfigure
161
162 patchShebangs .
163
164 cp -r ${cef-bin} third_party/cef/${cef-bin.name}
165 chmod +w -R third_party/cef/${cef-bin.name}
166 patchelf third_party/cef/${cef-bin.name}/${buildType}/libcef.so --set-rpath "${rpath}" --add-needed libudev.so
167 patchelf third_party/cef/${cef-bin.name}/${buildType}/libGLESv2.so --set-rpath "${rpath}" --add-needed libGL.so.1
168 patchelf third_party/cef/${cef-bin.name}/${buildType}/chrome-sandbox --set-interpreter $(cat $NIX_BINTOOLS/nix-support/dynamic-linker)
169 sed 's/-O0/-O2/' -i third_party/cef/${cef-bin.name}/cmake/cef_variables.cmake
170
171 sed \
172 -e 's|os.path.isdir(os.path.join(path, \x27.git\x27))|True|' \
173 -e 's|"%s rev-parse %s" % (git_exe, branch)|"echo '${rev}'"|' \
174 -e 's|"%s config --get remote.origin.url" % git_exe|"echo 'https://github.com/jetbrains/jcef'"|' \
175 -e 's|"%s rev-list --count %s" % (git_exe, branch)|"echo '${version}'"|' \
176 -i tools/git_util.py
177
178 cp ${clang-fmt} tools/buildtools/linux64/clang-format
179 chmod +w tools/buildtools/linux64/clang-format
180
181 sed \
182 -e 's|include(cmake/vcpkg.cmake)||' \
183 -e 's|bring_vcpkg()||' \
184 -e 's|vcpkg_install_package(boost-filesystem boost-interprocess thrift)||' \
185 -i CMakeLists.txt
186
187 sed -e 's|vcpkg_bring_host_thrift()|set(THRIFT_COMPILER_HOST ${thrift}/bin/thrift)|' -i remote/CMakeLists.txt
188
189 mkdir jcef_build
190 cd jcef_build
191
192 cmake -G "Ninja" -DPROJECT_ARCH="${projectArch}" -DCMAKE_BUILD_TYPE=${buildType} ..
193
194 runHook postConfigure
195 '';
196
197 outputs = [
198 "out"
199 "unpacked"
200 ];
201
202 postBuild = ''
203 export JCEF_ROOT_DIR=$(realpath ..)
204 ../tools/compile.sh ${platform} Release
205 '';
206
207 # N.B. For new versions, manually synchronize the following
208 # definitions with jb/tools/common/create_modules.sh to include
209 # newly added modules
210 installPhase = ''
211 runHook preInstall
212
213 export JCEF_ROOT_DIR=$(realpath ..)
214 export OUT_NATIVE_DIR=$JCEF_ROOT_DIR/jcef_build/native/${buildType}
215 export JB_TOOLS_DIR=$(realpath ../jb/tools)
216 export JB_TOOLS_OS_DIR=$JB_TOOLS_DIR/linux
217 export OUT_CLS_DIR=$(realpath ../out/${platform})
218 export TARGET_ARCH=${targetArch} DEPS_ARCH=${depsArch}
219 export OS=linux
220 export JOGAMP_DIR="$JCEF_ROOT_DIR"/third_party/jogamp/jar
221
222 mkdir -p $unpacked/{jogl,gluegen,jcef}
223
224 function extract_jar {
225 __jar=$1
226 __dst_dir=$2
227 __content_dir="''${3:-.}"
228 __tmp=.tmp_extract_jar
229 rm -rf "$__tmp" && mkdir "$__tmp"
230 (
231 cd "$__tmp" || exit 1
232 jar -xf "$__jar"
233 )
234 rm -rf "$__tmp/META-INF"
235 rm -rf "$__dst_dir" && mkdir "$__dst_dir"
236 if [ -z "$__content_dir" ]
237 then
238 cp -R "$__tmp"/* "$__dst_dir"
239 else
240 cp -R "$__tmp"/"$__content_dir"/* "$__dst_dir"
241 fi
242 rm -rf $__tmp
243 }
244
245 cd $unpacked/gluegen
246 cp "$JOGAMP_DIR"/gluegen-rt.jar .
247 cp "$JB_TOOLS_DIR"/common/gluegen-module-info.java module-info.java
248 javac --patch-module gluegen.rt=gluegen-rt.jar module-info.java
249 jar uf gluegen-rt.jar module-info.class
250 rm module-info.class module-info.java
251 mkdir lib
252 ''
253 # see https://github.com/JetBrains/jcef/commit/f3b787e3326c1915d663abded7f055c0866f32ec
254 + lib.optionalString (platform != "linuxarm64") ''
255 extract_jar "$JOGAMP_DIR"/gluegen-rt-natives-"$OS"-"$DEPS_ARCH".jar lib natives/"$OS"-"$DEPS_ARCH"
256 ''
257 + ''
258
259 cd ../jogl
260 cp "$JOGAMP_DIR"/gluegen-rt.jar .
261 cp "$JOGAMP_DIR"/jogl-all.jar .
262 cp "$JB_TOOLS_OS_DIR"/jogl-module-info.java module-info.java
263 javac --module-path . --patch-module jogl.all=jogl-all.jar module-info.java
264 jar uf jogl-all.jar module-info.class
265 rm module-info.class module-info.java
266 mkdir lib
267 ''
268 # see https://github.com/JetBrains/jcef/commit/f3b787e3326c1915d663abded7f055c0866f32ec
269 + lib.optionalString (platform != "linuxarm64") ''
270 extract_jar "$JOGAMP_DIR"/jogl-all-natives-"$OS"-"$DEPS_ARCH".jar lib natives/"$OS"-"$DEPS_ARCH"
271 ''
272 + ''
273
274 cd ../jcef
275 cp "$OUT_CLS_DIR"/jcef.jar .
276 mkdir lib
277 cp -R "$OUT_NATIVE_DIR"/* lib
278
279 mkdir -p $out/jmods
280
281 bash "$JB_TOOLS_DIR"/common/create_version_file.sh $out
282
283 runHook postInstall
284 '';
285
286 dontStrip = debugBuild;
287
288 postFixup = ''
289 cd $unpacked/gluegen
290 jmod create --class-path gluegen-rt.jar --libs lib $out/jmods/gluegen.rt.jmod
291 cd ../jogl
292 jmod create --module-path . --class-path jogl-all.jar --libs lib $out/jmods/jogl.all.jmod
293 cd ../jcef
294 jmod create --module-path . --class-path jcef.jar --libs lib $out/jmods/jcef.jmod
295
296 # stripJavaArchivesHook gets rid of jar file timestamps, but not of jmod file timestamps
297 # We have to manually call strip-nondeterminism to do this for jmod files too
298 find $out -name "*.jmod" -exec strip-nondeterminism --type jmod {} +
299 '';
300
301 meta = {
302 description = "Jetbrains' fork of JCEF";
303 license = lib.licenses.bsd3;
304 homepage = "https://github.com/JetBrains/JCEF";
305 platforms = [
306 "aarch64-linux"
307 "x86_64-linux"
308 ];
309 };
310}