diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-28 06:49:32 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-28 06:49:32 +0000 |
commit | 3945dcb435eb9ebcad8ba582663fd50cb8a59126 (patch) | |
tree | 0b254a7086ed69182368da33a0a22b7e9c39436a /build/toolchain | |
parent | ddad0f776277c3b10f7c59ffe86423b6775f2a53 (diff) | |
download | chromium_src-3945dcb435eb9ebcad8ba582663fd50cb8a59126.zip chromium_src-3945dcb435eb9ebcad8ba582663fd50cb8a59126.tar.gz chromium_src-3945dcb435eb9ebcad8ba582663fd50cb8a59126.tar.bz2 |
This adds preliminary support for Android toolchains. The logic is copied from the current GYP build.
Refactors the toolchain definitions by adding an include file to help defining GCC toolchains. This eliminates most of the duplication on Linux and Android. Adds make_global_settings for most Linux and Mac builds that should match the GYP build (this will require some more passes to get every place to be an exact match).
Fixes Android build issues in WebKit. Fixes the definition of is_android.
Renames the Linux toolchains to use the GN name of the CPU architecture so one can refer to them without conditionals. Remove conditionals from BUILDCONFIG.gn
Adds the gyp_header variable to the help (it wasn't getting inserted into the list of available variables).
R=thakis@chromium.org
Review URL: https://codereview.chromium.org/117863003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242674 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/toolchain')
-rw-r--r-- | build/toolchain/android/BUILD.gn | 101 | ||||
-rw-r--r-- | build/toolchain/android/default_goma_for_android.py | 17 | ||||
-rw-r--r-- | build/toolchain/clang.gni | 35 | ||||
-rw-r--r-- | build/toolchain/gcc_toolchain.gni | 68 | ||||
-rw-r--r-- | build/toolchain/get_default_posix_goma_dir.py | 11 | ||||
-rw-r--r-- | build/toolchain/goma.gni | 54 | ||||
-rw-r--r-- | build/toolchain/linux/BUILD.gn | 220 | ||||
-rw-r--r-- | build/toolchain/linux/find_android_compilers.py | 31 | ||||
-rw-r--r-- | build/toolchain/mac/BUILD.gn | 21 |
9 files changed, 393 insertions, 165 deletions
diff --git a/build/toolchain/android/BUILD.gn b/build/toolchain/android/BUILD.gn new file mode 100644 index 0000000..7710cd0 --- /dev/null +++ b/build/toolchain/android/BUILD.gn @@ -0,0 +1,101 @@ +# 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("../clang.gni") +import("../goma.gni") +import("../gcc_toolchain.gni") + +# Get the location of the Android tools in our tree. +android_ndk_root = + rebase_path("//third_party/android_tools/ndk", ".", "") +android_sdk_root = + rebase_path("//third_party/android_tools/sdk", ".", "") + +# Get the Android version of the name of the build host's architecture. +if (build_cpu_arch == "x64") { + android_host_arch = "x86_64" +} else if (build_cpu_arch == "x86") { + android_host_arch = "x86" +} else { + assert(false, "Need Android toolchain support for your build OS.") +} + +if (is_gyp) { + # Set the compilers for GYP to use. This logic is only relevant to GYP where + # there is "a" target compiler. In native GN builds, we have separate + # compilers for the toolchains below, any or all of which could be active in + # any given build. + if (is_clang) { + # Set the GYP header for all toolchains when running under Clang. + gyp_header = make_clang_global_settings + } else { + # Find the compiler for GYP for non-Clang Android. + if (cpu_arch == "x86") { + android_toolchain_arch = "x86-4.6" + } else if (cpu_arch == "arm") { + android_toolchain_arch = "arm-linux-androideabi-4.6" + } else { + assert(false, "Need Android toolchain support for your platform.") + } + + android_toolchain = + "$android_ndk_root/toolchains/$android_toolchain_arch/prebuilt/$build_os-$android_host_arch/bin" + + # This script will find the compilers for the given Android toolchain + # directory. + # TODO(brettw) write this script which locates the Android compilers. + #android_compilers = exec_script("find_android_compilers.py", + # [android_toolchain], "value") + android_compilers = ["gcc", "g++", "gcc", "g++"] + gyp_header = + "'make_global_settings': [" + + "['CC', '" + android_compilers[0] + "']," + + "['CXX', '" + android_compilers[1] + "']," + + "['CC.host', '" + android_compilers[2] + "']," + + "['CXX.host', '" + android_compilers[3] + "']," + + "]," + } + + if (use_goma) { + # There is a TODO(yyanagisawa) in common.gypi about the make generator not + # supporting CC_wrapper without CC. As a result, we must add a condition + # when on the generator when we're not explicitly setting the variables + # above (which happens when gyp_header is empty at this point). + # + # GYP will interpret the file once for each generator, so we have to write + # this condition into the GYP file since the user could have more than one + # generator set. + if (gyp_header == "") { + gyp_header += + "'conditions':" + + "['\"<(GENERATOR)\"==\"ninja\"', {" + + make_goma_global_settings + + "}]," + } else { + gyp_header += make_goma_global_settings + } + } +} + +gcc_toolchain("x86") { + prefix = "$android_ndk_root/toolchains/x86-4.6/prebuilt/$build_os-$android_host_arch/bin/i686-linux-android-" + cc = prefix + "gcc" + cxx = prefix + "g++" + ar = prefix + "ar" + ld = cxx + + toolchain_cpu_arch = "x86" + toolchain_os = "android" +} + +gcc_toolchain("arm") { + prefix = "$android_ndk_root/toolchains/arm-linux-androideabi-4.6/prebuilt/$build_os-$android_host_arch/bin/arm-linux-androideabi-" + cc = prefix + "gcc" + cxx = prefix + "g++" + ar = prefix + "ar" + ld = cxx + + toolchain_cpu_arch = "arm" + toolchain_os = "android" +} diff --git a/build/toolchain/android/default_goma_for_android.py b/build/toolchain/android/default_goma_for_android.py new file mode 100644 index 0000000..f84246e --- /dev/null +++ b/build/toolchain/android/default_goma_for_android.py @@ -0,0 +1,17 @@ +# 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. + +# This script just returns the environment variable GOMA_DIR if there is one, +# which is the default goma location on Android. Returns the empty string if +# it's not defined. +# +# TODO(brettw) this should be rationalized with the way that other systems get +# their goma setup. + +import os + +if 'GOMA_DIR' in os.environ: + print '"' + os.environ['GOMA_DIR'] + '"' +else: + print '""' diff --git a/build/toolchain/clang.gni b/build/toolchain/clang.gni new file mode 100644 index 0000000..d45ea06 --- /dev/null +++ b/build/toolchain/clang.gni @@ -0,0 +1,35 @@ +# Copyright (c) 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. + +declare_args() { + use_clang_type_profiler = false +} + +if (is_clang) { + # Define "make_clang_dir" which is the directory relative to the source root + # of the clang directory we're using. This is used for defining the header + # for GYP so it must match the directory format of GYP (rather than using + # GN-style "//..." paths). + if (is_linux && use_clang_type_profiler) { + if (cpu_arch == "x64") { + make_clang_dir = "third_party/llvm-allocated-type/Linux_x64" + } else { + # 32-bit Clang is unsupported. It may not build. Put your 32-bit Clang in + # this directory at your own risk if needed for some purpose (e.g. to + # compare 32-bit and 64-bit behavior like memory usage). Any failure by + # this compiler should not close the tree. + make_clang_dir = "third_party/llvm-allocated-type/Linux_ia32" + } + } else { + make_clang_dir = "third_party/llvm-build/Release+Asserts" + } + + make_clang_global_settings = + "'make_global_settings': [" + + "['CC', '$make_clang_dir/bin/clang']," + + "['CXX', '$make_clang_dir/bin/clang++']," + + "['CC.host', '\$(CC)']," + + "['CXX.host', '\$(CXX)']," + + "]," +} diff --git a/build/toolchain/gcc_toolchain.gni b/build/toolchain/gcc_toolchain.gni new file mode 100644 index 0000000..e1f8a89 --- /dev/null +++ b/build/toolchain/gcc_toolchain.gni @@ -0,0 +1,68 @@ +# Copyright (c) 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. + +# This template defines a GCC toolchain. +# +# It requires the following variables specifying the executables to run: +# - cc +# - cxx +# - ar +# - ld +# and the following which is used in the toolchain_args +# - toolchain_cpu_arch (What "cpu_arch" should be set to when invoking a +# build using this toolchain.) +# - toolchain_os (What "os" should be set to when invoking a build using this +# toolchain.) +template("gcc_toolchain") { + toolchain(target_name) { + # Make these apply to all tools below. + lib_prefix = "-l" + lib_dir_prefix="-L" + + tool("cc") { + # cflags_pch_c + command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out" + description = "CC \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("cxx") { + # cflags_pch_cc + command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out" + description = "CXX \$out" + depfile = "\$out.d" + deps = "gcc" + } + tool("alink") { + command = "rm -f \$out && $ar rcs \$out \$in" + description = "AR \$out" + } + tool("solink") { + command = "if [ ! -e \$lib -o ! -e \${lib}.TOC ]; then $ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname -Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive \$libs && { readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.TOC; else $ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname -Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive \$libs && { readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.tmp && if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC ; fi; fi" + description = "SOLINK \$lib" + #pool = "link_pool" + restat = "1" + } + tool("link") { + command = "$ld \$ldflags -o \$out -Wl,--start-group \$in \$solibs -Wl,--end-group \$libs" + description = "LINK \$out" + #pool = "link_pool" + } + tool("stamp") { + command = "\${postbuilds}touch \$out" + description = "STAMP \$out" + } + tool("copy") { + command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)" + description = "COPY \$in \$out" + } + + # When invoking this toolchain not as the default one, these args will be + # passed to the build. They are ignored when this is the default toolchain. + toolchain_args() { + cpu_arch = toolchain_cpu_arch + os = toolchain_os + } + } +} diff --git a/build/toolchain/get_default_posix_goma_dir.py b/build/toolchain/get_default_posix_goma_dir.py new file mode 100644 index 0000000..2aa0267 --- /dev/null +++ b/build/toolchain/get_default_posix_goma_dir.py @@ -0,0 +1,11 @@ +# 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. + +# This script returns the default goma directory for Posix systems, which is +# relative to the user's home directory. On Windows, goma.gypi hardcodes a +# value. + +import os + +print '"' + os.environ['HOME'] + '/goma"' diff --git a/build/toolchain/goma.gni b/build/toolchain/goma.gni new file mode 100644 index 0000000..457b548 --- /dev/null +++ b/build/toolchain/goma.gni @@ -0,0 +1,54 @@ +# Copyright (c) 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. + +# Defines the configuration of Goma. +# +# This is currently designed to match the GYP build exactly, so as not to break +# people during the transition. +# +# TODO(brettw) make Android work like normal Linux. It's silly that Android has +# completely different logic for configuring Goma. + +declare_args() { + use_goma = false + + goma_dir = "" + + # Goma directory used by the Android build. Empty means use the GOMA_DIR + # environment variable. + # + # TODO(brettw) remove this and make it work like regular Linux. + android_goma_dir = "" +} + +# The Android GYP build has some logic that automatically turns on goma when +# the directory is set, but this isn't done for other platforms. +# TODO(brettw) rationalize all Linux-y platforms. +if (is_android && android_goma_dir != "") { + use_goma = true +} + +if (use_goma && goma_dir == "") { + # Set the default goma directory. This must be a character-for-character + # match for the GYP default or else the compilers for the different targets + # won't match and GYP will assert. + if (is_win) { + goma_dir = "c:\goma\goma-win" + } else if (is_android) { + goma_dir = exec_script("android/default_goma_for_android.py", [], "value") + } else { + goma_dir = exec_script("get_default_posix_goma_dir.py", [], "value") + } +} + +if (use_goma) { + # Define the toolchain for the GYP build when using goma. + make_goma_global_settings = + "'make_global_settings': [" + + "['CC_wrapper', '$goma_dir/gomacc']," + + "['CXX_wrapper', '$goma_dir/gomacc']," + + "['CC.host_wrapper', '$gomadir/gomacc']," + + "['CXX.host_wrapper', '$gomadir/gomacc']," + + "]," +} diff --git a/build/toolchain/linux/BUILD.gn b/build/toolchain/linux/BUILD.gn index 0532d80..393288b 100644 --- a/build/toolchain/linux/BUILD.gn +++ b/build/toolchain/linux/BUILD.gn @@ -1,180 +1,74 @@ -# Copyright (c) 2013 The Chromium Authors. All rights reserved. +# 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. -cc = "gcc" -cxx = "g++" -ar = "ar" -ld = cxx +import("../clang.gni") +import("../goma.gni") +import("../gcc_toolchain.gni") -# The toolchains below all issue the same commands with some different flags. -# TODO(brettw) it would be nice to have a different way to express this without -# so much duplication. -cc_command = "$cc -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_c -c \$in -o \$out" -cxx_command = "$cxx -MMD -MF \$out.d \$defines \$includes \$cflags \$cflags_cc -c \$in -o \$out" -alink_command = "rm -f \$out && $ar rcs \$out \$in" -solink_command = "if [ ! -e \$lib -o ! -e \${lib}.TOC ]; then $ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname -Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive \$libs && { readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.TOC; else $ld -shared \$ldflags -o \$lib -Wl,-soname=\$soname -Wl,--whole-archive \$in \$solibs -Wl,--no-whole-archive \$libs && { readelf -d \${lib} | grep SONAME ; nm -gD -f p \${lib} | cut -f1-2 -d' '; } > \${lib}.tmp && if ! cmp -s \${lib}.tmp \${lib}.TOC; then mv \${lib}.tmp \${lib}.TOC ; fi; fi" -link_command = "$ld \$ldflags -o \$out -Wl,--start-group \$in \$solibs -Wl,--end-group \$libs" -stamp_command = "\${postbuilds}touch \$out" -copy_command = "ln -f \$in \$out 2>/dev/null || (rm -rf \$out && cp -af \$in \$out)" - -# ARM -------------------------------------------------------------------------- - -cc = "arm-linux-gnueabi-gcc" -cxx = "arm-linux-gnueabi-g++" -ar = "arm-linux-gnueabi-ar" -ld = cxx - -toolchain("arm") { - # Make these apply to all tools below. - lib_prefix = "-l" - lib_dir_prefix="-L" - - tool("cc") { - # cflags_pch_c - command = cc_command - description = "CC \$out" - depfile = "\$out.d" - deps = "gcc" - } - tool("cxx") { - # cflags_pch_cc - command = cxx_command - description = "CXX \$out" - depfile = "\$out.d" - deps = "gcc" - } - tool("alink") { - command = alink_command - description = "AR \$out" - } - tool("solink") { - command = solink_command - description = "SOLINK \$lib" - #pool = "link_pool" - restat = "1" - } - tool("link") { - command = link_command - description = "LINK \$out" - #pool = "link_pool" - } - tool("stamp") { - command = stamp_command - description = "STAMP \$out" - } - tool("copy") { - command = copy_command - description = "COPY \$in \$out" +if (is_gyp) { + # Set the compilers for GYP to use. This logic is only relevant to GYP where + # there is "a" target compiler. In native GN builds, we have separate + # compilers for the toolchains below, any or all of which could be active in + # any given build. + if (is_clang) { + # Set the GYP header for all toolchains when running under Clang. + gyp_header = make_clang_global_settings + } else { + gyp_header = "" } - # When invoking this toolchain not as the default one, these args will be - # passed to the build. They are ignored when this is the default toolchain. - toolchain_args() { - cpu_arch = "arm" + if (use_goma) { + # There is a TODO(yyanagisawa) in common.gypi about the make generator not + # supporting CC_wrapper without CC. As a result, we must add a condition + # when on the generator when we're not explicitly setting the variables + # above (which happens when gyp_header is empty at this point). + # + # GYP will interpret the file once for each generator, so we have to write + # this condition into the GYP file since the user could have more than one + # generator set. + if (gyp_header == "") { + gyp_header += + "'conditions':" + + "['\"<(GENERATOR)\"==\"ninja\"', {" + + make_goma_global_settings + + "}]," + } else { + gyp_header += make_goma_global_settings + } } } -# 32-bit ----------------------------------------------------------------------- +# ARM -------------------------------------------------------------------------- -toolchain("32") { - # Make these apply to all tools below. - lib_prefix = "-l" - lib_dir_prefix="-L" +gcc_toolchain("arm") { + cc = "arm-linux-gnueabi-gcc" + cxx = "arm-linux-gnueabi-g++" + ar = "arm-linux-gnueabi-ar" + ld = cxx - tool("cc") { - # cflags_pch_c - command = cc_command - description = "CC \$out" - depfile = "\$out.d" - deps = "gcc" - } - tool("cxx") { - # cflags_pch_cc - command = cxx_command - description = "CXX \$out" - depfile = "\$out.d" - deps = "gcc" - } - tool("alink") { - command = alink_command - description = "AR \$out" - } - tool("solink") { - command = solink_command - description = "SOLINK \$lib" - #pool = "link_pool" - restat = "1" - } - tool("link") { - command = link_command - description = "LINK \$out" - #pool = "link_pool" - } - tool("stamp") { - command = stamp_command - description = "STAMP \$out" - } - tool("copy") { - command = copy_command - description = "COPY \$in \$out" - } - - # When invoking this toolchain not as the default one, these args will be - # passed to the build. They are ignored when this is the default toolchain. - toolchain_args() { - cpu_arch = "x86" - } + toolchain_cpu_arch = "arm" + toolchain_os = "linux" } -# 64-bit ----------------------------------------------------------------------- +# 32-bit ----------------------------------------------------------------------- -toolchain("64") { - # Make these apply to all tools below. - lib_prefix = "-l" - lib_dir_prefix="-L" +gcc_toolchain("x86") { + cc = "gcc" + cxx = "g++" + ar = "ar" + ld = cxx - tool("cc") { - # cflags_pch_c - command = cc_command - description = "CC \$out" - depfile = "\$out.d" - deps = "gcc" - } - tool("cxx") { - # cflags_pch_cc - command = cxx_command - description = "CXX \$out" - depfile = "\$out.d" - deps = "gcc" - } - tool("alink") { - command = alink_command - description = "AR \$out" - } - tool("solink") { - command = solink_command - description = "SOLINK \$lib" - #pool = "link_pool" - restat = "1" - } - tool("link") { - command = link_command - description = "LINK \$out" - #pool = "link_pool" - } - tool("stamp") { - command = stamp_command - description = "STAMP \$out" - } - tool("copy") { - command = copy_command - description = "COPY \$in \$out" - } + toolchain_cpu_arch = "x86" + toolchain_os = "linux" +} - # When invoking this toolchain not as the default one, these args will be - # passed to the build. They are ignored when this is the default toolchain. - toolchain_args() { - cpu_arch = "x64" - } +gcc_toolchain("x64") { + cc = "gcc" + cxx = "g++" + ar = "ar" + ld = cxx + + toolchain_cpu_arch = "x64" + toolchain_os = "linux" } diff --git a/build/toolchain/linux/find_android_compilers.py b/build/toolchain/linux/find_android_compilers.py new file mode 100644 index 0000000..7061ecc --- /dev/null +++ b/build/toolchain/linux/find_android_compilers.py @@ -0,0 +1,31 @@ +# 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. + +# This script locates the Android compilers given the bin directory of the +# android toolchain. + +import glob +import subprocess +import sys + +if len(sys.argv) != 2: + print "Error: expecting one argument of the android toolchain dir." + sys.exit(1) + +# TODO(brettw) this logic seems like a bad idea. It was copied from +# common.gypi. It seems like the toolchain should just know the name given the +# current platform rather than having to rely on glob. +android_toolchain = sys.argv[1] +cc = glob.glob(android_toolchain + "/*-gcc") +cxx = glob.glob(android_toolchain + "/*-g++") +if len(cc) != 1 or len(cxx) != 1: + print "Either none or more than one matching compiler." + sys.exit(1) + +# Get the host compilers from the current path. +which_gcc = subprocess.check_output(["which gcc"], shell=True).strip() +which_gxx = subprocess.check_output(["which g++"], shell=True).strip() + +print ('["' + cc[0] + '","' + cxx[0] + '","' + which_gcc + '","' + + which_gxx + '"]') diff --git a/build/toolchain/mac/BUILD.gn b/build/toolchain/mac/BUILD.gn index 4150ae6..612d8bf 100644 --- a/build/toolchain/mac/BUILD.gn +++ b/build/toolchain/mac/BUILD.gn @@ -2,11 +2,28 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +# TODO(brettw) Use "gcc_toolchain.gni" like the Linux toolchains. This requires +# some enhancements since the commands on Mac are slightly different than on +# Linux. + # Should only be running on Mac. assert(is_mac || is_ios) -cc = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang", ".", root_build_dir) -cxx = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang++", ".", root_build_dir) +# Clang variables. +import("../clang.gni") + +if (is_clang) { + cc = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang", ".", root_build_dir) + cxx = rebase_path("//third_party/llvm-build/Release+Asserts/bin/clang++", ".", root_build_dir) + + # Set the GYP header for all toolchains when running under Clang. + if (is_gyp) { + gyp_header = make_clang_global_settings + } +} else { + cc = "gcc" + cxx = "g++" +} ld = cxx # This will copy the gyp-mac-tool to the build directory. We pass in the source |