SPEC-3723: restructure meta-agl-demo
[AGL/meta-agl-demo.git] / recipes-wam / chromium / chromium68_git.bb
1 # Copyright (c) 2018 LG Electronics, Inc.
2
3 SUMMARY = "Chromium webruntime for webOS"
4 AUTHOR = "Lokesh Kumar Goel <lokeshkumar.goel@lge.com>"
5 SECTION = "webos/apps"
6 LICENSE = "Apache-2.0 & BSD-3-Clause & LGPL-2.0 & LGPL-2.1"
7 LIC_FILES_CHKSUM = "\
8     file://src/LICENSE;md5=0fca02217a5d49a14dfe2d11837bb34d \
9     file://src/third_party/blink/renderer/core/LICENSE-LGPL-2;md5=36357ffde2b64ae177b2494445b79d21 \
10     file://src/third_party/blink/renderer/core/LICENSE-LGPL-2.1;md5=a778a33ef338abbaf8b8a7c36b6eec80 \
11 "
12
13 require gn-utils.inc
14
15 inherit gettext qemu pythonnative
16
17 DEPENDS = "virtual/gettext wayland wayland-native pixman freetype glib-2.0 fontconfig openssl pango cairo icu libxkbcommon libexif dbus pciutils udev libcap alsa-lib virtual/egl elfutils-native libdrm atk gperf-native gconf nss nss-native nspr nspr-native bison-native qemu-native"
18
19 PROVIDES = "${BROWSER_APPLICATION}"
20
21 SRC_URI = "\
22     git://github.com/igalia/${BPN};branch=WIP@39.agl.compositor;protocol=https;rev=${SRCREV_chromium68};name=chromium68 \
23     git://github.com/webosose/v8;destsuffix=git/src/v8;rev=${SRCREV_v8};name=v8 \
24     file://v8-qemu-wrapper.patch \
25 "
26 SRCREV_chromium68 = "61e96d1ee5dfc2461697457d287bf922d8a03d9a"
27 SRCREV_v8 = "1e3af71f1ff3735e8a5b639c48dfca63a7b8a647"
28
29 # we don't include SRCPV in PV, so we have to manually include SRCREVs in do_fetch vardeps
30 do_fetch[vardeps] += "SRCREV_v8"
31 SRCREV_FORMAT = "main_v8"
32
33 S = "${WORKDIR}/git"
34
35 SRC_DIR = "${S}/src"
36 OUT_DIR = "${WORKDIR}/build"
37 BUILD_TYPE = "Release"
38
39 B = "${OUT_DIR}/${BUILD_TYPE}"
40
41 WEBRUNTIME_BUILD_TARGET = "webos:weboswebruntime"
42 BROWSER_APP_BUILD_TARGET = "chrome"
43 BROWSER_APPLICATION = "chromium68-browser"
44 BROWSER_APPLICATION_DIR = "/opt/chromium68"
45
46 TARGET = "${WEBRUNTIME_BUILD_TARGET} ${BROWSER_APP_BUILD_TARGET}"
47
48 # Skip do_install_append of webos_system_bus. It is not compatible with this component.
49 WEBOS_SYSTEM_BUS_FILES_LOCATION = "${S}/files/sysbus"
50
51 PACKAGECONFIG ?= "jumbo use-upstream-wayland"
52
53 # Options to enable debug-webcore build.
54 # Add the following line to local.conf (or local.dev.inc) to enable them:
55 #   PACKAGECONFIG_append_pn-chromium68 = " debug-webcore"
56 # Other debug options are controlled by sections later in this file
57 PACKAGECONFIG[debug-webcore] = "remove_webcore_debug_symbols=false,remove_webcore_debug_symbols=true"
58
59 # Set a default value for jumbo file merge of 8. This should be good for build
60 # servers and workstations with a big number of cores. In case build is
61 # happening in a machine with less cores but still enough RAM a good value could
62 # be 50.
63 JUMBO_FILE_MERGE_LIMIT="8"
64 PACKAGECONFIG[jumbo] = "use_jumbo_build=true jumbo_file_merge_limit=${JUMBO_FILE_MERGE_LIMIT}, use_jumbo_build=false"
65
66 PACKAGECONFIG[lttng] = "use_lttng=true,use_lttng=false,lttng-ust,lttng-tools lttng-modules babeltrace"
67
68 # Chromium can use v4l2 device for hardware accelerated video decoding on such boards as Renesas R-car M3, for example.
69 # In case of R-car m3, additional patches are required for gstreamer and v4l2apps.
70 # See https://github.com/igel-oss/meta-browser-hwdecode/tree/igalia-chromium71.
71 PACKAGECONFIG[use-linux-v4l2] = "use_v4l2_codec=true use_v4lplugin=true use_linux_v4l2_only=true"
72
73 PACKAGECONFIG[use-upstream-wayland] = " \
74         ozone_platform_wayland_external=false ozone_platform_wayland=true \
75         use_system_minigbm=true, \
76         ozone_platform_wayland_external=true ozone_platform_wayland=false \
77 "
78
79 GN_ARGS = "\
80     enable_memorymanager_webapi=false\
81     ffmpeg_branding=\"Chrome\"\
82     host_os=\"linux\"\
83     ozone_auto_platforms=false\
84     proprietary_codecs=true\
85     target_os=\"linux\"\
86     treat_warnings_as_errors=false\
87     is_agl=true\
88     use_cbe=true\
89     is_chrome_cbe=true\
90     use_cups=false\
91     use_custom_libcxx=false\
92     use_kerberos=false\
93     use_neva_media=false\
94     use_ozone=true\
95     use_xkbcommon=true\
96     use_pmlog=false\
97     use_system_debugger_abort=true\
98     use_webos_gpu_info_collector=false\
99     ${PACKAGECONFIG_CONFARGS}\
100 "
101
102 # From Chromium's BUILDCONFIG.gn:
103 # Set to enable the official build level of optimization. This has nothing
104 # to do with branding, but enables an additional level of optimization above
105 # release (!is_debug). This might be better expressed as a tri-state
106 # (debug, release, official) but for historical reasons there are two
107 # separate flags.
108 # See also: https://groups.google.com/a/chromium.org/d/msg/chromium-dev/hkcb6AOX5gE/PPT1ukWoBwAJ
109 GN_ARGS += "is_debug=false is_official_build=true"
110
111 # is_cfi default value is true for x86-64 builds with is_official_build=true.
112 # As of M63, we explicitly need to set it to false, otherwise we fail the
113 # following assertion in //build/config/sanitizers/sanitizers.gni:
114 #   assert(!is_cfi || is_clang,
115 #          "is_cfi requires setting is_clang = true in 'gn args'")
116 GN_ARGS += "is_cfi=false"
117
118 # By default, passing is_official_build=true to GN causes its symbol_level
119 # variable to be set to "2". This means the compiler will be passed "-g2" and
120 # we will end up with a very large chrome binary (around 5Gb as of M58)
121 # regardless of whether DEBUG_BUILD has been set or not. In addition, binutils,
122 # file and other utilities are unable to read a 32-bit binary this size, which
123 # causes it not to be stripped.
124 # The solution is two-fold:
125 # 1. Make sure -g is not passed on 32-bit architectures via DEBUG_FLAGS. -g is
126 #    the same as -g2. -g1 generates an 800MB binary, which is a lot more
127 #    manageable.
128 # 2. Explicitly pass symbol_level=0 to GN. This causes -g0 to be passed
129 #    instead, so that if DEBUG_BUILD is not set GN will not create a huge debug
130 #    binary anyway. Since our compiler flags are passed after GN's, -g0 does
131 #    not cause any issues if DEBUG_BUILD is set, as -g1 will be passed later.
132 DEBUG_FLAGS_remove_arm = "-g"
133 DEBUG_FLAGS_append_arm = "-g1"
134 DEBUG_FLAGS_remove_x86 = "-g"
135 DEBUG_FLAGS_append_x86 = "-g1"
136 GN_ARGS += "symbol_level=0"
137
138 # We do not want to use Chromium's own Debian-based sysroots, it is easier to
139 # just let Chromium's build system assume we are not using a sysroot at all and
140 # let Yocto handle everything.
141 GN_ARGS += "use_sysroot=false"
142
143 # Toolchains we will use for the build. We need to point to the toolchain file
144 # we've created, set the right target architecture and make sure we are not
145 # using Chromium's toolchain (bundled clang, bundled binutils etc).
146 GN_ARGS += "\
147         custom_toolchain=\"//build/toolchain/yocto:yocto_target\" \
148         gold_path=\"\" \
149         host_toolchain=\"//build/toolchain/yocto:yocto_native\" \
150         is_clang=${@is_default_cc_clang(d)} \
151         clang_base_path=\"${@clang_install_path(d)}\" \
152         clang_use_chrome_plugins=false \
153         linux_use_bundled_binutils=false \
154         target_cpu=\"${@gn_target_arch_name(d)}\" \
155         v8_snapshot_toolchain=\"//build/toolchain/yocto:yocto_target\" \
156 "
157
158 # ARM builds need special additional flags (see ${S}/build/config/arm.gni).
159 # If we do not pass |arm_arch| and friends to GN, it will deduce a value that
160 # will then conflict with TUNE_CCARGS and CC.
161 # Note that as of M61 in some corner cases parts of the build system disable
162 # the "compiler_arm_fpu" GN config, whereas -mfpu is always passed via ${CC}.
163 # We might want to rework that if there are issues in the future.
164 def get_compiler_flag(params, param_name, d):
165     """Given a sequence of compiler arguments in |params|, returns the value of
166     an option |param_name| or an empty string if the option is not present."""
167     for param in params:
168       if param.startswith(param_name):
169         return param.split('=')[1]
170     return ''
171
172 ARM_FLOAT_ABI = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hard', 'softfp', d)}"
173 ARM_FPU = "${@get_compiler_flag(d.getVar('TUNE_CCARGS').split(), '-mfpu', d)}"
174 ARM_TUNE = "${@get_compiler_flag(d.getVar('TUNE_CCARGS').split(), '-mcpu', d)}"
175 ARM_VERSION_aarch64 = "8"
176 ARM_VERSION_armv7a = "7"
177 ARM_VERSION_armv7ve = "7"
178 ARM_VERSION_armv6 = "6"
179
180 # GN computes and defaults to it automatically where needed
181 # forcing it from cmdline breaks build on places where it ends up
182 # overriding what GN wants
183 TUNE_CCARGS_remove = "-mthumb"
184
185 GN_ARGS_append_arm = " \
186         arm_float_abi=\"${ARM_FLOAT_ABI}\" \
187         arm_fpu=\"${ARM_FPU}\" \
188         arm_tune=\"${ARM_TUNE}\" \
189         arm_version=${ARM_VERSION} \
190 "
191 # tcmalloc's atomicops-internals-arm-v6plus.h uses the "dmb" instruction that
192 # is not available on (some?) ARMv6 models, which causes the build to fail.
193 GN_ARGS_append_armv6 += 'use_allocator="none"'
194 # The WebRTC code fails to build on ARMv6 when NEON is enabled.
195 # https://bugs.chromium.org/p/webrtc/issues/detail?id=6574
196 GN_ARGS_append_armv6 += 'arm_use_neon=false'
197
198 # Disable glibc shims on musl
199 # tcmalloc does not play well with musl as of M62 (and possibly earlier).
200 # https://github.com/gperftools/gperftools/issues/693
201 GN_ARGS_append_libc-musl = ' use_allocator_shim=false'
202
203 # V8's JIT infrastructure requires binaries such as mksnapshot and
204 # mkpeephole to be run in the host during the build. However, these
205 # binaries must have the same bit-width as the target (e.g. a x86_64
206 # host targeting ARMv6 needs to produce a 32-bit binary). Instead of
207 # depending on a third Yocto toolchain, we just build those binaries
208 # for the target and run them on the host with QEMU.
209 python do_create_v8_qemu_wrapper () {
210     """Creates a small wrapper that invokes QEMU to run some target V8 binaries
211     on the host."""
212     qemu_libdirs = [d.expand('${STAGING_DIR_HOST}${libdir}'),
213                     d.expand('${STAGING_DIR_HOST}${base_libdir}')]
214     qemu_cmd = qemu_wrapper_cmdline(d, d.getVar('STAGING_DIR_HOST', True),
215                                     qemu_libdirs)
216     wrapper_path = d.expand('${B}/v8-qemu-wrapper.sh')
217     with open(wrapper_path, 'w') as wrapper_file:
218         wrapper_file.write("""#!/bin/sh
219
220 # This file has been generated automatically.
221 # It invokes QEMU to run binaries built for the target in the host during the
222 # build process.
223
224 %s "$@"
225 """ % qemu_cmd)
226     os.chmod(wrapper_path, 0o755)
227 }
228 do_create_v8_qemu_wrapper[dirs] = "${B}"
229 addtask create_v8_qemu_wrapper after do_patch before do_configure
230
231 python do_write_toolchain_file () {
232     """Writes a BUILD.gn file for Yocto detailing its toolchains."""
233     toolchain_dir = d.expand("${S}/src/build/toolchain/yocto")
234     bb.utils.mkdirhier(toolchain_dir)
235     toolchain_file = os.path.join(toolchain_dir, "BUILD.gn")
236     write_toolchain_file(d, toolchain_file)
237 }
238 addtask write_toolchain_file after do_patch before do_configure
239
240 # More options to speed up the build
241 GN_ARGS += "\
242     enable_nacl=false\
243     disable_ftp_support=true\
244     enable_print_preview=false\
245     enable_remoting=false\
246     use_glib=true\
247     use_gnome_keyring=false\
248     use_pulseaudio=false\
249 "
250
251 # Respect ld-is-gold in DISTRO_FEATURES when enabling gold
252 # Similar patch applied in meta-browser
253 # http://patchwork.openembedded.org/patch/77755/
254 EXTRA_OEGN_GOLD = "${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-gold', 'use_gold=true', 'use_gold=false', d)}"
255 GN_ARGS += "${EXTRA_OEGN_GOLD}"
256
257 # Doesn't build for armv[45]*
258 COMPATIBLE_MACHINE = "(-)"
259 COMPATIBLE_MACHINE_aarch64 = "(.*)"
260 COMPATIBLE_MACHINE_armv6 = "(.*)"
261 COMPATIBLE_MACHINE_armv7a = "(.*)"
262 COMPATIBLE_MACHINE_armv7ve = "(.*)"
263 COMPATIBLE_MACHINE_x86 = "(.*)"
264 COMPATIBLE_MACHINE_x86-64 = "(.*)"
265
266 #CHROMIUM_PLUGINS_PATH = "${libdir}"
267 CBE_DATA_PATH = "${libdir}/cbe"
268 CBE_DATA_LOCALES_PATH = "${CBE_DATA_PATH}/locales"
269
270 # The text relocations are intentional -- see comments in [GF-52468]
271 # TODO: check if we need INSANE_SKIP on ldflags
272 INSANE_SKIP_${PN} = "textrel ldflags"
273
274
275 do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
276 do_compile() {
277     if [ ! -f ${OUT_DIR}/${BUILD_TYPE}/build.ninja ]; then
278          do_configure
279     fi
280
281     export PATH="${S}/depot_tools:$PATH"
282     ${S}/depot_tools/ninja -v -C ${OUT_DIR}/${BUILD_TYPE} ${TARGET}
283 }
284
285 do_configure() {
286     configure_env
287 }
288
289 configure_env() {
290     export GYP_CHROMIUM_NO_ACTION=1
291     export PATH="${S}/depot_tools:$PATH"
292
293     GN_ARGS="${GN_ARGS}"
294     echo GN_ARGS is ${GN_ARGS}
295     echo BUILD_TARGETS are ${TARGET}
296     cd ${SRC_DIR}
297     gn gen ${OUT_DIR}/${BUILD_TYPE} --args="${GN_ARGS}"
298 }
299
300 WINDOW_SIZE ?= "1920,1080"
301
302 configure_browser_settings() {
303     USER_AGENT="Mozilla/5.0 (Linux; NetCast; U) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/${CHROMIUM_VERSION} Safari/537.31"
304     echo "${USER_AGENT}" > ${D_DIR}/user_agent_conf
305     #We can replace below WINDOW_SIZE values from build configuration if available
306     #echo "${WINDOW_SIZE}" > ${D_DIR}/window_size_conf
307 }
308
309 install_chromium_browser() {
310     D_DIR=${D}${BROWSER_APPLICATION_DIR}
311     install -d ${D_DIR}
312
313     # Install browser files
314      if [ -e "${SRC_DIR}/webos/install" ]; then
315          cd ${OUT_DIR}/${BUILD_TYPE}
316          xargs --arg-file=${SRC_DIR}/webos/install/default_browser/binary.list cp -R --no-dereference --preserve=mode,links -v --target-directory=${D_DIR}
317          cd ${SRC_DIR}
318          xargs --arg-file=${SRC_DIR}/webos/install/default_browser/runtime.list cp -R --no-dereference --preserve=mode,links -v --target-directory=${D_DIR}
319      fi
320
321     # AGL does not have PMLOG
322     sed -i.bak s/PmLogCtl.*// ${D_DIR}/run_webbrowser
323
324     # To execute chromium in JAILER, Security Part needs permissions change
325     # run_webbrowser: Script file for launching chromium
326     chmod -v 755 ${D_DIR}/chrome
327     chmod -v 755 ${D_DIR}/kill_webbrowser
328     chmod -v 755 ${D_DIR}/run_webbrowser
329
330     configure_browser_settings
331 }
332
333 install_webruntime() {
334     install -d ${D}${libdir}
335     install -d ${D}${includedir}/${BPN}
336     install -d ${D}${CBE_DATA_PATH}
337     install -d ${D}${CBE_DATA_LOCALES_PATH}
338
339     # Install webos webview files
340     if [ -e "${SRC_DIR}/webos/install" ]; then
341         cd ${SRC_DIR}
342         xargs --arg-file=${SRC_DIR}/webos/install/weboswebruntime/staging_inc.list cp --parents --target-directory=${D}${includedir}/${BPN}
343
344         cd ${OUT_DIR}/${BUILD_TYPE}
345
346         cp libcbe.so ${D}${libdir}/
347         if [ "${WEBOS_LTTNG_ENABLED}" = "1" ]; then
348           # use bindir if building non-cbe
349           cp libchromium_lttng_provider.so ${D}${libdir}/
350         fi
351         xargs --arg-file=${SRC_DIR}/webos/install/weboswebruntime/binary.list cp --parents --target-directory=${D}${CBE_DATA_PATH}
352         cat ${SRC_DIR}/webos/install/weboswebruntime/data_locales.list | xargs -I{} install -m 755 -p {} ${D}${CBE_DATA_LOCALES_PATH}
353     fi
354
355     # move this to separate mksnapshot-cross recipe once we figure out how to build just cross mksnapshot from chromium repository
356     install -d ${D}${bindir_cross}
357     gzip -c ${OUT_DIR}/${BUILD_TYPE}/${MKSNAPSHOT_PATH}mksnapshot > ${D}${bindir_cross}/${HOST_SYS}-mksnapshot.gz
358 }
359
360 do_install() {
361     install_webruntime
362     install_chromium_browser
363 }
364
365 WEBOS_SYSTEM_BUS_DIRS_LEGACY_BROWSER_APPLICATION = " \
366     ${webos_sysbus_prvservicesdir}/${BROWSER_APPLICATION}.service \
367     ${webos_sysbus_pubservicesdir}/${BROWSER_APPLICATION}.service \
368     ${webos_sysbus_prvrolesdir}/${BROWSER_APPLICATION}.json \
369     ${webos_sysbus_pubrolesdir}/${BROWSER_APPLICATION}.json \
370 "
371
372 SYSROOT_DIRS_append = " ${bindir_cross}"
373
374 PACKAGES_prepend = " \
375     ${PN}-cross-mksnapshot \
376     ${BROWSER_APPLICATION} \
377 "
378
379 FILES_${BROWSER_APPLICATION} += " \
380     ${BROWSER_APPLICATION_DIR} \
381     ${WEBOS_SYSTEM_BUS_DIRS_LEGACY_BROWSER_APPLICATION} \
382 "
383
384 RDEPENDS_${BROWSER_APPLICATION} += "${PN}"
385
386 VIRTUAL-RUNTIME_gpu-libs ?= ""
387 RDEPENDS_${PN} += "${VIRTUAL-RUNTIME_gpu-libs}"
388
389 # The text relocations are intentional -- see comments in [GF-52468]
390 # TODO: check if we need INSANE_SKIP on ldflags
391 INSANE_SKIP_${BROWSER_APPLICATION} += "libdir ldflags textrel"
392
393 FILES_${PN} = " \
394     ${libdir}/*.so \
395     ${CBE_DATA_PATH}/* \
396     ${libdir}/${BPN}/*.so \
397     ${WEBOS_SYSTEM_BUS_DIRS} \
398 "
399
400 FILES_${PN}-dev = " \
401     ${includedir} \
402 "
403
404 FILES_${PN}-cross-mksnapshot = "${bindir_cross}/${HOST_SYS}-mksnapshot.gz"