[wam][cef] Add the CEF recipe
[AGL/meta-agl-demo.git] / recipes-wam / cef / cef_git.bb
1 require gn-utils.inc
2
3 LICENSE = "Apache-2.0 & BSD-3-Clause & LGPL-2.0-only & LGPL-2.1-only"
4
5 LIC_FILES_CHKSUM = "\
6     file://LICENSE;md5=c408a301e3407c3803499ce9290515d6 \
7     file://third_party/blink/renderer/core/LICENSE-LGPL-2;md5=36357ffde2b64ae177b2494445b79d21 \
8     file://third_party/blink/renderer/core/LICENSE-LGPL-2.1;md5=a778a33ef338abbaf8b8a7c36b6eec80 \
9 "
10 CHROMIUM_URL = "github.com/rogerzanoni/chromium108.git"
11 CHROMIUM_VERSION = "108.0.5359.125"
12 BRANCH_chromium108 = "5359"
13 # Taken from https://bitbucket.org/chromiumembedded/cef/src/5615/CHROMIUM_BUILD_COMPATIBILITY.txt
14 SRCREV_chromium108 = "fe6cbc05f1ec805339364b0df0e8be925a991a80"
15 SRCREV_cef = "a98cd4cdc0fdc49b6c38ba10cec800922745441e"
16 GN_TARGET_CPU = "${@gn_arch_name('${TUNE_ARCH}')}"
17
18 PV = "${CHROMIUM_VERSION}.${BRANCH_chromium108}+git"
19
20 FILESEXTRAPATHS:prepend := "${THISDIR}/files/cef:"
21 FILESEXTRAPATHS:prepend := "${THISDIR}/files/chromium:"
22
23 SRC_URI = "\
24     git://${CHROMIUM_URL};branch=${BRANCH_chromium108};protocol=https;rev=${SRCREV_chromium108};name=chromium108;destsuffix=git/chromium/src \
25     file://0001-sql-relax-constraints-on-VirtualCursor-layout.patch \
26     file://0002-Don-t-look-for-depot_tools-in-chrommium-s-third_part.patch \
27     file://0003-Remove-the-GN-settings-done-for-clang-that-conflict-.patch \
28     file://0004-Don-t-use-DRI-for-renesas.patch \
29     file://0005-Add-the-essential-parts-of-wayland-extensions-and-ag.patch \
30     file://0006-Add-webos-agl-waylandwindow-window-tree-host-essenti.patch \
31     file://0007-Only-bind-to-agl_shell-if-it-s-the-browser-process.patch \
32     file://0008-Add-a-method-to-check-if-the-agl-window-is-configure.patch \
33     file://0009-Start-using-agl-shell-version-4.patch \
34     \
35     git://bitbucket.org/chromiumembedded/cef.git;branch=${BRANCH_chromium108};protocol=https;rev=${SRCREV_cef};name=cef;destsuffix=git/chromium/src/cef \
36     file://0001-Add-an-option-to-use-an-output-directory-outside-src.patch;patchdir=cef \
37     file://0002-Add-an-option-to-override-the-default-distrib-direct.patch;patchdir=cef \
38     file://0003-Add-an-option-to-use-an-alternative-base-output-dire.patch;patchdir=cef \
39     file://0004-Add-an-option-to-bypass-sysroot-checking-and-force.patch;patchdir=cef \
40     file://0005-Linux-Fix-build-without-X11-fixes-issue-3431.patch;patchdir=cef \
41     file://0006-Add-AGL-wayland-window-related-calls.patch;patchdir=cef \
42     file://0007-Add-a-method-to-check-if-the-agl-window-is-configure.patch;patchdir=cef \
43     file://0008-Add-the-SetActivateRegion-method.patch;patchdir=cef \
44     file://0009-Allow-passing-the-app_id-on-widget-creation.patch;patchdir=cef \
45     file://0010-Update-generated-api-wrapper-files.patch;patchdir=cef \
46 "
47
48 BASE_DIR = "${WORKDIR}/git/chromium"
49 CHROMIUM_DIR = "${BASE_DIR}/src"
50 CEF_DIR = "${CHROMIUM_DIR}/cef"
51 DEPOT_TOOLS_DIR="${STAGING_DIR_NATIVE}${datadir}/depot_tools"
52 S = "${BASE_DIR}/src"
53 B = "${WORKDIR}/build"
54
55 OUT_PATH = "${B}/out/Release_GN_${GN_TARGET_CPU}"
56 DIST_PATH = "${OUT_PATH}/dist/cef-minimal_${GN_TARGET_CPU}"
57 CEF_DATA_PATH = "${datadir}/cef"
58
59 DEPENDS:append = " curl clang-native gperf-native wayland dbus libcxx compiler-rt libxkbcommon nss nss-native atk at-spi2-atk libdrm pango cairo virtual/egl qemu-native pciutils glib-2.0 pkgconfig-native pulseaudio"
60
61 do_sync[depends] += "depot-tools-wam-native:do_populate_sysroot"
62 do_configure[depends] += "depot-tools-wam-native:do_populate_sysroot"
63 do_compile[depends] += "depot-tools-wam-native:do_populate_sysroot"
64
65 DOWNLOAD_PGO_PROFILES="False"
66
67 # Adapted from CEF's tools/gclient_hooks.py
68 python do_gclient_config() {
69   import os
70   # Create gclient configuration file.
71   gclient_file = os.path.join(d.expand('${BASE_DIR}'), '.gclient')
72   # Exclude unnecessary directories. Intentionally written without newlines.
73   gclient_spec = \
74       "solutions = [{"+\
75         "'managed': False,"+\
76         "'name': 'src', "+\
77         "'url': '" + d.expand('https://${CHROMIUM_URL}') + "', "+\
78         "'custom_vars': {"+\
79           d.expand("'checkout_pgo_profiles': '${DOWNLOAD_PGO_PROFILES}'") +\
80         "}, "+\
81         "'custom_deps': {"+\
82           "'build': None, "+\
83           "'build/scripts/command_wrapper/bin': None, "+\
84           "'build/scripts/gsd_generate_index': None, "+\
85           "'build/scripts/private/data/reliability': None, "+\
86           "'build/scripts/tools/deps2git': None, "+\
87           "'build/third_party/lighttpd': None, "+\
88           "'commit-queue': None, "+\
89           "'depot_tools': None, "+\
90           "'src/chrome_frame/tools/test/reference_build/chrome': None, "+\
91           "'src/chrome/tools/test/reference_build/chrome_linux': None, "+\
92           "'src/chrome/tools/test/reference_build/chrome_mac': None, "+\
93           "'src/chrome/tools/test/reference_build/chrome_win': None, "+\
94         "}, "+\
95         "'deps_file': 'DEPS', "+\
96         "'safesync_url': ''"+\
97       "}]"
98
99   with open(gclient_file, 'w+', encoding='utf-8') as fp:
100     fp.write(gclient_spec)
101 }
102 addtask do_gclient_config after do_unpack before do_configure
103
104 # Mostly adapted from CEF's tools/automate/automate-git.py
105 do_sync[network] = "1"
106 python do_sync() {
107   import os
108   def cef_run(command_line, working_dir):
109     import subprocess
110     env = os.environ
111     env['PATH'] = d.expand("${DEPOT_TOOLS_DIR}") + os.pathsep + env['PATH']
112     env['DEPOT_TOOLS_UPDATE'] = "0"
113     env['GCLIENT_PY3'] = "1"
114
115     subprocess.check_output(command_line.split(),
116                             cwd=working_dir,
117                             env=env,
118                             shell=False,
119                             stderr=subprocess.STDOUT)
120
121   def cef_apply_patch(name, patches_path=os.path.join(d.expand("${CEF_DIR}"), 'patch', 'patches')):
122     patch_file = os.path.join(patches_path, name)
123     if not os.path.exists(patch_file + ".patch"):
124       # Attempt to apply the patch file.
125       patch_tool = os.path.join(d.expand("${CEF_DIR}"), 'tools', 'patcher.py')
126       cef_run('%s %s --patch-file "%s" --patch-dir "%s"' %
127               ("python3", patch_tool, patch_file, d.expand("${CHROMIUM_DIR}")),
128               d.expand("${CHROMIUM_DIR}"))
129
130   def cef_apply_deps_patch():
131     """ Patch the Chromium DEPS file before `gclient sync` if necessary. """
132     deps_path = os.path.join(d.expand("${CHROMIUM_DIR}"), 'DEPS')
133     if os.path.isfile(deps_path):
134       cef_apply_patch('DEPS')
135     else:
136       raise Exception("Path does not exist: DEPS")
137
138   def cef_apply_runhooks_patch():
139     """ Patch the Chromium runhooks files before `gclient runhooks` if necessary. """
140     cef_apply_patch('runhooks')
141
142   # CEF automation script usually applies
143   # applies patches before running sync and
144   # runhooks. This is taken directly from the
145   # automation script
146   def cef_do_sync():
147     cef_apply_deps_patch()
148     cef_run("gclient sync --reset --nohooks --jobs 16", d.expand("${CHROMIUM_DIR}"))
149     cef_apply_runhooks_patch()
150     cef_run("gclient runhooks --jobs 16", d.expand("${CHROMIUM_DIR}"))
151
152   cef_do_sync()
153 }
154 addtask do_sync after do_gclient_config before do_configure
155
156 # gn defaults from CEF wiki, except for use_sysroot
157 GN_DEFINES = "use_sysroot=false \
158               symbol_level=0 \
159               is_cfi=false \
160               use_thin_lto=false \
161 "
162
163 # Disable GTK and prevent cef from
164 # building its gtk demos
165 GN_DEFINES:append = " \
166               use_gtk=false \
167               cef_use_gtk=false \
168 "
169
170 GN_DEFINES:append = " \
171               treat_warnings_as_errors=false \
172               is_component_build=false \
173               use_cups=false \
174               use_kerberos=false \
175               use_ozone=true \
176               use_xkbcommon=true \
177               use_wayland_gbm=true \
178               use_gnome_keyring=false \
179               enable_remoting=false \
180 "
181
182 # ozone options
183 GN_DEFINES:append = " \
184               use_ozone=true \
185               ozone_auto_platforms=false \
186               ozone_platform_headless=true \
187               ozone_platform_wayland=true \
188               ozone_platform_x11=false \
189               use_system_minigbm=true \
190               use_system_libdrm=true \
191               use_system_libwayland=true \
192 "
193
194 GN_DEFINES:append = " \
195               dcheck_always_on=false \
196               is_debug=false \
197               is_official_build=false \
198 "
199
200 GN_DEFINES:append = " \
201               use_egl=true \
202               use_glib=true \
203               use_dri=false \
204 "
205
206 # Disable PGO optimizations
207 GN_DEFINES:append = " chrome_pgo_phase=0 "
208
209 RUNTIME = "llvm"
210 TOOLCHAIN = "clang"
211 TOOLCHAIN:class-native = "clang"
212
213 BUILD_AR:toolchain-clang = "llvm-ar"
214 BUILD_CC:toolchain-clang = "clang"
215 BUILD_CXX:toolchain-clang = "clang++"
216 BUILD_LD:toolchain-clang = "clang"
217
218 COMPATIBLE_MACHINE = "(-)"
219 COMPATIBLE_MACHINE:aarch64 = "(.*)"
220 COMPATIBLE_MACHINE:armv6 = "(.*)"
221 COMPATIBLE_MACHINE:armv7a = "(.*)"
222 COMPATIBLE_MACHINE:armv7ve = "(.*)"
223 COMPATIBLE_MACHINE:x86 = "(.*)"
224 COMPATIBLE_MACHINE:x86-64 = "(.*)"
225
226 GN_DEFINES:append = ' \
227               use_lld=true \
228               use_gold=false \
229               gold_path="" \
230               is_clang=true \
231               clang_use_chrome_plugins=false \
232               clang_base_path="${STAGING_BINDIR_NATIVE}" \
233               host_toolchain=\"//build/toolchain/cros:host\" \
234               use_custom_libcxx_for_host=false \
235               cros_host_ar=\"${BUILD_AR}\" \
236               cros_host_cc=\"${BUILD_CC}\" \
237               cros_host_cxx=\"${BUILD_CXX}\" \
238               cros_host_ld=\"${BUILD_CXX}\" \
239               cros_host_extra_cppflags=\"${BUILD_CPPFLAGS}\" \
240               cros_host_extra_cxxflags=\"${BUILD_CXXFLAGS}\" \
241               cros_host_extra_ldflags=\"${BUILD_LDFLAGS}\" \
242               custom_toolchain=\"//build/toolchain/cros:target\" \
243               use_custom_libcxx=false \
244               target_cpu=\"${GN_TARGET_CPU}\" \
245               cros_target_ar=\"${AR}\" \
246               cros_target_cc=\"${CC}\" \
247               cros_target_cxx=\"${CXX}\" \
248               cros_target_ld=\"${CXX}\" \
249               cros_target_extra_cppflags=\"${CPPFLAGS}\" \
250               cros_target_extra_cxxflags=\"${CXXFLAGS}\" \
251               cros_target_extra_ldflags=\"${LDFLAGS}\" \
252               v8_snapshot_toolchain=\"//build/toolchain/cros:v8_snapshot\" \
253               cros_v8_snapshot_ar=\"${BUILD_AR}\" \
254               cros_v8_snapshot_cc=\"${BUILD_CC}\" \
255               cros_v8_snapshot_cxx=\"${BUILD_CXX}\" \
256               cros_v8_snapshot_cppflags=\"${CPPFLAGS}\" \
257               cros_v8_snapshot_cxxflags=\"${CXXFLAGS}\" \
258               cros_v8_snapshot_ldflags=\"${LDFLAGS}\" \
259               use_v8_context_snapshot=false \
260 '
261
262 PACKAGECONFIG ??= "upower use-egl"
263 PACKAGECONFIG[use-egl] = ",,virtual/egl virtual/libgles2"
264 PACKAGECONFIG[upower] = ",,,upower"
265
266 GN_DEFINES:append = ' \
267               ${PACKAGECONFIG_CONFARGS} \
268 '
269
270 do_configure () {
271     bbnote "do_configure:"
272     bbnote "Base out path: ${B}"
273
274     export DEPOT_TOOLS_UPDATE=0
275     export GCLIENT_PY3=1
276     export PATH="${DEPOT_TOOLS_DIR}:$PATH"
277     export GN_DEFINES="${GN_DEFINES}"
278
279     cd ${S}/cef
280     python3 tools/gclient_hook.py --base-out-path ${B} --bypass-sysroot-check
281 }
282
283 do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
284 do_compile () {
285     if [ ! -f ${OUT_PATH}/build.ninja ]; then
286          do_configure
287     fi
288
289     export PATH="${DEPOT_TOOLS_DIR}:$PATH"
290     export PATH="$PATH:${S}/third_party/ninja"
291     ninja ${PARALLEL_MAKE} -C ${OUT_PATH} libcef chrome_sandbox
292 }
293
294 do_install () {
295     cd ${S}/cef
296     python3 tools/make_distrib.py --output-dir ${OUT_PATH}/dist \
297                                   --dist-path-name cef-minimal \
298                                   --base-out-path ${B} \
299                                   --no-docs \
300                                   --no-symbols \
301                                   --no-archive \
302                                   --ninja-build \
303                                   --minimal \
304                                   --${GN_TARGET_CPU}-build \
305                                   --ozone
306
307     install -d ${D}${CEF_DATA_PATH}
308
309     cp -R --no-dereference --preserve=mode,links -v ${DIST_PATH}/* ${D}${CEF_DATA_PATH}
310     # TODO(rzanoni): Follow the wiki instructions to install the sandbox
311 }
312
313 # TODO: fix QA issues, libraries in the wrong location
314 FILES:${PN} += " \
315     ${CEF_DATA_PATH} \
316 "
317
318 INSANE_SKIP:${PN} += "libdir"
319
320 PROVIDES:${PN} += "cef"