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