Commit 86ee045d authored by brettw@chromium.org's avatar brettw@chromium.org

Make it possible for Android GN host builds to use Clang.

The problem was that the toolchain definitions had an is_clang block in them, but this is only evaluated in the context of the default toolchain (so false for and Android build). But then when we were re-evaluating the build config for the host compile, it was forcing clang to true which was causing the clang flags to be set.

This changes the way we default the is_clang value. Forcing it to true prevents it from being overridden manually. In some cases, like mac, this is pointless. In other cases like Linux, we may want to turn it on and off. Changing this definition allows us to toggle it on and off for different toolchains as we desire.

Ideally I think the way of defining toolchains would be different to make this a bit more flexible, I'll think about this. But this will work for now.

R=thakis@chromium.org

Review URL: https://codereview.chromium.org/385823002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282685 0039d316-1c4b-4281-b951-d872f2087c98
parent c5077667
...@@ -516,7 +516,7 @@ if (is_linux && current_toolchain == host_toolchain) { ...@@ -516,7 +516,7 @@ if (is_linux && current_toolchain == host_toolchain) {
if (is_clang) { if (is_clang) {
# See http://crbug.com/138571#c18 # See http://crbug.com/138571#c18
cflags += [ "-Wno-unused-value" ] cflags = [ "-Wno-unused-value" ]
} }
......
...@@ -31,7 +31,7 @@ declare_args() { ...@@ -31,7 +31,7 @@ declare_args() {
# Set to true when compiling with the Clang compiler. Typically this is used # Set to true when compiling with the Clang compiler. Typically this is used
# to configure warnings. # to configure warnings.
is_clang = false is_clang = (os == "mac" || os == "ios")
# Forces a 64-bit build on Windows. Does nothing on other platforms. Normally # Forces a 64-bit build on Windows. Does nothing on other platforms. Normally
# we build 32-bit on Windows regardless of the current host OS bit depth. # we build 32-bit on Windows regardless of the current host OS bit depth.
...@@ -101,9 +101,6 @@ if (os == "win") { ...@@ -101,9 +101,6 @@ if (os == "win") {
is_nacl = false is_nacl = false
is_posix = true is_posix = true
is_win = false is_win = false
if (!is_clang) {
is_clang = true # Always use clang on Mac.
}
} else if (os == "android") { } else if (os == "android") {
is_android = true is_android = true
is_chromeos = false is_chromeos = false
...@@ -142,10 +139,6 @@ if (os == "win") { ...@@ -142,10 +139,6 @@ if (os == "win") {
is_nacl = false is_nacl = false
is_posix = true is_posix = true
is_win = false is_win = false
if (!is_gyp_xcode_generator) {
# Always use clang on iOS when using ninja
is_clang = true
}
} else if (os == "linux") { } else if (os == "linux") {
is_android = false is_android = false
is_chromeos = false is_chromeos = false
...@@ -460,11 +453,22 @@ if (is_win) { ...@@ -460,11 +453,22 @@ if (is_win) {
set_default_toolchain("//build/toolchain/win:32") set_default_toolchain("//build/toolchain/win:32")
} }
} else if (is_android) { } else if (is_android) {
host_toolchain = "//build/toolchain/linux:$build_cpu_arch" # Use clang for the x86/64 Linux host builds.
# (Disabled until the Clang build works properly.)
#if (build_cpu_arch == "x86" || build_cpu_arch == "x64") {
# host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
#} else {
host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
#}
set_default_toolchain("//build/toolchain/android:$cpu_arch") set_default_toolchain("//build/toolchain/android:$cpu_arch")
} else if (is_linux) { } else if (is_linux) {
host_toolchain = "//build/toolchain/linux:$build_cpu_arch" if (is_clang) {
set_default_toolchain("//build/toolchain/linux:$cpu_arch") host_toolchain = "//build/toolchain/linux:clang_$build_cpu_arch"
set_default_toolchain("//build/toolchain/linux:clang_$cpu_arch")
} else {
host_toolchain = "//build/toolchain/linux:$build_cpu_arch"
set_default_toolchain("//build/toolchain/linux:$cpu_arch")
}
} else if (is_mac) { } else if (is_mac) {
host_toolchain = "//build/toolchain/mac:clang" host_toolchain = "//build/toolchain/mac:clang"
set_default_toolchain(host_toolchain) set_default_toolchain(host_toolchain)
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# This template defines a GCC toolchain. # This template defines a toolchain for something that works like gcc
# (including clang).
# #
# It requires the following variables specifying the executables to run: # It requires the following variables specifying the executables to run:
# - cc # - cc
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
# at the beginning and end for all targets in a toolchain. # at the beginning and end for all targets in a toolchain.
# - deps # - deps
# Just fowarded to the toolchain definition. # Just fowarded to the toolchain definition.
# - is_clang
template("gcc_toolchain") { template("gcc_toolchain") {
toolchain(target_name) { toolchain(target_name) {
assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value")
...@@ -108,6 +110,9 @@ template("gcc_toolchain") { ...@@ -108,6 +110,9 @@ template("gcc_toolchain") {
toolchain_args() { toolchain_args() {
cpu_arch = invoker.toolchain_cpu_arch cpu_arch = invoker.toolchain_cpu_arch
os = invoker.toolchain_os os = invoker.toolchain_os
if (defined(invoker.is_clang)) {
is_clang = invoker.is_clang
}
} }
if (defined(invoker.deps)) { if (defined(invoker.deps)) {
......
...@@ -15,52 +15,69 @@ gcc_toolchain("arm") { ...@@ -15,52 +15,69 @@ gcc_toolchain("arm") {
toolchain_cpu_arch = "arm" toolchain_cpu_arch = "arm"
toolchain_os = "linux" toolchain_os = "linux"
is_clang = false
} }
gcc_toolchain("x86") { gcc_toolchain("clang_x86") {
if (is_clang) { if (use_clang_type_profiler) {
if (use_clang_type_profiler) { prefix = rebase_path("//third_party/llvm-allocated-type/Linux_ia32/bin",
prefix = rebase_path("//third_party/llvm-allocated-type/Linux_ia32/bin", root_build_dir)
root_build_dir)
} else {
prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
root_build_dir)
}
cc = "$prefix/clang"
cxx = "$prefix/clang++"
} else { } else {
cc = "gcc" prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
cxx = "g++" root_build_dir)
} }
cc = "$prefix/clang"
cxx = "$prefix/clang++"
ar = "ar" ar = "ar"
ld = cxx ld = cxx
toolchain_cpu_arch = "x86" toolchain_cpu_arch = "x86"
toolchain_os = "linux" toolchain_os = "linux"
is_clang = true
} }
gcc_toolchain("x64") { gcc_toolchain("x86") {
if (is_clang) { cc = "gcc"
if (use_clang_type_profiler) { cxx = "g++"
prefix = rebase_path("//third_party/llvm-allocated-type/Linux_x64/bin",
root_build_dir) ar = "ar"
} else { ld = cxx
prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
root_build_dir) toolchain_cpu_arch = "x86"
} toolchain_os = "linux"
cc = "$prefix/clang" is_clang = false
cxx = "$prefix/clang++" }
gcc_toolchain("clang_x64") {
if (use_clang_type_profiler) {
prefix = rebase_path("//third_party/llvm-allocated-type/Linux_x64/bin",
root_build_dir)
} else { } else {
cc = "gcc" prefix = rebase_path("//third_party/llvm-build/Release+Asserts/bin",
cxx = "g++" root_build_dir)
} }
cc = "$prefix/clang"
cxx = "$prefix/clang++"
ar = "ar"
ld = cxx
toolchain_cpu_arch = "x64"
toolchain_os = "linux"
is_clang = true
}
gcc_toolchain("x64") {
cc = "gcc"
cxx = "g++"
ar = "ar" ar = "ar"
ld = cxx ld = cxx
toolchain_cpu_arch = "x64" toolchain_cpu_arch = "x64"
toolchain_os = "linux" toolchain_os = "linux"
is_clang = false
} }
gcc_toolchain("mipsel") { gcc_toolchain("mipsel") {
...@@ -71,4 +88,5 @@ gcc_toolchain("mipsel") { ...@@ -71,4 +88,5 @@ gcc_toolchain("mipsel") {
toolchain_cpu_arch = "mipsel" toolchain_cpu_arch = "mipsel"
toolchain_os = "linux" toolchain_os = "linux"
is_clang = false
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment