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