dart-sdk/build/toolchain/android/BUILD.gn
Zachary Anderson 6bf2c800fd Reland: [infra] Roll clang to match the version used by Flutter
Flutter uses the same clang toolchain as Fuchsia. This CL puts Dart
on that toolchain, as well. This roll should entail no changes to
glibc version requirements on Linux.

The Fuchsia buildtools distribute clang-format with the toolchain
rather than separately, so this CL introduces forwarding scripts
that are copied to the right place under //buildtools.

This CL sets the default for the number of workers in //tools/gn.py
to 1, as the newer GN version fails occasionally when run
concurrently with other invocations.

As Flutter does, this CL uses the clang toolchain to build for
Android. Thus, it is now possible to build for Android on MacOS.

This change is a prerequisite for assembling the SDK in GN
rather than with a python script:

https://codereview.chromium.org/2848943003/

and will be nicer for making prebuilt SDKs for Fuchsia.

Review-Url: https://codereview.chromium.org/2855283002 .
2017-05-03 15:42:46 -07:00

165 lines
5.5 KiB
Plaintext

# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/sysroot.gni") # Imports android/config.gni.
import("//build/toolchain/ccache.gni")
import("//build/toolchain/clang.gni")
import("//build/toolchain/goma.gni")
import("//build/toolchain/gcc_toolchain.gni")
# The Android GCC toolchains share most of the same parameters, so we have this
# wrapper around gcc_toolchain to avoid duplication of logic.
#
# Parameters:
# - android_ndk_sysroot
# Sysroot for this architecture.
# - android_ndk_lib_dir
# Subdirectory inside of android_ndk_sysroot where libs go.
# - tool_prefix
# Prefix to be added to the tool names.
# - toolchain_cpu
# Same as gcc_toolchain
template("android_gcc_toolchain") {
gcc_toolchain(target_name) {
# Make our manually injected libs relative to the build dir.
android_ndk_lib = rebase_path(
invoker.android_ndk_sysroot + "/" + invoker.android_ndk_lib_dir,
root_build_dir)
libs_section_prefix = "$android_ndk_lib/crtbegin_dynamic.o"
libs_section_postfix = "$android_ndk_lib/crtend_android.o"
solink_libs_section_prefix = "$android_ndk_lib/crtbegin_so.o"
solink_libs_section_postfix = "$android_ndk_lib/crtend_so.o"
# The tools should be run relative to the build dir.
tool_prefix = rebase_path(invoker.tool_prefix, root_build_dir)
if (use_goma) {
assert(!use_ccache, "Goma and ccache can't be used together.")
compiler_prefix = "$goma_dir/gomacc "
} else if (use_ccache) {
compiler_prefix = "ccache "
} else {
compiler_prefix = ""
}
is_clang = invoker.is_clang
if (is_clang) {
host_suffix = ""
if (host_os == "linux") {
host_suffix = "x86_64-linux"
} else if (host_os == "mac") {
host_suffix = "x86_64-darwin"
} else {
assert(false, "Unknown host")
}
prefix = rebase_path("//buildtools/toolchain/clang+llvm-$host_suffix/bin",
root_build_dir)
cc = compiler_prefix + prefix + "/clang"
cxx = compiler_prefix + prefix + "/clang++"
} else {
cc = compiler_prefix + tool_prefix + "gcc"
cxx = compiler_prefix + tool_prefix + "g++"
}
ar = tool_prefix + "ar"
ld = cxx
readelf = compiler_prefix + tool_prefix + "readelf"
nm = compiler_prefix + tool_prefix + "nm"
toolchain_os = "android"
toolchain_cpu = invoker.toolchain_cpu
# We make the assumption that the gcc_toolchain will produce a soname with
# the following definition.
soname = "{{target_output_name}}{{output_extension}}"
stripped_soname = "lib.stripped/${soname}"
temp_stripped_soname = "${stripped_soname}.tmp"
android_strip = "${tool_prefix}strip"
strip_command =
"$android_strip --strip-unneeded -o $temp_stripped_soname $soname"
replace_command = "if ! cmp -s $temp_stripped_soname $stripped_soname; then mv $temp_stripped_soname $stripped_soname; fi"
postsolink = "$strip_command && $replace_command"
solink_outputs = [ stripped_soname ]
default_output_extension = android_product_extension
# We make the assumption that the gcc_toolchain will produce an exe with
# the following definition.
exe = "{{root_out_dir}}/{{target_output_name}}{{output_extension}}"
stripped_exe = "exe.stripped/$exe"
postlink = "$android_strip --strip-unneeded -o $stripped_exe $exe"
link_outputs = [ stripped_exe ]
}
}
template("android_gcc_toolchains_helper") {
android_gcc_toolchain(target_name) {
android_ndk_sysroot = invoker.android_ndk_sysroot
android_ndk_lib_dir = invoker.android_ndk_lib_dir
tool_prefix = invoker.tool_prefix
toolchain_cpu = invoker.toolchain_cpu
}
android_gcc_toolchain("clang_$target_name") {
android_ndk_sysroot = invoker.android_ndk_sysroot
android_ndk_lib_dir = invoker.android_ndk_lib_dir
tool_prefix = invoker.tool_prefix
toolchain_cpu = invoker.toolchain_cpu
is_clang = true
}
}
android_gcc_toolchains_helper("x86") {
android_ndk_sysroot = "$android_ndk_root/$x86_android_sysroot_subdir"
android_ndk_lib_dir = "usr/lib"
tool_prefix = "$x86_android_toolchain_root/bin/i686-linux-android-"
toolchain_cpu = "x86"
}
android_gcc_toolchains_helper("arm") {
android_ndk_sysroot = "$android_ndk_root/$arm_android_sysroot_subdir"
android_ndk_lib_dir = "usr/lib"
tool_prefix = "$arm_android_toolchain_root/bin/arm-linux-androideabi-"
toolchain_cpu = "arm"
}
android_gcc_toolchains_helper("mipsel") {
android_ndk_sysroot = "$android_ndk_root/$mips_android_sysroot_subdir"
android_ndk_lib_dir = "usr/lib"
tool_prefix = "$mips_android_toolchain_root/bin/mipsel-linux-android-"
toolchain_cpu = "mipsel"
}
android_gcc_toolchains_helper("x64") {
android_ndk_sysroot = "$android_ndk_root/$x86_64_android_sysroot_subdir"
android_ndk_lib_dir = "usr/lib64"
tool_prefix = "$x86_64_android_toolchain_root/bin/x86_64-linux-android-"
toolchain_cpu = "x86_64"
}
android_gcc_toolchains_helper("arm64") {
android_ndk_sysroot = "$android_ndk_root/$arm64_android_sysroot_subdir"
android_ndk_lib_dir = "usr/lib"
tool_prefix = "$arm64_android_toolchain_root/bin/aarch64-linux-android-"
toolchain_cpu = "aarch64"
}
android_gcc_toolchains_helper("mips64el") {
android_ndk_sysroot = "$android_ndk_root/$mips64_android_sysroot_subdir"
android_ndk_lib_dir = "usr/lib64"
tool_prefix = "$mips64_android_toolchain_root/bin/mipsel-linux-android-"
toolchain_cpu = "mipsel64el"
}