c6bc949ac02fbce686d8c510c5c1cb050959996b
[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 # Options to enable debug build. Add this PACKAGECONFIG to local.conf
68 # to enable debug build. By default debug is completely disabled to
69 # speed up build
70 PACKAGECONFIG[debug] = "symbol_level=2 use_debug_fission=true,symbol_level=1"
71 PACKAGECONFIG[debug-blink] = "blink_symbol_level=2 use_debug_fission=true,blink_symbol_level=1"
72
73 GN_ARGS = "\
74     enable_memorymanager_webapi=false\
75     ffmpeg_branding=\"Chrome\"\
76     host_os=\"linux\"\
77     ozone_auto_platforms=false\
78     proprietary_codecs=true\
79     target_os=\"linux\"\
80     treat_warnings_as_errors=false\
81     is_agl=true\
82     use_cbe=true\
83     is_chrome_cbe=true\
84     is_component_build=false\
85     use_cups=false\
86     use_custom_libcxx=false\
87     use_kerberos=false\
88     use_neva_media=false\
89     use_ozone=true\
90     use_xkbcommon=true\
91     use_wayland_gbm=false\
92     use_pmlog=false\
93     use_system_debugger_abort=true\
94     ${PACKAGECONFIG_CONFARGS}\
95 "
96
97 # From Chromium's BUILDCONFIG.gn:
98 # Set to enable the official build level of optimization. This has nothing
99 # to do with branding, but enables an additional level of optimization above
100 # release (!is_debug). This might be better expressed as a tri-state
101 # (debug, release, official) but for historical reasons there are two
102 # separate flags.
103 # See also: https://groups.google.com/a/chromium.org/d/msg/chromium-dev/hkcb6AOX5gE/PPT1ukWoBwAJ
104 GN_ARGS += "is_debug=false is_official_build=true"
105
106 # is_cfi default value is true for x86-64 builds with is_official_build=true.
107 # As of M63, we explicitly need to set it to false, otherwise we fail the
108 # following assertion in //build/config/sanitizers/sanitizers.gni:
109 #   assert(!is_cfi || is_clang,
110 #          "is_cfi requires setting is_clang = true in 'gn args'")
111 GN_ARGS += "is_cfi=false"
112
113 # We do not want to use Chromium's own Debian-based sysroots, it is easier to
114 # just let Chromium's build system assume we are not using a sysroot at all and
115 # let Yocto handle everything.
116 GN_ARGS += "use_sysroot=false"
117
118 # ARM builds need special additional flags (see ${S}/build/config/arm.gni).
119 # If we do not pass |arm_arch| and friends to GN, it will deduce a value that
120 # will then conflict with TUNE_CCARGS and CC.
121 # Note that as of M61 in some corner cases parts of the build system disable
122 # the "compiler_arm_fpu" GN config, whereas -mfpu is always passed via ${CC}.
123 # We might want to rework that if there are issues in the future.
124 def get_compiler_flag(params, param_name, d):
125     """Given a sequence of compiler arguments in |params|, returns the value of
126     an option |param_name| or an empty string if the option is not present."""
127     for param in params:
128       if param.startswith(param_name):
129         return param.split('=')[1]
130     return ''
131
132 ARM_FLOAT_ABI = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hard', 'softfp', d)}"
133 ARM_FPU = "${@get_compiler_flag(d.getVar('TUNE_CCARGS').split(), '-mfpu', d)}"
134 ARM_TUNE = "${@get_compiler_flag(d.getVar('TUNE_CCARGS').split(), '-mcpu', d)}"
135 ARM_VERSION:aarch64 = "8"
136 ARM_VERSION:armv7a = "7"
137 ARM_VERSION:armv7ve = "7"
138 ARM_VERSION:armv6 = "6"
139
140 # GN computes and defaults to it automatically where needed
141 # forcing it from cmdline breaks build on places where it ends up
142 # overriding what GN wants
143 TUNE_CCARGS:remove = "-mthumb"
144
145 GN_ARGS:append:arm = " \
146         arm_float_abi=\"${ARM_FLOAT_ABI}\" \
147         arm_fpu=\"${ARM_FPU}\" \
148         arm_tune=\"${ARM_TUNE}\" \
149         arm_version=${ARM_VERSION} \
150 "
151 # tcmalloc's atomicops-internals-arm-v6plus.h uses the "dmb" instruction that
152 # is not available on (some?) ARMv6 models, which causes the build to fail.
153 GN_ARGS:append:armv6 = ' use_allocator="none"'
154 # The WebRTC code fails to build on ARMv6 when NEON is enabled.
155 # https://bugs.chromium.org/p/webrtc/issues/detail?id=6574
156 GN_ARGS:append:armv6 = ' arm_use_neon=false'
157
158 # Disable glibc shims on musl
159 # tcmalloc does not play well with musl as of M62 (and possibly earlier).
160 # https://github.com/gperftools/gperftools/issues/693
161 GN_ARGS:append:libc-musl = ' use_allocator_shim=false'
162
163 # More options to speed up the build
164 GN_ARGS += "\
165     enable_nacl=false\
166     disable_ftp_support=true\
167     enable_print_preview=false\
168     enable_remoting=false\
169     use_glib=true\
170     use_gnome_keyring=false\
171     use_pulseaudio=false\
172 "
173
174 # Doesn't build for armv[45]*
175 COMPATIBLE_MACHINE = "(-)"
176 COMPATIBLE_MACHINE:aarch64 = "(.*)"
177 COMPATIBLE_MACHINE:armv6 = "(.*)"
178 COMPATIBLE_MACHINE:armv7a = "(.*)"
179 COMPATIBLE_MACHINE:armv7ve = "(.*)"
180 COMPATIBLE_MACHINE:x86 = "(.*)"
181 COMPATIBLE_MACHINE:x86-64 = "(.*)"
182
183 #CHROMIUM_PLUGINS_PATH = "${libdir}"
184 CBE_DATA_PATH = "${libdir}/cbe"
185 CBE_DATA_LOCALES_PATH = "${CBE_DATA_PATH}/locales"
186
187 # The text relocations are intentional -- see comments in [GF-52468]
188 # TODO: check if we need INSANE_SKIP on ldflags
189 INSANE_SKIP:${PN} = "textrel ldflags"
190
191
192 do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
193 do_compile() {
194     if [ ! -f ${OUT_DIR}/build.ninja ]; then
195          do_configure
196     fi
197
198     export PATH="${S}/depot_tools:$PATH"
199     ${S}/depot_tools/ninja ${PARALLEL_MAKE} -v -C ${OUT_DIR} ${TARGET}
200 }
201
202 do_configure() {
203     configure_env
204 }
205
206 configure_env() {
207     export GYP_CHROMIUM_NO_ACTION=1
208     export PATH="${S}/depot_tools:$PATH"
209
210     GN_ARGS="${GN_ARGS}"
211     echo GN_ARGS is ${GN_ARGS}
212     echo BUILD_TARGETS are ${TARGET}
213     cd ${SRC_DIR}
214     gn gen ${OUT_DIR} --args="${GN_ARGS}"
215 }
216
217 WINDOW_SIZE ?= "1920,1080"
218
219 configure_browser_settings() {
220     USER_AGENT="Mozilla/5.0 (Linux; NetCast; U) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/${CHROMIUM_VERSION} Safari/537.31"
221     echo "${USER_AGENT}" > ${D_DIR}/user_agent_conf
222     #We can replace below WINDOW_SIZE values from build configuration if available
223     #echo "${WINDOW_SIZE}" > ${D_DIR}/window_size_conf
224 }
225
226 install_chromium_browser() {
227     # Install browser files
228     ${S}/depot_tools/ninja ${PARALLEL_MAKE} -C ${OUT_DIR} webos/install/default_browser
229
230     D_DIR=${D}${BROWSER_APPLICATION_DIR}
231     L_DIR=${D}${CBE_DATA_PATH}
232     install -d ${D_DIR}
233     install -d ${L_DIR}
234
235     cp -R --no-dereference --preserve=mode,links -v ${OUT_DIR}/image/${BROWSER_APPLICATION_DIR}/* ${D_DIR}
236
237     # AGL does not have PMLOG
238     sed -i.bak s/PmLogCtl.*// ${D_DIR}/run_webbrowser
239
240     # To execute chromium in JAILER, Security Part needs permissions change
241     # run_webbrowser: Script file for launching chromium
242     chmod -v 755 ${D_DIR}/chrome
243     chmod -v 755 ${D_DIR}/kill_webbrowser
244     chmod -v 755 ${D_DIR}/run_webbrowser
245
246     configure_browser_settings
247 }
248
249 install_webruntime() {
250
251     # # Generate install webos webview files
252     # ${S}/depot_tools/ninja ${PARALLEL_MAKE} -C ${OUT_DIR} webos/install/weboswebruntime
253
254     # # Move installation files to D directory
255     # mv ${OUT_DIR}/image/* ${D}
256     # # Rename include and locale directories
257     # mv ${D}${includedir}/webruntime ${D}${includedir}/${BPN}
258     # mv ${D}${CBE_DATA_PATH}/neva_locales ${D}${CBE_DATA_LOCALES_PATH}
259
260     # # move this to separate mksnapshot-cross recipe once we figure out how to build just cross mksnapshot from chromium repository
261     # install -d ${D}${bindir_cross}
262     # gzip -c ${OUT_DIR}/${MKSNAPSHOT_PATH}mksnapshot > ${D}${bindir_cross}/${HOST_SYS}-mksnapshot.gz
263
264     install -d ${D}${libdir}
265     install -d ${D}${libdir}/swiftshader
266     install -d ${D}${includedir}/${BPN}
267     install -d ${D}${CBE_DATA_PATH}
268     install -d ${D}${CBE_DATA_LOCALES_PATH}
269
270     # Install webos webview files
271     ${S}/depot_tools/ninja ${PARALLEL_MAKE} -C ${OUT_DIR} webos/install/weboswebruntime
272
273     install -v -m 0644 ${OUT_DIR}/swiftshader/*.so ${D}${libdir}/swiftshader
274
275     cp -R --no-dereference --preserve=mode,links -v ${OUT_DIR}/image/${includedir}/${BPN}/* ${D}${includedir}/${BPN}/
276     install -v -m 0644 ${OUT_DIR}/image/${libdir}/*.so ${D}${libdir}
277
278     install -v -m 0644 ${OUT_DIR}/image/${CBE_DATA_PATH}/icudtl.dat ${D}${CBE_DATA_PATH}
279     install -v -m 0644 ${OUT_DIR}/image/${CBE_DATA_PATH}/snapshot_blob.bin ${D}${CBE_DATA_PATH}
280     # app_runtime_content.pak, webos_content.pak, extensions_shell_and_test.pak
281     install -v -m 0644 ${OUT_DIR}/image/${CBE_DATA_PATH}/*.pak ${D}${CBE_DATA_PATH}
282
283     cp -R --no-dereference --preserve=mode,links -v ${OUT_DIR}/image/${CBE_DATA_LOCALES_PATH}/*.pak ${D}${CBE_DATA_LOCALES_PATH}
284
285     chown root:root -R ${D}${libdir}
286     chown root:root -R ${D}${includedir}
287     chown root:root -R ${D}${CBE_DATA_LOCALES_PATH}
288
289     # move this to separate mksnapshot-cross recipe once we figure out how to build just cross mksnapshot from chromium repository
290     install -d ${D}${base_bindir}
291     gzip -c ${OUT_DIR}/${MKSNAPSHOT_PATH}mksnapshot > ${D}${base_bindir}/${HOST_SYS}-mksnapshot.gz
292
293 }
294
295 do_install() {
296     install_webruntime
297     install_chromium_browser
298 }
299
300 WEBOS_SYSTEM_BUS_DIRS_LEGACY_BROWSER_APPLICATION = " \
301     ${webos_sysbus_prvservicesdir}/${BROWSER_APPLICATION}.service \
302     ${webos_sysbus_pubservicesdir}/${BROWSER_APPLICATION}.service \
303     ${webos_sysbus_prvrolesdir}/${BROWSER_APPLICATION}.json \
304     ${webos_sysbus_pubrolesdir}/${BROWSER_APPLICATION}.json \
305 "
306
307 SYSROOT_DIRS:append = " ${bindir_cross}"
308
309 PACKAGES:prepend = " \
310     ${PN}-cross-mksnapshot \
311     ${BROWSER_APPLICATION} \
312 "
313
314 FILES:${BROWSER_APPLICATION} += " \
315     ${BROWSER_APPLICATION_DIR} \
316     ${WEBOS_SYSTEM_BUS_DIRS_LEGACY_BROWSER_APPLICATION} \
317 "
318
319 RDEPENDS:${BROWSER_APPLICATION} += "${PN}"
320
321 VIRTUAL-RUNTIME_gpu-libs ?= ""
322 RDEPENDS:${PN} += "${VIRTUAL-RUNTIME_gpu-libs}"
323
324 # The text relocations are intentional -- see comments in [GF-52468]
325 # TODO: check if we need INSANE_SKIP on ldflags
326 INSANE_SKIP:${BROWSER_APPLICATION} += "libdir ldflags textrel"
327
328 FILES:${PN} = " \
329     ${libdir}/*.so \
330     ${libdir}/swiftshader/*.so \
331     ${CBE_DATA_PATH}/* \
332     ${libdir}/${BPN}/*.so \
333     ${WEBOS_SYSTEM_BUS_DIRS} \
334 "
335
336 FILES:${PN}-dev = " \
337     ${includedir} \
338 "
339
340 FILES:${PN}-cross-mksnapshot = "${bindir_cross}/${HOST_SYS}-mksnapshot.gz"