1*4882a593Smuzhiyunrequire chromium.inc 2*4882a593Smuzhiyunrequire chromium-unbundle.inc 3*4882a593Smuzhiyunrequire gn-utils.inc 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunGTKIC_VERSION = "${@bb.utils.contains('PACKAGECONFIG', 'gtk4', '4', '3',d)}" 6*4882a593Smuzhiyun 7*4882a593Smuzhiyuninherit features_check gtk-icon-cache qemu 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun# The actual directory name in out/ is irrelevant for GN. 10*4882a593SmuzhiyunOUTPUT_DIR = "out/Release" 11*4882a593SmuzhiyunB = "${S}/${OUTPUT_DIR}" 12*4882a593Smuzhiyun 13*4882a593SmuzhiyunSRC_URI += " \ 14*4882a593Smuzhiyun file://0001-limit-number-of-LTO-jobs.patch \ 15*4882a593Smuzhiyun file://0002-Remove-the-GN-settings-done-for-clang-that-conflict-.patch \ 16*4882a593Smuzhiyun file://0003-v8-qemu-wrapper.patch \ 17*4882a593Smuzhiyun file://0004-wrapper-extra-flags.patch \ 18*4882a593Smuzhiyun file://0005-BUILD-do-not-specify-march-on-arm.patch \ 19*4882a593Smuzhiyun file://0007-Delete-compiler-options-not-available-in-release-ver.patch \ 20*4882a593Smuzhiyun file://0008-avoid-link-latomic-failure-on-CentOS-8-host.patch \ 21*4882a593Smuzhiyun file://0009-nomerge-attribute-on-declaration-is-only-available-s.patch \ 22*4882a593Smuzhiyun file://0011-Revert-Use-ffile-compilation-dir-instead-of-fdebug-c.patch \ 23*4882a593Smuzhiyun file://0013-Fix-html_minifier-script-for-node-v12.patch \ 24*4882a593Smuzhiyun file://0015-drop-gsimple-template-names.patch \ 25*4882a593Smuzhiyun file://0016-cast-to-bool-to-avoid-constexpr-error.patch \ 26*4882a593Smuzhiyun" 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunSRC_URI:append:libc-musl = "\ 29*4882a593Smuzhiyun file://musl/0001-mallinfo-implementation-is-glibc-specific.patch \ 30*4882a593Smuzhiyun file://musl/0002-execinfo-implementation-is-glibc-specific.patch \ 31*4882a593Smuzhiyun file://musl/0003-Define-TEMP_FAILURE_RETRY-and-__si_fields.patch \ 32*4882a593Smuzhiyun file://musl/0004-blink-Fix-build-with-musl.patch \ 33*4882a593Smuzhiyun file://musl/0005-breakpad-Fix-build-with-musl.patch \ 34*4882a593Smuzhiyun file://musl/0006-fontconfig-Musl-does-not-have-rand_r-API.patch \ 35*4882a593Smuzhiyun file://musl/0007-__libc_malloc-is-internal-to-glibc.patch \ 36*4882a593Smuzhiyun file://musl/0008-gnu_libc_version-API-is-glibc-specific.patch \ 37*4882a593Smuzhiyun file://musl/0009-provide-res_ninit-and-nclose-APIs-on-non-glibc-linux.patch \ 38*4882a593Smuzhiyun file://musl/0011-crashpad-Fix-build-with-musl.patch \ 39*4882a593Smuzhiyun file://musl/0012-debug-Fix-build-with-musl.patch \ 40*4882a593Smuzhiyun file://musl/0015-mallopt-is-glibc-specific-API.patch \ 41*4882a593Smuzhiyun file://musl/0018--Use-monotonic-clock-for-pthread_cond_timedwait-with-.patch \ 42*4882a593Smuzhiyun file://musl/0020-Fix-tab-crashes-on-musl.patch \ 43*4882a593Smuzhiyun file://musl/0021-pthread_getname_np.patch \ 44*4882a593Smuzhiyun file://musl/0022-sys-stat.patch \ 45*4882a593Smuzhiyun file://musl/scoped-file.patch \ 46*4882a593Smuzhiyun file://musl/fix-narrowing-cast.patch \ 47*4882a593Smuzhiyun file://musl/credentials-header.patch \ 48*4882a593Smuzhiyun file://musl/fstatat64.patch \ 49*4882a593Smuzhiyun" 50*4882a593Smuzhiyun 51*4882a593SmuzhiyunANY_OF_DISTRO_FEATURES = "opengl vulkan" 52*4882a593Smuzhiyun 53*4882a593Smuzhiyun# Append instead of assigning; the gtk-icon-cache class inherited above also 54*4882a593Smuzhiyun# adds packages to DEPENDS. 55*4882a593SmuzhiyunDEPENDS += " \ 56*4882a593Smuzhiyun alsa-lib \ 57*4882a593Smuzhiyun ${@bb.utils.contains('DISTRO_FEATURES', 'x11', 'at-spi2-core', '', d)} \ 58*4882a593Smuzhiyun atk \ 59*4882a593Smuzhiyun bison-native \ 60*4882a593Smuzhiyun cairo \ 61*4882a593Smuzhiyun curl \ 62*4882a593Smuzhiyun expat \ 63*4882a593Smuzhiyun flac \ 64*4882a593Smuzhiyun glib-2.0 \ 65*4882a593Smuzhiyun gn-native \ 66*4882a593Smuzhiyun gperf-native \ 67*4882a593Smuzhiyun gtk+3 \ 68*4882a593Smuzhiyun jpeg \ 69*4882a593Smuzhiyun libdrm \ 70*4882a593Smuzhiyun libffi \ 71*4882a593Smuzhiyun libwebp \ 72*4882a593Smuzhiyun libxkbcommon \ 73*4882a593Smuzhiyun libxslt \ 74*4882a593Smuzhiyun ninja-native \ 75*4882a593Smuzhiyun nodejs-native \ 76*4882a593Smuzhiyun nspr \ 77*4882a593Smuzhiyun nspr-native \ 78*4882a593Smuzhiyun nss \ 79*4882a593Smuzhiyun nss-native \ 80*4882a593Smuzhiyun pango \ 81*4882a593Smuzhiyun pciutils \ 82*4882a593Smuzhiyun pkgconfig-native \ 83*4882a593Smuzhiyun ${@bb.utils.contains('DISTRO_FEATURES', 'pulseaudio', 'pulseaudio', '', d)} \ 84*4882a593Smuzhiyun qemu-native \ 85*4882a593Smuzhiyun virtual/libgl \ 86*4882a593Smuzhiyun" 87*4882a593SmuzhiyunDEPEND:append:runtime-llvm = " compiler-rt-native libcxx-native" 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun# The wrapper script we use from upstream requires bash. 90*4882a593SmuzhiyunRDEPENDS:${PN} = "bash" 91*4882a593Smuzhiyun 92*4882a593SmuzhiyunCOMPATIBLE_MACHINE = "(-)" 93*4882a593SmuzhiyunCOMPATIBLE_MACHINE:aarch64 = "(.*)" 94*4882a593SmuzhiyunCOMPATIBLE_MACHINE:armv6 = "(.*)" 95*4882a593SmuzhiyunCOMPATIBLE_MACHINE:armv7a = "(.*)" 96*4882a593SmuzhiyunCOMPATIBLE_MACHINE:armv7ve = "(.*)" 97*4882a593SmuzhiyunCOMPATIBLE_MACHINE:x86-64 = "(.*)" 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun# Also build the parts that are run on the host with clang. 100*4882a593SmuzhiyunBUILD_AR:toolchain-clang = "llvm-ar" 101*4882a593SmuzhiyunBUILD_CC:toolchain-clang = "clang" 102*4882a593SmuzhiyunBUILD_CXX:toolchain-clang = "clang++" 103*4882a593SmuzhiyunBUILD_LD:toolchain-clang = "clang" 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunPACKAGECONFIG ??= "upower use-egl" 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun# this makes sure the dependencies for the EGL mode are present; otherwise, the configure scripts 108*4882a593Smuzhiyun# automatically and silently fall back to GLX 109*4882a593SmuzhiyunPACKAGECONFIG[use-egl] = ",,virtual/egl virtual/libgles2" 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun# Empty PACKAGECONFIG options listed here to avoid warnings. 112*4882a593Smuzhiyun# The .bb file should use these to conditionally add patches 113*4882a593Smuzhiyun# and command-line switches (extra dependencies should not 114*4882a593Smuzhiyun# be necessary but are OK to add). 115*4882a593SmuzhiyunPACKAGECONFIG[component-build] = "" 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun# Starting with M61, Chromium defaults to building with its own copy of libc++ 118*4882a593Smuzhiyun# instead of the system's libstdc++. Add a knob to control this behavior 119*4882a593Smuzhiyun# https://groups.google.com/a/chromium.org/d/msg/chromium-packagers/8aYO3me2SCE/SZ8pJXhZAwAJ 120*4882a593SmuzhiyunPACKAGECONFIG[custom-libcxx] = "use_custom_libcxx=true,use_custom_libcxx=false,," 121*4882a593Smuzhiyun 122*4882a593SmuzhiyunPACKAGECONFIG[cups] = "use_cups=true,use_cups=false,cups" 123*4882a593SmuzhiyunPACKAGECONFIG[gtk4] = "" 124*4882a593SmuzhiyunPACKAGECONFIG[kiosk-mode] = "" 125*4882a593SmuzhiyunPACKAGECONFIG[proprietary-codecs] = ' \ 126*4882a593Smuzhiyun ffmpeg_branding="Chrome" proprietary_codecs=true, \ 127*4882a593Smuzhiyun ffmpeg_branding="Chromium" proprietary_codecs=false \ 128*4882a593Smuzhiyun' 129*4882a593Smuzhiyun# Enable UPower by default. 130*4882a593Smuzhiyun# Chromium expects to be able to query battery status through D-Bus. 131*4882a593SmuzhiyunPACKAGECONFIG[upower] = ",,,upower" 132*4882a593Smuzhiyun 133*4882a593Smuzhiyun# Disable VA-API by default. It is compile time enabled since M88, but it's not 134*4882a593Smuzhiyun# desired to make all the users of the Chromium meta-browser recipe depend on 135*4882a593Smuzhiyun# libva without a real need. Both X11 (non-Ozone) and Wayland (Ozone) can use it, 136*4882a593Smuzhiyun# but remember to also use proprietary codecs so that H.264 is supported. Also note 137*4882a593Smuzhiyun# that not all the hardware configs might be supported. 138*4882a593SmuzhiyunPACKAGECONFIG[use-vaapi] = "use_vaapi=true use_libgav1_parser=true,use_vaapi=false,libva" 139*4882a593Smuzhiyun 140*4882a593Smuzhiyun# Base GN arguments, mostly related to features we want to enable or disable. 141*4882a593SmuzhiyunGN_ARGS = " \ 142*4882a593Smuzhiyun ${PACKAGECONFIG_CONFARGS} \ 143*4882a593Smuzhiyun is_component_build=${@bb.utils.contains('PACKAGECONFIG', 'component-build', 'true', 'false', d)} \ 144*4882a593Smuzhiyun use_gnome_keyring=false \ 145*4882a593Smuzhiyun use_kerberos=false \ 146*4882a593Smuzhiyun use_pulseaudio=${@bb.utils.contains('DISTRO_FEATURES', 'pulseaudio', 'true', 'false', d)} \ 147*4882a593Smuzhiyun use_system_libjpeg=true \ 148*4882a593Smuzhiyun" 149*4882a593Smuzhiyun# Not enabled by default, because the freetype version from oe-core 150*4882a593Smuzhiyun# often isn't compatible, e.g. freetype-2.11 isn't compatible with 151*4882a593Smuzhiyun# chromium-94 152*4882a593SmuzhiyunGN_ARGS += "use_system_freetype=false" 153*4882a593Smuzhiyun 154*4882a593Smuzhiyun# Qt support appears to be underdevelopment in Nov 2022 so disable now 155*4882a593Smuzhiyun# but a PACKAGECONFIG option should be added when the feature is ready. 156*4882a593SmuzhiyunGN_ARGS += "use_qt=false" 157*4882a593Smuzhiyun 158*4882a593Smuzhiyun# Closure_compile needs to be disabled to avoid pulling in java dependencies, 159*4882a593Smuzhiyun# which are typicaly not wanted. It started to happen after https://crrev.com/c/1278470 160*4882a593Smuzhiyun# This argument was renamed to enable_js_type_check after https://crrev.com/c/2248564 161*4882a593SmuzhiyunGN_ARGS += "enable_js_type_check=false" 162*4882a593Smuzhiyun 163*4882a593Smuzhiyun# Make sure pkg-config, when used with the host's toolchain to build the 164*4882a593Smuzhiyun# binaries we need to run on the host, uses the right pkg-config to avoid 165*4882a593Smuzhiyun# passing include directories belonging to the target. 166*4882a593SmuzhiyunGN_ARGS += 'host_pkg_config="pkg-config-native"' 167*4882a593Smuzhiyun 168*4882a593Smuzhiyun# From Chromium's BUILDCONFIG.gn: 169*4882a593Smuzhiyun# Set to enable the official build level of optimization. This has nothing 170*4882a593Smuzhiyun# to do with branding, but enables an additional level of optimization above 171*4882a593Smuzhiyun# release (!is_debug). This might be better expressed as a tri-state 172*4882a593Smuzhiyun# (debug, release, official) but for historical reasons there are two 173*4882a593Smuzhiyun# separate flags. 174*4882a593Smuzhiyun# See also: https://groups.google.com/a/chromium.org/d/msg/chromium-dev/hkcb6AOX5gE/PPT1ukWoBwAJ 175*4882a593SmuzhiyunGN_ARGS += "is_debug=false is_official_build=true" 176*4882a593Smuzhiyun 177*4882a593Smuzhiyun# Use lld linker its quicker see https://lld.llvm.org/#performance 178*4882a593SmuzhiyunGN_ARGS += "use_lld=true use_gold=false" 179*4882a593Smuzhiyun 180*4882a593Smuzhiyun# By default, passing is_official_build=true to GN causes its symbol_level 181*4882a593Smuzhiyun# variable to be set to "2". This means the compiler will be passed "-g2" and 182*4882a593Smuzhiyun# we will end up with a very large chrome binary (around 5Gb as of M58) 183*4882a593Smuzhiyun# regardless of whether DEBUG_BUILD has been set or not. In addition, binutils, 184*4882a593Smuzhiyun# file and other utilities are unable to read a 32-bit binary this size, which 185*4882a593Smuzhiyun# causes it not to be stripped. 186*4882a593Smuzhiyun# The solution is two-fold: 187*4882a593Smuzhiyun# 1. Make sure -g is not passed on 32-bit architectures via DEBUG_FLAGS. -g is 188*4882a593Smuzhiyun# the same as -g2. -g1 generates an 800MB binary, which is a lot more 189*4882a593Smuzhiyun# manageable. 190*4882a593Smuzhiyun# 2. Explicitly pass symbol_level=0 to GN. This causes -g0 to be passed 191*4882a593Smuzhiyun# instead, so that if DEBUG_BUILD is not set GN will not create a huge debug 192*4882a593Smuzhiyun# binary anyway. Since our compiler flags are passed after GN's, -g0 does 193*4882a593Smuzhiyun# not cause any issues if DEBUG_BUILD is set, as -g1 will be passed later. 194*4882a593SmuzhiyunDEBUG_FLAGS:remove:arm = "-g" 195*4882a593SmuzhiyunDEBUG_FLAGS:append:arm = "-g1" 196*4882a593SmuzhiyunDEBUG_FLAGS:remove:x86 = "-g" 197*4882a593SmuzhiyunDEBUG_FLAGS:append:x86 = "-g1" 198*4882a593SmuzhiyunGN_ARGS += "symbol_level=0" 199*4882a593Smuzhiyun 200*4882a593Smuzhiyun# As of Chromium 62.0.3202.94 and Yocto Rocko (GCC 7, binutils 2.29), passing 201*4882a593Smuzhiyun# -g to the compiler results in many linker errors on aarch64, such as: 202*4882a593Smuzhiyun# obj/third_party/WebKit/Source/modules/payments/libpayments.a(PaymentEventDataConversion.o)(.debug_loc+0x4e25): error: relocation overflow in R_AARCH64_ABS32 203*4882a593SmuzhiyunDEBUG_FLAGS:remove:aarch64 = "-g" 204*4882a593SmuzhiyunDEBUG_FLAGS:append:aarch64 = "-g1" 205*4882a593Smuzhiyun 206*4882a593Smuzhiyun# As of Chromium 60.0.3112.101 and Yocto Pyro (GCC 6, binutils 2.28), passing 207*4882a593Smuzhiyun# -g to the compiler results in many linker errors on x86_64, such as: 208*4882a593Smuzhiyun# obj/third_party/WebKit/Source/core/loader/libloader.a(ModuleTreeLinker.o)(.debug_loc+0x1e9a5): error: relocation overflow: reference to local symbol 82 in obj/third_party/WebKit/Source/core/loader/libloader.a(ModuleTreeLinker.o) 209*4882a593Smuzhiyun# obj/third_party/WebKit/Source/core/libcore_generated.a(ScriptModule.o)(.debug_loc+0x253c): error: relocation overflow: reference to local symbol 31 in obj/third_party/WebKit/Source/core/libcore_generated.a(ScriptModule.o) 210*4882a593Smuzhiyun# so we have to use the same hack described above. 211*4882a593SmuzhiyunDEBUG_FLAGS:remove:x86-64 = "-g" 212*4882a593SmuzhiyunDEBUG_FLAGS:append:x86-64 = "-g1" 213*4882a593Smuzhiyun 214*4882a593Smuzhiyun# Disable Chrome Remote Desktop (aka Chromoting) support. Building host support 215*4882a593Smuzhiyun# (so that the machine running this recipe can be controlled remotely from 216*4882a593Smuzhiyun# another machine) requires additional effort to build some extra binaries, 217*4882a593Smuzhiyun# whereas connecting to other machines requires building and installing a 218*4882a593Smuzhiyun# Chrome extension (it is not clear how to do that automatically). 219*4882a593SmuzhiyunGN_ARGS += "enable_remoting=false" 220*4882a593Smuzhiyun 221*4882a593Smuzhiyun# NaCl support depends on the NaCl toolchain that needs to be built before NaCl 222*4882a593Smuzhiyun# itself. The whole process is quite cumbersome so we just disable the whole 223*4882a593Smuzhiyun# thing for now. 224*4882a593SmuzhiyunGN_ARGS += "enable_nacl=false" 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun# We do not want to use Chromium's own Debian-based sysroots, it is easier to 227*4882a593Smuzhiyun# just let Chromium's build system assume we are not using a sysroot at all and 228*4882a593Smuzhiyun# let Yocto handle everything. 229*4882a593SmuzhiyunGN_ARGS += "use_sysroot=false" 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun# The clang version used to build this recipe may be older than upstream 232*4882a593Smuzhiyun# Chromium's, which can cause unexpected warnings to show up. They should not 233*4882a593Smuzhiyun# cause the build to fail. 234*4882a593SmuzhiyunGN_ARGS += "treat_warnings_as_errors=false" 235*4882a593Smuzhiyun 236*4882a593Smuzhiyun# Enabling Control Flow Integrity requires more research (i.e. we need to 237*4882a593Smuzhiyun# figure out when it was first deemed stable by Chromium). Upstream only 238*4882a593Smuzhiyun# enables this for x86-64 right now. 239*4882a593SmuzhiyunGN_ARGS += "is_cfi=false" 240*4882a593Smuzhiyun 241*4882a593Smuzhiyun# Disable activation of field trial tests that can cause problems in 242*4882a593Smuzhiyun# production. 243*4882a593Smuzhiyun# See https://groups.google.com/a/chromium.org/d/msg/chromium-packagers/ECWC57W7E0k/9Kc5UAmyDAAJ 244*4882a593SmuzhiyunGN_ARGS += "disable_fieldtrial_testing_config=true" 245*4882a593Smuzhiyun 246*4882a593Smuzhiyun# Disable PGO optimization as generated profdata requires the same version of 247*4882a593Smuzhiyun# clang that upstream uses. Otherwise, clang-llvm produces the following error: 248*4882a593Smuzhiyun# Unsupported instrumentation profile format version. 249*4882a593Smuzhiyun# See https://crrev.com/c/2424669 250*4882a593SmuzhiyunGN_ARGS += "chrome_pgo_phase=0" 251*4882a593Smuzhiyun 252*4882a593Smuzhiyun# API keys for accessing Google services. By default, we use an invalid key 253*4882a593Smuzhiyun# only to prevent the "you are missing an API key" infobar from being shown on 254*4882a593Smuzhiyun# startup. 255*4882a593Smuzhiyun# See https://dev.chromium.org/developers/how-tos/api-keys for more information 256*4882a593Smuzhiyun# on how to obtain your own keys. You can then set the variables below in 257*4882a593Smuzhiyun# local.conf or a .bbappend file. 258*4882a593SmuzhiyunGOOGLE_API_KEY ??= "invalid-api-key" 259*4882a593SmuzhiyunGOOGLE_DEFAULT_CLIENT_ID ??= "invalid-client-id" 260*4882a593SmuzhiyunGOOGLE_DEFAULT_CLIENT_SECRET ??= "invalid-client-secret" 261*4882a593SmuzhiyunGN_ARGS += ' \ 262*4882a593Smuzhiyun google_api_key="${GOOGLE_API_KEY}" \ 263*4882a593Smuzhiyun google_default_client_id="${GOOGLE_DEFAULT_CLIENT_ID}" \ 264*4882a593Smuzhiyun google_default_client_secret="${GOOGLE_DEFAULT_CLIENT_SECRET}" \ 265*4882a593Smuzhiyun' 266*4882a593Smuzhiyun 267*4882a593Smuzhiyun# Use libcxx headers for native parts 268*4882a593SmuzhiyunBUILD_CPPFLAGS:append:runtime-llvm = " -isysroot=${STAGING_DIR_NATIVE} -stdlib=libc++" 269*4882a593Smuzhiyun# Use libgcc for native parts 270*4882a593SmuzhiyunBUILD_LDFLAGS:append:runtime-llvm = " -rtlib=libgcc -unwindlib=libgcc -stdlib=libc++ -lc++abi -rpath ${STAGING_LIBDIR_NATIVE}" 271*4882a593Smuzhiyun 272*4882a593Smuzhiyun# Toolchains we will use for the build. We need to point to the toolchain file 273*4882a593Smuzhiyun# we've created, set the right target architecture and make sure we are not 274*4882a593Smuzhiyun# using Chromium's toolchain (bundled clang, bundled binutils etc). 275*4882a593SmuzhiyunGN_ARGS += ' \ 276*4882a593Smuzhiyun custom_toolchain="//build/toolchain/yocto:yocto_target" \ 277*4882a593Smuzhiyun gold_path="" \ 278*4882a593Smuzhiyun host_toolchain="//build/toolchain/yocto:yocto_native" \ 279*4882a593Smuzhiyun is_clang=true \ 280*4882a593Smuzhiyun clang_base_path="${@clang_install_path(d)}" \ 281*4882a593Smuzhiyun clang_use_chrome_plugins=false \ 282*4882a593Smuzhiyun target_cpu="${@gn_target_arch_name(d)}" \ 283*4882a593Smuzhiyun v8_snapshot_toolchain="//build/toolchain/yocto:yocto_target" \ 284*4882a593Smuzhiyun' 285*4882a593Smuzhiyun 286*4882a593Smuzhiyun# This parameter is added by limit-number-of-LTO-jobs.patch with the default value of 8, 287*4882a593Smuzhiyun# but we can use whatever user configured in PARALLEL_MAKE 288*4882a593SmuzhiyunGN_ARGS += 'max_jobs_per_link="${@oe.utils.parallel_make_argument(d, '%d')}"' 289*4882a593Smuzhiyun 290*4882a593Smuzhiyun# ARM builds need special additional flags (see ${S}/build/config/arm.gni). 291*4882a593Smuzhiyun# If we do not pass |arm_arch| and friends to GN, it will deduce a value that 292*4882a593Smuzhiyun# will then conflict with TUNE_CCARGS and CC. 293*4882a593Smuzhiyun# Note that as of M61 in some corner cases parts of the build system disable 294*4882a593Smuzhiyun# the "compiler:arm_fpu" GN config, whereas -mfpu is always passed via ${CC}. 295*4882a593Smuzhiyun# We might want to rework that if there are issues in the future. 296*4882a593Smuzhiyundef get_compiler_flag(params, param_name, d): 297*4882a593Smuzhiyun """Given a sequence of compiler arguments in |params|, returns the value of 298*4882a593Smuzhiyun an option |param_name| or an empty string if the option is not present.""" 299*4882a593Smuzhiyun for param in params: 300*4882a593Smuzhiyun if param.startswith(param_name): 301*4882a593Smuzhiyun return param.split('=')[1] 302*4882a593Smuzhiyun return '' 303*4882a593Smuzhiyun 304*4882a593SmuzhiyunARM_FLOAT_ABI = "${@bb.utils.contains('TUNE_FEATURES', 'callconvention-hard', 'hard', 'softfp', d)}" 305*4882a593SmuzhiyunARM_FPU = "${@get_compiler_flag(d.getVar('TUNE_CCARGS').split(), '-mfpu', d)}" 306*4882a593SmuzhiyunARM_TUNE = "${@get_compiler_flag(d.getVar('TUNE_CCARGS').split(), '-mcpu', d)}" 307*4882a593SmuzhiyunARM_VERSION:aarch64 = "8" 308*4882a593SmuzhiyunARM_VERSION:armv7a = "7" 309*4882a593SmuzhiyunARM_VERSION:armv7ve = "7" 310*4882a593SmuzhiyunARM_VERSION:armv6 = "6" 311*4882a593Smuzhiyun 312*4882a593Smuzhiyun# GN computes and defaults to it automatically where needed 313*4882a593Smuzhiyun# forcing it from cmdline breaks build on places where it ends up 314*4882a593Smuzhiyun# overriding what GN wants 315*4882a593SmuzhiyunTUNE_CCARGS:remove = "-mthumb" 316*4882a593Smuzhiyun 317*4882a593SmuzhiyunGN_ARGS:append:arm = ' \ 318*4882a593Smuzhiyun arm_float_abi="${ARM_FLOAT_ABI}" \ 319*4882a593Smuzhiyun arm_fpu="${ARM_FPU}" \ 320*4882a593Smuzhiyun arm_tune="${ARM_TUNE}" \ 321*4882a593Smuzhiyun arm_version=${ARM_VERSION} \ 322*4882a593Smuzhiyun' 323*4882a593Smuzhiyun# tcmalloc's atomicops-internals-arm-v6plus.h uses the "dmb" instruction that 324*4882a593Smuzhiyun# is not available on (some?) ARMv6 models, which causes the build to fail. 325*4882a593SmuzhiyunGN_ARGS:append:armv6 = ' use_partition_alloc_as_malloc=false enable_backup_ref_ptr_support=false' 326*4882a593Smuzhiyun# The WebRTC code fails to build on ARMv6 when NEON is enabled. 327*4882a593Smuzhiyun# https://bugs.chromium.org/p/webrtc/issues/detail?id=6574 328*4882a593SmuzhiyunGN_ARGS:append:armv6 = ' arm_use_neon=false' 329*4882a593Smuzhiyun 330*4882a593Smuzhiyun# Disable glibc shims on musl 331*4882a593Smuzhiyun# tcmalloc does not play well with musl as of M62 (and possibly earlier). 332*4882a593Smuzhiyun# https://github.com/gperftools/gperftools/issues/693 333*4882a593SmuzhiyunGN_ARGS:append:libc-musl = ' use_allocator_shim=false use_partition_alloc_as_malloc=false enable_backup_ref_ptr_support=false' 334*4882a593Smuzhiyun 335*4882a593SmuzhiyunCHROMIUM_EXTRA_ARGS ?= " \ 336*4882a593Smuzhiyun ${@bb.utils.contains('PACKAGECONFIG', 'use-egl', '--use-gl=egl', '', d)} \ 337*4882a593Smuzhiyun ${@bb.utils.contains('PACKAGECONFIG', 'kiosk-mode', '--kiosk --no-first-run --incognito', '', d)} \ 338*4882a593Smuzhiyun ${@bb.utils.contains('PACKAGECONFIG', 'gtk4', '--gtk-version=4', '', d)} \ 339*4882a593Smuzhiyun" 340*4882a593Smuzhiyun 341*4882a593Smuzhiyun# V8's JIT infrastructure requires binaries such as mksnapshot and 342*4882a593Smuzhiyun# mkpeephole to be run in the host during the build. However, these 343*4882a593Smuzhiyun# binaries must have the same bit-width as the target (e.g. a x86_64 344*4882a593Smuzhiyun# host targeting ARMv6 needs to produce a 32-bit binary). Instead of 345*4882a593Smuzhiyun# depending on a third Yocto toolchain, we just build those binaries 346*4882a593Smuzhiyun# for the target and run them on the host with QEMU. 347*4882a593Smuzhiyunpython do_create_v8_qemu_wrapper () { 348*4882a593Smuzhiyun """Creates a small wrapper that invokes QEMU to run some target V8 binaries 349*4882a593Smuzhiyun on the host.""" 350*4882a593Smuzhiyun qemu_libdirs = [d.expand('${STAGING_DIR_HOST}${libdir}'), 351*4882a593Smuzhiyun d.expand('${STAGING_DIR_HOST}${base_libdir}')] 352*4882a593Smuzhiyun qemu_cmd = qemu_wrapper_cmdline(d, d.getVar('STAGING_DIR_HOST', True), 353*4882a593Smuzhiyun qemu_libdirs) 354*4882a593Smuzhiyun wrapper_path = d.expand('${B}/v8-qemu-wrapper.sh') 355*4882a593Smuzhiyun with open(wrapper_path, 'w') as wrapper_file: 356*4882a593Smuzhiyun wrapper_file.write("""#!/bin/sh 357*4882a593Smuzhiyun 358*4882a593Smuzhiyun# This file has been generated automatically. 359*4882a593Smuzhiyun# It invokes QEMU to run binaries built for the target in the host during the 360*4882a593Smuzhiyun# build process. 361*4882a593Smuzhiyun 362*4882a593Smuzhiyun%s "$@" 363*4882a593Smuzhiyun""" % qemu_cmd) 364*4882a593Smuzhiyun os.chmod(wrapper_path, 0o755) 365*4882a593Smuzhiyun} 366*4882a593Smuzhiyundo_create_v8_qemu_wrapper[dirs] = "${B}" 367*4882a593Smuzhiyunaddtask create_v8_qemu_wrapper after do_patch before do_configure 368*4882a593Smuzhiyun 369*4882a593Smuzhiyun# Check the LLVMVERSION defined in the meta-clang layer. Given Chromium is 370*4882a593Smuzhiyun# developed using new C++ features, the LLVMVERSION has to be >= 12. Otherwise, 371*4882a593Smuzhiyun# it is not guaranteed that Chromium will compile. 372*4882a593Smuzhiyunpython do_check_llvm_version () { 373*4882a593Smuzhiyun from distutils.version import LooseVersion 374*4882a593Smuzhiyun 375*4882a593Smuzhiyun min_llvm_version = "12.0.0" 376*4882a593Smuzhiyun llvm_version = d.getVar('LLVMVERSION', False) 377*4882a593Smuzhiyun if not llvm_version: 378*4882a593Smuzhiyun bb.warn("Unable to determine LLVM version. Chromium may not be compiled " 379*4882a593Smuzhiyun "successfully if the LLVM version is below %s." % min_llvm_version) 380*4882a593Smuzhiyun return 381*4882a593Smuzhiyun 382*4882a593Smuzhiyun if LooseVersion(llvm_version) < LooseVersion(min_llvm_version): 383*4882a593Smuzhiyun bb.fatal("Your LLVMVERSION (%s) is lower than the minimum required " 384*4882a593Smuzhiyun "LLVMVERSION (%s). If you are using dunfell, make sure you " 385*4882a593Smuzhiyun "use clang12 branch." % (llvm_version, min_llvm_version)) 386*4882a593Smuzhiyun} 387*4882a593Smuzhiyunaddtask check_llvm_version before do_configure 388*4882a593Smuzhiyun 389*4882a593Smuzhiyunpython do_write_toolchain_file () { 390*4882a593Smuzhiyun """Writes a BUILD.gn file for Yocto detailing its toolchains.""" 391*4882a593Smuzhiyun toolchain_dir = d.expand("${S}/build/toolchain/yocto") 392*4882a593Smuzhiyun bb.utils.mkdirhier(toolchain_dir) 393*4882a593Smuzhiyun toolchain_file = os.path.join(toolchain_dir, "BUILD.gn") 394*4882a593Smuzhiyun write_toolchain_file(d, toolchain_file) 395*4882a593Smuzhiyun} 396*4882a593Smuzhiyunaddtask write_toolchain_file after do_patch before do_configure 397*4882a593Smuzhiyun 398*4882a593Smuzhiyundo_add_nodejs_symlink () { 399*4882a593Smuzhiyun # Adds a symlink to the node binary to the location expected by 400*4882a593Smuzhiyun # Chromium's build system. 401*4882a593Smuzhiyun chromium_node_dir="${S}/third_party/node/linux/node-linux-x64/bin" 402*4882a593Smuzhiyun nodejs_native_path="${STAGING_BINDIR_NATIVE}/node" 403*4882a593Smuzhiyun mkdir -p "${chromium_node_dir}" 404*4882a593Smuzhiyun if [ ! -f "${nodejs_native_path}" ]; then 405*4882a593Smuzhiyun echo "${nodejs_native_path} does not exist." 406*4882a593Smuzhiyun exit 1 407*4882a593Smuzhiyun fi 408*4882a593Smuzhiyun ln -sf "${nodejs_native_path}" "${chromium_node_dir}/node" 409*4882a593Smuzhiyun} 410*4882a593Smuzhiyunaddtask add_nodejs_symlink after do_configure before do_compile 411*4882a593Smuzhiyun 412*4882a593Smuzhiyundo_configure() { 413*4882a593Smuzhiyun cd ${S} 414*4882a593Smuzhiyun python3 ./build/linux/unbundle/replace_gn_files.py --system-libraries ${GN_UNBUNDLE_LIBS} 415*4882a593Smuzhiyun gn gen --args='${GN_ARGS}' "${OUTPUT_DIR}" 416*4882a593Smuzhiyun} 417*4882a593Smuzhiyun 418*4882a593Smuzhiyundo_compile() { 419*4882a593Smuzhiyun ninja -v ${PARALLEL_MAKE} chrome chrome_sandbox chromedriver.unstripped 420*4882a593Smuzhiyun} 421*4882a593Smuzhiyundo_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+" 422*4882a593Smuzhiyun 423*4882a593Smuzhiyundo_install() { 424*4882a593Smuzhiyun install -d ${D}${bindir} 425*4882a593Smuzhiyun install -d ${D}${datadir} 426*4882a593Smuzhiyun install -d ${D}${datadir}/applications 427*4882a593Smuzhiyun install -d ${D}${datadir}/icons 428*4882a593Smuzhiyun install -d ${D}${datadir}/icons/hicolor 429*4882a593Smuzhiyun install -d ${D}${libdir}/chromium 430*4882a593Smuzhiyun install -d ${D}${libdir}/chromium/locales 431*4882a593Smuzhiyun 432*4882a593Smuzhiyun install -m 4755 chrome_sandbox ${D}${libdir}/chromium/chrome-sandbox 433*4882a593Smuzhiyun install -m 0755 chrome ${D}${libdir}/chromium/chromium-bin 434*4882a593Smuzhiyun install -m 0644 *.bin ${D}${libdir}/chromium/ 435*4882a593Smuzhiyun install -m 0644 icudtl.dat ${D}${libdir}/chromium/icudtl.dat 436*4882a593Smuzhiyun 437*4882a593Smuzhiyun # Process and install Chromium's template .desktop file. 438*4882a593Smuzhiyun sed -e "s,@@MENUNAME@@,Chromium Browser,g" \ 439*4882a593Smuzhiyun -e "s,@@PACKAGE@@,chromium,g" \ 440*4882a593Smuzhiyun -e "s,@@USR_BIN_SYMLINK_NAME@@,chromium,g" \ 441*4882a593Smuzhiyun ${S}/chrome/installer/linux/common/desktop.template > chromium.desktop 442*4882a593Smuzhiyun install -m 0644 chromium.desktop ${D}${datadir}/applications/chromium.desktop 443*4882a593Smuzhiyun 444*4882a593Smuzhiyun # Install icons. 445*4882a593Smuzhiyun for size in 16 24 32 48 64 128 256; do 446*4882a593Smuzhiyun install -d ${D}${datadir}/icons/hicolor/${size}x${size} 447*4882a593Smuzhiyun install -d ${D}${datadir}/icons/hicolor/${size}x${size}/apps 448*4882a593Smuzhiyun for dirname in "chromium" "default_100_percent/chromium"; do 449*4882a593Smuzhiyun icon="${S}/chrome/app/theme/${dirname}/product_logo_${size}.png" 450*4882a593Smuzhiyun if [ -f "${icon}" ]; then 451*4882a593Smuzhiyun install -m 0644 "${icon}" \ 452*4882a593Smuzhiyun ${D}${datadir}/icons/hicolor/${size}x${size}/apps/chromium.png 453*4882a593Smuzhiyun fi 454*4882a593Smuzhiyun done 455*4882a593Smuzhiyun done 456*4882a593Smuzhiyun 457*4882a593Smuzhiyun # A wrapper for the proprietary Google Chrome version already exists. 458*4882a593Smuzhiyun # We can just use that one instead of reinventing the wheel. 459*4882a593Smuzhiyun WRAPPER_FILE=${S}/chrome/installer/linux/common/wrapper 460*4882a593Smuzhiyun sed -e "s,@@CHANNEL@@,stable,g" \ 461*4882a593Smuzhiyun -e "s,@@PROGNAME@@,chromium-bin,g" \ 462*4882a593Smuzhiyun ${WRAPPER_FILE} > chromium-wrapper 463*4882a593Smuzhiyun install -m 0755 chromium-wrapper ${D}${libdir}/chromium/chromium-wrapper 464*4882a593Smuzhiyun ln -s ${libdir}/chromium/chromium-wrapper ${D}${bindir}/chromium 465*4882a593Smuzhiyun 466*4882a593Smuzhiyun # Chromium *.pak files 467*4882a593Smuzhiyun install -m 0644 chrome_*.pak ${D}${libdir}/chromium/ 468*4882a593Smuzhiyun install -m 0644 resources.pak ${D}${libdir}/chromium/resources.pak 469*4882a593Smuzhiyun 470*4882a593Smuzhiyun # Locales. 471*4882a593Smuzhiyun install -m 0644 locales/*.pak ${D}${libdir}/chromium/locales/ 472*4882a593Smuzhiyun 473*4882a593Smuzhiyun # Add extra command line arguments to the chromium-wrapper script by 474*4882a593Smuzhiyun # modifying the dummy "CHROME_EXTRA_ARGS" line 475*4882a593Smuzhiyun sed -i "s/^CHROME_EXTRA_ARGS=\"\"/CHROME_EXTRA_ARGS=\"${CHROMIUM_EXTRA_ARGS}\"/" ${D}${libdir}/chromium/chromium-wrapper 476*4882a593Smuzhiyun 477*4882a593Smuzhiyun # ANGLE. 478*4882a593Smuzhiyun if [ -e libEGL.so ]; then 479*4882a593Smuzhiyun install -m 0644 libEGL.so ${D}${libdir}/chromium/ 480*4882a593Smuzhiyun install -m 0644 libGLESv2.so ${D}${libdir}/chromium/ 481*4882a593Smuzhiyun fi 482*4882a593Smuzhiyun 483*4882a593Smuzhiyun # libvulkan (for ANGLE). 484*4882a593Smuzhiyun if [ -e libvulkan.so.1 ]; then 485*4882a593Smuzhiyun install -m 0644 libvulkan.so.1 ${D}${libdir}/chromium/ 486*4882a593Smuzhiyun fi 487*4882a593Smuzhiyun 488*4882a593Smuzhiyun # Swiftshader VK. 489*4882a593Smuzhiyun if [ -e libvk_swiftshader.so ]; then 490*4882a593Smuzhiyun install -m 0644 libvk_swiftshader.so ${D}${libdir}/chromium/ 491*4882a593Smuzhiyun # This is needed for ANGLE to find libvk_swiftshader.so. 492*4882a593Smuzhiyun install -m 0644 vk_swiftshader_icd.json ${D}${libdir}/chromium/ 493*4882a593Smuzhiyun fi 494*4882a593Smuzhiyun 495*4882a593Smuzhiyun if [ -n "${@bb.utils.contains('PACKAGECONFIG', 'component-build', 'component-build', '', d)}" ]; then 496*4882a593Smuzhiyun install -m 0755 *.so ${D}${libdir}/chromium/ 497*4882a593Smuzhiyun fi 498*4882a593Smuzhiyun 499*4882a593Smuzhiyun # When building chromium with use_system_minigbm=false, 500*4882a593Smuzhiyun # libminigbm.so does not seem to get linked in statically. 501*4882a593Smuzhiyun # So we simply check whether it exists in all cases and ship it. 502*4882a593Smuzhiyun if [ -e libminigbm.so ]; then 503*4882a593Smuzhiyun install -m 0755 libminigbm.so ${D}${libdir}/chromium/ 504*4882a593Smuzhiyun fi 505*4882a593Smuzhiyun 506*4882a593Smuzhiyun # ChromeDriver. 507*4882a593Smuzhiyun install -m 0755 chromedriver.unstripped ${D}${bindir}/chromedriver 508*4882a593Smuzhiyun 509*4882a593Smuzhiyun # Install chrome_crashpad_handler. 510*4882a593Smuzhiyun install -m 0755 chrome_crashpad_handler ${D}${libdir}/chromium/ 511*4882a593Smuzhiyun} 512*4882a593Smuzhiyun 513*4882a593SmuzhiyunPACKAGES =+ "${PN}-chromedriver" 514*4882a593Smuzhiyun 515*4882a593SmuzhiyunFILES:${PN}-chromedriver = "${bindir}/chromedriver" 516*4882a593Smuzhiyun 517*4882a593SmuzhiyunFILES:${PN} = " \ 518*4882a593Smuzhiyun ${bindir}/chromium \ 519*4882a593Smuzhiyun ${datadir}/applications/chromium.desktop \ 520*4882a593Smuzhiyun ${datadir}/icons/hicolor/*x*/apps/chromium.png \ 521*4882a593Smuzhiyun ${libdir}/chromium/* \ 522*4882a593Smuzhiyun" 523*4882a593Smuzhiyun 524*4882a593SmuzhiyunPACKAGE_DEBUG_SPLIT_STYLE = "debug-without-src" 525*4882a593Smuzhiyun 526*4882a593Smuzhiyun# There is no need to ship empty -dev packages. 527*4882a593SmuzhiyunALLOW_EMPTY:${PN}-dev = "0" 528*4882a593Smuzhiyun 529*4882a593Smuzhiyun# ERROR: QA Issue: lib32-chromium-ozone-wayland: ELF binary /usr/bin/chromium has relocations in .text [textrel] 530*4882a593SmuzhiyunINSANE_SKIP:${PN}:append:x86 = "textrel" 531*4882a593Smuzhiyun 532