Convert to new override syntax
[AGL/meta-agl-demo.git] / recipes-wam / chromium / chromium.inc
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 at-spi2-atk gperf-native gconf nss nss-native nspr nspr-native bison-native qemu-native"
18
19 PROVIDES = "${BROWSER_APPLICATION}"
20
21 SRCREV_v8 = "1e3af71f1ff3735e8a5b639c48dfca63a7b8a647"
22
23 # we don't include SRCPV in PV, so we have to manually include SRCREVs in do_fetch vardeps
24 do_fetch[vardeps] += "SRCREV_v8"
25 SRCREV_FORMAT = "main_v8"
26
27 S = "${WORKDIR}/git"
28
29 SRC_DIR = "${S}/src"
30 BUILD_TYPE = "Release"
31
32 B = "${WORKDIR}/build"
33 OUT_DIR = "${B}/${BUILD_TYPE}"
34
35 WEBRUNTIME_BUILD_TARGET = "webos:weboswebruntime"
36 BROWSER_APP_BUILD_TARGET = "chrome"
37 BROWSER_APPLICATION = "chromium84-browser"
38 BROWSER_APPLICATION_DIR = "/opt/chromium84"
39
40 TARGET = "${WEBRUNTIME_BUILD_TARGET} ${BROWSER_APP_BUILD_TARGET}"
41
42 # Skip do_install:append of webos_system_bus. It is not compatible with this component.
43 WEBOS_SYSTEM_BUS_FILES_LOCATION = "${S}/files/sysbus"
44
45 PACKAGECONFIG ?= "jumbo use-upstream-wayland"
46
47
48 # Set a default value for jumbo file merge of 8. This should be good for build
49 # servers and workstations with a big number of cores. In case build is
50 # happening in a machine with less cores but still enough RAM a good value could
51 # be 50.
52 JUMBO_FILE_MERGE_LIMIT="8"
53 PACKAGECONFIG[jumbo] = "use_jumbo_build=true jumbo_file_merge_limit=${JUMBO_FILE_MERGE_LIMIT}, use_jumbo_build=false"
54
55 PACKAGECONFIG[lttng] = "use_lttng=true,use_lttng=false,lttng-ust,lttng-tools lttng-modules babeltrace"
56
57 # Chromium can use v4l2 device for hardware accelerated video decoding on such boards as Renesas R-car M3, for example.
58 # In case of R-car m3, additional patches are required for gstreamer and v4l2apps.
59 # See https://github.com/igel-oss/meta-browser-hwdecode/tree/igalia-chromium71.
60 PACKAGECONFIG[use-linux-v4l2] = "use_v4l2_codec=true use_v4lplugin=true use_linux_v4l2_only=true"
61
62 PACKAGECONFIG[use-upstream-wayland] = " \
63     ozone_platform_wayland_external=false ozone_platform_wayland=true, \
64     ozone_platform_wayland_external=true ozone_platform_wayland=false \
65 "
66
67 GN_ARGS = "\
68     enable_memorymanager_webapi=false\
69     ffmpeg_branding=\"Chrome\"\
70     host_os=\"linux\"\
71     ozone_auto_platforms=false\
72     proprietary_codecs=true\
73     target_os=\"linux\"\
74     treat_warnings_as_errors=false\
75     is_agl=true\
76     use_cbe=true\
77     is_chrome_cbe=true\
78     is_component_build=false\
79     use_cups=false\
80     use_custom_libcxx=false\
81     use_kerberos=false\
82     use_neva_media=false\
83     use_ozone=true\
84     use_xkbcommon=true\
85     use_wayland_gbm=false\
86     use_pmlog=false\
87     use_system_debugger_abort=true\
88     ${PACKAGECONFIG_CONFARGS}\
89 "
90
91 # From Chromium's BUILDCONFIG.gn:
92 # Set to enable the official build level of optimization. This has nothing
93 # to do with branding, but enables an additional level of optimization above
94 # release (!is_debug). This might be better expressed as a tri-state
95 # (debug, release, official) but for historical reasons there are two
96 # separate flags.
97 # See also: https://groups.google.com/a/chromium.org/d/msg/chromium-dev/hkcb6AOX5gE/PPT1ukWoBwAJ
98 GN_ARGS += "is_debug=false is_official_build=true"
99
100 # is_cfi default value is true for x86-64 builds with is_official_build=true.
101 # As of M63, we explicitly need to set it to false, otherwise we fail the
102 # following assertion in //build/config/sanitizers/sanitizers.gni:
103 #   assert(!is_cfi || is_clang,
104 #          "is_cfi requires setting is_clang = true in 'gn args'")
105 GN_ARGS += "is_cfi=false"
106
107 # By default, passing is_official_build=true to GN causes its symbol_level
108 # variable to be set to "2". This means the compiler will be passed "-g2" and
109 # we will end up with a very large chrome binary (around 5Gb as of M58)
110 # regardless of whether DEBUG_BUILD has been set or not. In addition, binutils,
111 # file and other utilities are unable to read a 32-bit binary this size, which
112 # causes it not to be stripped.
113 # The solution is two-fold:
114 # 1. Make sure -g is not passed on 32-bit architectures via DEBUG_FLAGS. -g is
115 #    the same as -g2. -g1 generates an 800MB binary, which is a lot more
116 #    manageable.
117 # 2. Explicitly pass symbol_level=0 to GN. This causes -g0 to be passed
118 #    instead, so that if DEBUG_BUILD is not set GN will not create a huge debug
119 #    binary anyway. Since our compiler flags are passed after GN's, -g0 does
120 #    not cause any issues if DEBUG_BUILD is set, as -g1 will be passed later.
121 DEBUG_FLAGS:remove:arm = "-g"
122 DEBUG_FLAGS:append:arm = "-g1"
123 DEBUG_FLAGS:remove:x86 = "-g"
124 DEBUG_FLAGS:append:x86 = "-g1"
125 GN_ARGS += "symbol_level=0"
126
127 # We do not want to use Chromium's own Debian-based sysroots, it is easier to
128 # just let Chromium's build system assume we are not using a sysroot at all and
129 # let Yocto handle everything.
130 GN_ARGS += "use_sysroot=false"
131
132 # ARM builds need special additional flags (see ${S}/build/config/arm.gni).
133 # If we do not pass |arm_arch| and friends to GN, it will deduce a value that
134 # will then conflict with TUNE_CCARGS and CC.
135 # Note that as of M61 in some corner cases parts of the build system disable
136 # the "compiler_arm_fpu" GN config, whereas -mfpu is always passed via ${CC}.
137 # We might want to rework that if there are issues in the future.
138 def get_compiler_flag(params, param_name, d):
139     """Given a sequence of compiler arguments in |params|, returns the value of
140     an option |param_name| or an empty string if the option is not present."""
141     for param in params:
142       if param.startswith(param_name):
143         return param.split('=')[1]
144     return ''
145
146 ARM_FLOAT_ABI = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hard', 'softfp', d)}"
147 ARM_FPU = "${@get_compiler_flag(d.getVar('TUNE_CCARGS').split(), '-mfpu', d)}"
148 ARM_TUNE = "${@get_compiler_flag(d.getVar('TUNE_CCARGS').split(), '-mcpu', d)}"
149 ARM_VERSION:aarch64 = "8"
150 ARM_VERSION:armv7a = "7"
151 ARM_VERSION:armv7ve = "7"
152 ARM_VERSION:armv6 = "6"
153
154 # GN computes and defaults to it automatically where needed
155 # forcing it from cmdline breaks build on places where it ends up
156 # overriding what GN wants
157 TUNE_CCARGS:remove = "-mthumb"
158
159 GN_ARGS:append:arm = " \
160         arm_float_abi=\"${ARM_FLOAT_ABI}\" \
161         arm_fpu=\"${ARM_FPU}\" \
162         arm_tune=\"${ARM_TUNE}\" \
163         arm_version=${ARM_VERSION} \
164 "
165 # tcmalloc's atomicops-internals-arm-v6plus.h uses the "dmb" instruction that
166 # is not available on (some?) ARMv6 models, which causes the build to fail.
167 GN_ARGS:append:armv6 += 'use_allocator="none"'
168 # The WebRTC code fails to build on ARMv6 when NEON is enabled.
169 # https://bugs.chromium.org/p/webrtc/issues/detail?id=6574
170 GN_ARGS:append:armv6 += 'arm_use_neon=false'
171
172 # Disable glibc shims on musl
173 # tcmalloc does not play well with musl as of M62 (and possibly earlier).
174 # https://github.com/gperftools/gperftools/issues/693
175 GN_ARGS:append:libc-musl = ' use_allocator_shim=false'
176
177 # More options to speed up the build
178 GN_ARGS += "\
179     enable_nacl=false\
180     disable_ftp_support=true\
181     enable_print_preview=false\
182     enable_remoting=false\
183     use_glib=true\
184     use_gnome_keyring=false\
185     use_pulseaudio=false\
186 "
187
188 # Doesn't build for armv[45]*
189 COMPATIBLE_MACHINE = "(-)"
190 COMPATIBLE_MACHINE:aarch64 = "(.*)"
191 COMPATIBLE_MACHINE:armv6 = "(.*)"
192 COMPATIBLE_MACHINE:armv7a = "(.*)"
193 COMPATIBLE_MACHINE:armv7ve = "(.*)"
194 COMPATIBLE_MACHINE:x86 = "(.*)"
195 COMPATIBLE_MACHINE:x86-64 = "(.*)"
196
197 #CHROMIUM_PLUGINS_PATH = "${libdir}"
198 CBE_DATA_PATH = "${libdir}/cbe"
199 CBE_DATA_LOCALES_PATH = "${CBE_DATA_PATH}/locales"
200
201 # The text relocations are intentional -- see comments in [GF-52468]
202 # TODO: check if we need INSANE_SKIP on ldflags
203 INSANE_SKIP:${PN} = "textrel ldflags"
204
205
206 do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
207 do_compile() {
208     if [ ! -f ${OUT_DIR}/build.ninja ]; then
209          do_configure
210     fi
211
212     export PATH="${S}/depot_tools:$PATH"
213     ${S}/depot_tools/ninja ${PARALLEL_MAKE} -v -C ${OUT_DIR} ${TARGET}
214 }
215
216 do_configure() {
217     configure_env
218 }
219
220 configure_env() {
221     export GYP_CHROMIUM_NO_ACTION=1
222     export PATH="${S}/depot_tools:$PATH"
223
224     GN_ARGS="${GN_ARGS}"
225     echo GN_ARGS is ${GN_ARGS}
226     echo BUILD_TARGETS are ${TARGET}
227     cd ${SRC_DIR}
228     gn gen ${OUT_DIR} --args="${GN_ARGS}"
229 }
230
231 WINDOW_SIZE ?= "1920,1080"
232
233 configure_browser_settings() {
234     USER_AGENT="Mozilla/5.0 (Linux; NetCast; U) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/${CHROMIUM_VERSION} Safari/537.31"
235     echo "${USER_AGENT}" > ${D_DIR}/user_agent_conf
236     #We can replace below WINDOW_SIZE values from build configuration if available
237     #echo "${WINDOW_SIZE}" > ${D_DIR}/window_size_conf
238 }
239
240 install_chromium_browser() {
241     # Install browser files
242     ${S}/depot_tools/ninja ${PARALLEL_MAKE} -C ${OUT_DIR} webos/install/default_browser
243
244     D_DIR=${D}${BROWSER_APPLICATION_DIR}
245     L_DIR=${D}${CBE_DATA_PATH}
246     install -d ${D_DIR}
247     install -d ${L_DIR}
248
249     cp -R --no-dereference --preserve=mode,links -v ${OUT_DIR}/image/${BROWSER_APPLICATION_DIR}/* ${D_DIR}
250
251     # AGL does not have PMLOG
252     sed -i.bak s/PmLogCtl.*// ${D_DIR}/run_webbrowser
253
254     # To execute chromium in JAILER, Security Part needs permissions change
255     # run_webbrowser: Script file for launching chromium
256     chmod -v 755 ${D_DIR}/chrome
257     chmod -v 755 ${D_DIR}/kill_webbrowser
258     chmod -v 755 ${D_DIR}/run_webbrowser
259
260     configure_browser_settings
261 }
262
263 install_webruntime() {
264
265     # # Generate install webos webview files
266     # ${S}/depot_tools/ninja ${PARALLEL_MAKE} -C ${OUT_DIR} webos/install/weboswebruntime
267
268     # # Move installation files to D directory
269     # mv ${OUT_DIR}/image/* ${D}
270     # # Rename include and locale directories
271     # mv ${D}${includedir}/webruntime ${D}${includedir}/${BPN}
272     # mv ${D}${CBE_DATA_PATH}/neva_locales ${D}${CBE_DATA_LOCALES_PATH}
273
274     # # move this to separate mksnapshot-cross recipe once we figure out how to build just cross mksnapshot from chromium repository
275     # install -d ${D}${bindir_cross}
276     # gzip -c ${OUT_DIR}/${MKSNAPSHOT_PATH}mksnapshot > ${D}${bindir_cross}/${HOST_SYS}-mksnapshot.gz
277
278     install -d ${D}${libdir}
279     install -d ${D}${libdir}/swiftshader
280     install -d ${D}${includedir}/${BPN}
281     install -d ${D}${CBE_DATA_PATH}
282     install -d ${D}${CBE_DATA_LOCALES_PATH}
283
284     # Install webos webview files
285     ${S}/depot_tools/ninja ${PARALLEL_MAKE} -C ${OUT_DIR} webos/install/weboswebruntime
286
287     install -v -m 0644 ${OUT_DIR}/swiftshader/*.so ${D}${libdir}/swiftshader
288
289     cp -R --no-dereference --preserve=mode,links -v ${OUT_DIR}/image/${includedir}/${BPN}/* ${D}${includedir}/${BPN}/
290     install -v -m 0644 ${OUT_DIR}/image/${libdir}/*.so ${D}${libdir}
291
292     install -v -m 0644 ${OUT_DIR}/image/${CBE_DATA_PATH}/icudtl.dat ${D}${CBE_DATA_PATH}
293     install -v -m 0644 ${OUT_DIR}/image/${CBE_DATA_PATH}/snapshot_blob.bin ${D}${CBE_DATA_PATH}
294     # app_runtime_content.pak, webos_content.pak, extensions_shell_and_test.pak
295     install -v -m 0644 ${OUT_DIR}/image/${CBE_DATA_PATH}/*.pak ${D}${CBE_DATA_PATH}
296
297     cp -R --no-dereference --preserve=mode,links -v ${OUT_DIR}/image/${CBE_DATA_LOCALES_PATH}/*.pak ${D}${CBE_DATA_LOCALES_PATH}
298
299     chown root:root -R ${D}${libdir}
300     chown root:root -R ${D}${includedir}
301     chown root:root -R ${D}${CBE_DATA_LOCALES_PATH}
302
303     # move this to separate mksnapshot-cross recipe once we figure out how to build just cross mksnapshot from chromium repository
304     install -d ${D}${base_bindir}
305     gzip -c ${OUT_DIR}/${MKSNAPSHOT_PATH}mksnapshot > ${D}${base_bindir}/${HOST_SYS}-mksnapshot.gz
306
307 }
308
309 do_install() {
310     install_webruntime
311     install_chromium_browser
312 }
313
314 WEBOS_SYSTEM_BUS_DIRS_LEGACY_BROWSER_APPLICATION = " \
315     ${webos_sysbus_prvservicesdir}/${BROWSER_APPLICATION}.service \
316     ${webos_sysbus_pubservicesdir}/${BROWSER_APPLICATION}.service \
317     ${webos_sysbus_prvrolesdir}/${BROWSER_APPLICATION}.json \
318     ${webos_sysbus_pubrolesdir}/${BROWSER_APPLICATION}.json \
319 "
320
321 SYSROOT_DIRS:append = " ${bindir_cross}"
322
323 PACKAGES:prepend = " \
324     ${PN}-cross-mksnapshot \
325     ${BROWSER_APPLICATION} \
326 "
327
328 FILES:${BROWSER_APPLICATION} += " \
329     ${BROWSER_APPLICATION_DIR} \
330     ${WEBOS_SYSTEM_BUS_DIRS_LEGACY_BROWSER_APPLICATION} \
331 "
332
333 RDEPENDS:${BROWSER_APPLICATION} += "${PN}"
334
335 VIRTUAL-RUNTIME_gpu-libs ?= ""
336 RDEPENDS:${PN} += "${VIRTUAL-RUNTIME_gpu-libs}"
337
338 # The text relocations are intentional -- see comments in [GF-52468]
339 # TODO: check if we need INSANE_SKIP on ldflags
340 INSANE_SKIP:${BROWSER_APPLICATION} += "libdir ldflags textrel"
341
342 FILES:${PN} = " \
343     ${libdir}/*.so \
344     ${libdir}/swiftshader/*.so \
345     ${CBE_DATA_PATH}/* \
346     ${libdir}/${BPN}/*.so \
347     ${WEBOS_SYSTEM_BUS_DIRS} \
348 "
349
350 FILES:${PN}-dev = " \
351     ${includedir} \
352 "
353
354 FILES:${PN}-cross-mksnapshot = "${bindir_cross}/${HOST_SYS}-mksnapshot.gz"