From 7aad03d639856da4ff958121b3e4187ea75a81a5 Mon Sep 17 00:00:00 2001 From: James Robinson Date: Fri, 19 Feb 2016 14:05:21 -0800 Subject: [PATCH] Enable building for Android using clang for target builds --- .../src/flutter/build/config/BUILDCONFIG.gn | 6 ++- .../flutter/build/config/compiler/BUILD.gn | 19 ++------- .../flutter/build/toolchain/android/BUILD.gn | 42 +++++++++++++++---- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/engine/src/flutter/build/config/BUILDCONFIG.gn b/engine/src/flutter/build/config/BUILDCONFIG.gn index a691d132d6..b4ac21d6ab 100644 --- a/engine/src/flutter/build/config/BUILDCONFIG.gn +++ b/engine/src/flutter/build/config/BUILDCONFIG.gn @@ -581,7 +581,11 @@ if (is_win) { } else { assert(false, "Unknown host for android cross compile") } - set_default_toolchain("//build/toolchain/android:$current_cpu") + if (is_clang) { + set_default_toolchain("//build/toolchain/android:clang_$current_cpu") + } else { + set_default_toolchain("//build/toolchain/android:$current_cpu") + } } else if (is_linux) { if (is_clang) { host_toolchain = "//build/toolchain/linux:clang_$host_cpu" diff --git a/engine/src/flutter/build/config/compiler/BUILD.gn b/engine/src/flutter/build/config/compiler/BUILD.gn index 93182b74a0..8028ffb091 100644 --- a/engine/src/flutter/build/config/compiler/BUILD.gn +++ b/engine/src/flutter/build/config/compiler/BUILD.gn @@ -573,11 +573,11 @@ config("compiler") { if (is_clang) { if (current_cpu == "arm") { - cflags += [ "-target arm-linux-androideabi" ] - ldflags += [ "-target arm-linux-androideabi" ] + cflags += [ "--target=arm-linux-androideabi" ] + ldflags += [ "--target=arm-linux-androideabi" ] } else if (current_cpu == "x86") { - cflags += [ "-target x86-linux-androideabi" ] - ldflags += [ "-target x86-linux-androideabi" ] + cflags += [ "--target=x86-linux-androideabi" ] + ldflags += [ "--target=x86-linux-androideabi" ] } } } @@ -843,9 +843,6 @@ if (is_win) { default_warning_flags_cc += [ # See comment for -Wno-c++11-narrowing. "-Wno-narrowing", - - # TODO(thakis): Remove, http://crbug.com/263960 - "-Wno-literal-suffix", ] } @@ -905,14 +902,6 @@ if (is_clang) { # code generated by flex (used in angle) contains that keyword. # http://crbug.com/255186 "-Wno-deprecated-register", - - # TODO(thakis): This used to be implied by -Wno-unused-function, - # which we no longer use. Check if it makes sense to remove - # this as well. http://crbug.com/316352 - "-Wno-unneeded-internal-declaration", - - # TODO(thakis): Remove, http://crbug.com/263960 - "-Wno-reserved-user-defined-literal", ] # NaCl's Clang compiler and Chrome's hermetic Clang compiler will almost diff --git a/engine/src/flutter/build/toolchain/android/BUILD.gn b/engine/src/flutter/build/toolchain/android/BUILD.gn index 087f04b350..e543fc66f5 100644 --- a/engine/src/flutter/build/toolchain/android/BUILD.gn +++ b/engine/src/flutter/build/toolchain/android/BUILD.gn @@ -45,8 +45,18 @@ template("android_gcc_toolchain") { compiler_prefix = "" } - cc = compiler_prefix + tool_prefix + "gcc" - cxx = compiler_prefix + tool_prefix + "g++" + is_clang = invoker.is_clang + if (is_clang) { + prefix = rebase_path("//third_party/llvm-build/Release+Asserts/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" @@ -80,7 +90,23 @@ template("android_gcc_toolchain") { } } -android_gcc_toolchain("x86") { +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" @@ -88,7 +114,7 @@ android_gcc_toolchain("x86") { toolchain_cpu = "x86" } -android_gcc_toolchain("arm") { +android_gcc_toolchains_helper("arm") { android_ndk_sysroot = "$android_ndk_root/$arm_android_sysroot_subdir" android_ndk_lib_dir = "usr/lib" @@ -96,7 +122,7 @@ android_gcc_toolchain("arm") { toolchain_cpu = "arm" } -android_gcc_toolchain("mipsel") { +android_gcc_toolchains_helper("mipsel") { android_ndk_sysroot = "$android_ndk_root/$mips_android_sysroot_subdir" android_ndk_lib_dir = "usr/lib" @@ -104,7 +130,7 @@ android_gcc_toolchain("mipsel") { toolchain_cpu = "mipsel" } -android_gcc_toolchain("x64") { +android_gcc_toolchains_helper("x64") { android_ndk_sysroot = "$android_ndk_root/$x86_64_android_sysroot_subdir" android_ndk_lib_dir = "usr/lib64" @@ -112,7 +138,7 @@ android_gcc_toolchain("x64") { toolchain_cpu = "x86_64" } -android_gcc_toolchain("arm64") { +android_gcc_toolchains_helper("arm64") { android_ndk_sysroot = "$android_ndk_root/$arm64_android_sysroot_subdir" android_ndk_lib_dir = "usr/lib" @@ -120,7 +146,7 @@ android_gcc_toolchain("arm64") { toolchain_cpu = "aarch64" } -android_gcc_toolchain("mips64el") { +android_gcc_toolchains_helper("mips64el") { android_ndk_sysroot = "$android_ndk_root/$mips64_android_sysroot_subdir" android_ndk_lib_dir = "usr/lib64"