From 58eabf0b4f69f136629286538c31c10e9375c51c Mon Sep 17 00:00:00 2001 From: Ken Rockot Date: Sat, 28 Apr 2018 03:01:04 +0000 Subject: [PATCH] Build 32- and 64-bit Android mojo_core for Chrome OS distribution Causes Chrome builds for Chrome OS to emit additional 32-bit and 64-bit copies of the mojo_core shared library built against the Android toolchain, for use from within the ARC++ container. In order to support building these library targets, this also modifies DEPS to include a minimal set of required Android support tools and libraries in chromeos checkouts. Bug: 822034 Change-Id: I219837de3076490cdea8315e6cc98c5432871ea0 Reviewed-on: https://chromium-review.googlesource.com/1026203 Commit-Queue: Ken Rockot Reviewed-by: Dirk Pranke Cr-Commit-Position: refs/heads/master@{#554617} --- DEPS | 11 +++-- build/config/BUILD.gn | 8 +++- build/config/android/abi.gni | 5 +- build/config/android/config.gni | 13 ++++-- build/config/compiler/BUILD.gn | 17 ++++++- build/config/compiler/compiler.gni | 4 +- build/toolchain/toolchain.gni | 2 +- chrome/BUILD.gn | 5 +- mojo/edk/BUILD.gn | 73 ++++++++++++++++++++++++------ 9 files changed, 109 insertions(+), 29 deletions(-) diff --git a/DEPS b/DEPS index afee57c56d22b8..8efcbe6c9ac413 100644 --- a/DEPS +++ b/DEPS @@ -29,6 +29,7 @@ gclient_gn_args_file = 'src/build/config/gclient_args.gni' gclient_gn_args = [ 'checkout_android', + 'checkout_android_native_support', 'checkout_libaom', 'checkout_nacl', 'checkout_oculus_sdk', @@ -42,6 +43,10 @@ vars = { # purposes. 'checkout_configuration': 'default', + # Pull in Android native toolchain dependencies for Chrome OS too, so we can + # build ARC++ support libraries. + 'checkout_android_native_support': 'checkout_android or checkout_chromeos', + # By default, do not check out android sdk sources. This can be overridden # e.g. with custom_vars. 'checkout_android_sdk_sources': False, @@ -338,7 +343,7 @@ deps = { 'src/third_party/android_ndk': { 'url': Var('chromium_git') + '/android_ndk.git' + '@' + '635bc380968a76f6948fee65f80a0b28db53ae81', - 'condition': 'checkout_android', + 'condition': 'checkout_android_native_support', }, 'src/third_party/android_support_test_runner': { @@ -365,7 +370,7 @@ deps = { 'src/third_party/android_tools': { 'url': Var('chromium_git') + '/android_tools.git' + '@' + 'c22a664c39af72dd8f89200220713dcad811300a', - 'condition': 'checkout_android', + 'condition': 'checkout_android_native_support', }, 'src/third_party/android_sdk/public': { @@ -524,7 +529,7 @@ deps = { 'src/third_party/elfutils/src': { 'url': Var('chromium_git') + '/external/elfutils.git' + '@' + '249673729a7e5dbd5de4f3760bdcaa3d23d154d7', - 'condition': 'checkout_android', + 'condition': 'checkout_android_native_support', }, 'src/third_party/errorprone/lib': { diff --git a/build/config/BUILD.gn b/build/config/BUILD.gn index 717cc28fba1465..187f76cb86ae5f 100644 --- a/build/config/BUILD.gn +++ b/build/config/BUILD.gn @@ -78,7 +78,13 @@ config("feature_flags") { if (use_nss_certs) { defines += [ "USE_NSS_CERTS=1" ] } - if (use_ozone) { + if (use_ozone && !is_android) { + # Note that some Chrome OS builds unconditionally set |use_ozone| to true, + # but they also build some targets with the Android toolchain. This ensures + # that Android targets still build with USE_OZONE=0 in such cases. + # + # TODO(crbug.com/837032): Maybe this can be cleaned up if we can avoid + # setting use_ozone globally. defines += [ "USE_OZONE=1" ] } if (use_x11) { diff --git a/build/config/android/abi.gni b/build/config/android/abi.gni index 877c3f74629a1d..dc25b498d81d53 100644 --- a/build/config/android/abi.gni +++ b/build/config/android/abi.gni @@ -5,7 +5,10 @@ # Logic separated out from config.gni so that it can be used by compiler.gni # without introducing a circular dependency. -assert(is_android) +# NOTE: Because Chrome OS builds may depend on targets built with the Android +# toolchain, this GNI file may be read and processed from within Chrome OS +# toolchains. Checking |is_android| here would therefore be too restrictive. +assert(is_android || is_chromeos) declare_args() { # Adds intrumentation to each function. Writes a file with the order that diff --git a/build/config/android/config.gni b/build/config/android/config.gni index 4dcd5b116729b5..8b5d273cda97ab 100644 --- a/build/config/android/config.gni +++ b/build/config/android/config.gni @@ -4,7 +4,10 @@ # This file contains common system config stuff for the Android build. -if (is_android) { +# NOTE: Because Chrome OS builds may depend on targets built with the Android +# toolchain, this GNI file may be read and processed from within Chrome OS +# toolchains. Checking |is_android| here would therefore be too restrictive. +if (is_android || is_chromeos) { import("//build_overrides/build.gni") import("abi.gni") @@ -13,9 +16,11 @@ if (is_android) { # heavily but don't write gclient args files. import("//build/config/gclient_args.gni") - if (defined(checkout_android)) { - assert(checkout_android, - "target_os in your .gclient configuration must include android.") + if (defined(checkout_android_native_support)) { + assert(checkout_android_native_support, + "Missing native Android toolchain support. |target_os| in your " + + ".gclient configuration must include \"android\" and/or " + + "\"chromeos\".") } } diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn index ccc2bc80948e60..7ce97ad2eb19bb 100644 --- a/build/config/compiler/BUILD.gn +++ b/build/config/compiler/BUILD.gn @@ -416,7 +416,14 @@ config("compiler") { ldflags += [ "--gcc-toolchain=$_rebased_android_toolchain_root" ] } - if ((is_posix || is_fuchsia) && use_lld && !is_nacl) { + if (((is_posix || is_fuchsia) && use_lld && !is_nacl) || + (target_os == "chromeos" && is_android)) { + # NOTE: Some Chrome OS builds globally disable LLD, but they also build some + # targets against Android toolchains which should use LLD. Therefore we + # explicitly select LLD in these cases. + # + # TODO(https://crbug.com/837095): This should be cleaned up if/when LLD can + # work properly for Chrome OS builds. ldflags += [ "-fuse-ld=lld" ] if (current_cpu == "arm64") { # Reduce the page size from 65536 in order to reduce binary size slightly @@ -2116,7 +2123,13 @@ config("symbols") { } cflags += [ "-g2" ] } - if (use_debug_fission && !is_nacl) { + if (use_debug_fission && !is_nacl && !is_android) { + # NOTE: Some Chrome OS builds globally set |use_debug_fission| to true, + # but they also build some targets against Android toolchains which aren't + # compatible with it. + # + # TODO(https://crbug.com/837032): See if we can clean this up by e.g. not + # setting use_debug_fission globally. cflags += [ "-gsplit-dwarf" ] } asmflags = cflags diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni index a33d421b482016..79838c086a7f42 100644 --- a/build/config/compiler/compiler.gni +++ b/build/config/compiler/compiler.gni @@ -225,7 +225,9 @@ if (symbol_level == -1) { } # Assert that the configuration isn't going to hit https://crbug.com/648948. -assert(ignore_elf32_limitations || !is_android || +# An exception is made when target_os == "chromeos" as we only use the Android +# toolchain there to build relatively small binaries. +assert(ignore_elf32_limitations || !is_android || target_os == "chromeos" || (android_64bit_target_cpu && !build_apk_secondary_abi) || is_component_build || symbol_level < 2, "Android 32-bit non-component builds cannot have symbol_level=2 " + diff --git a/build/toolchain/toolchain.gni b/build/toolchain/toolchain.gni index cb0b9b0fab9500..21adefc825ca01 100644 --- a/build/toolchain/toolchain.gni +++ b/build/toolchain/toolchain.gni @@ -36,7 +36,7 @@ if (generate_linker_map) { assert( is_official_build, "Linker map files should only be generated when is_official_build = true") - assert(target_os == "android" || target_os == "linux", + assert(current_os == "android" || current_os == "linux", "Linker map files should only be generated for Android and Linux") } diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn index 009a281d50a2d9..721834cd7675be 100644 --- a/chrome/BUILD.gn +++ b/chrome/BUILD.gn @@ -299,7 +299,10 @@ if (!is_android && !is_mac) { } if (is_chromeos) { - data_deps += [ "//mojo/edk:mojo_core" ] + data_deps += [ + "//mojo/edk:mojo_core", + "//mojo/edk:mojo_core_for_arc", + ] } # These files are used by the installer so we need a public dep. diff --git a/mojo/edk/BUILD.gn b/mojo/edk/BUILD.gn index 4c4d92725ed030..8597307906bfb6 100644 --- a/mojo/edk/BUILD.gn +++ b/mojo/edk/BUILD.gn @@ -206,7 +206,7 @@ core_impl_source_set("impl_for_edk") { for_mojo_core = false } -if (is_chromeos || is_linux) { +if (is_chromeos || is_linux || is_android) { core_impl_source_set("impl_for_mojo_core") { for_mojo_core = true } @@ -223,26 +223,69 @@ if (is_chromeos || is_linux) { configs += [ ":export_only_thunks_api" ] } + if (is_chromeos) { + if (target_cpu == "arm" || target_cpu == "arm64") { + android32_toolchain = "android_clang_arm" + android64_toolchain = "android_clang_arm64" + } else { + android32_toolchain = "android_clang_x86" + android64_toolchain = "android_clang_x64" + } + + group("mojo_core_for_arc") { + deps = [ + ":mojo_core_arc32", + ":mojo_core_arc64", + ] + } + + copy("mojo_core_arc32") { + sources = [ + "${root_out_dir}/${android32_toolchain}/libmojo_core.so", + ] + outputs = [ + "${root_out_dir}/libmojo_core_arc32.so", + ] + deps = [ + ":mojo_core(//build/toolchain/android:${android32_toolchain})", + ] + } + + copy("mojo_core_arc64") { + sources = [ + "${root_out_dir}/${android64_toolchain}/libmojo_core.so", + ] + outputs = [ + "${root_out_dir}/libmojo_core_arc64.so", + ] + deps = [ + ":mojo_core(//build/toolchain/android:${android64_toolchain})", + ] + } + } + config("export_only_thunks_api") { ldflags = [ "-Wl,--version-script=" + rebase_path("//mojo/edk/export_only_thunks_api.lst") ] } - test("mojo_core_unittests") { - sources = [ - "mojo_core_unittest.cc", - "run_all_core_unittests.cc", - ] + if (is_chromeos || is_linux) { + test("mojo_core_unittests") { + sources = [ + "mojo_core_unittest.cc", + "run_all_core_unittests.cc", + ] - deps = [ - "//base", - "//base/test:test_support", - "//mojo/public/c/system", - "//testing/gtest", - ] + deps = [ + "//base", + "//base/test:test_support", + "//mojo/public/c/system", + "//testing/gtest", + ] - data_deps = [ - ":mojo_core", - ] + data_deps = [ + ":mojo_core", + ] + } } }