Rework the way ChromiumOS toolchains will work in GN.
This CL reworks the way ChromiumOS toolchains work in GN, in such a way that they might actually have all the flags they need for the ChromiumOS ebuild files to be able to set all of the flags it needs (though there are still some missing GN build_args). Specifically, the ebuild will now need to set the following in args.gn: host_toolchain = "//build/toolchain/cros:host" v8_snapshot_toolchain = "//build/toolchain/cros:v8_snapshot" in order to support boards other than the amd64-generic build. The ebuild should actually set these variables all the time; it just happens that the amd64-generic build will work at the moment without the variables, but that will not be guaranteed to remain true in the future. This CL also adds the following optional build args that do pretty much what you'd expect them to do: cros_target_ld, cros_target_extra_cflags, cros_target_extra_cppflags, cros_target_extra_cxx_flags, cros_target_extra_ldflags, cros_host_ar, cros_host_cc, cros_host_cxx, cros_host_ld, cros_host_is_clang, cros_host_extra_cflags, cros_host_extra_cppflags, cros_host_extra_cxx_flags, cros_host_extra_ldflags, cros_v8_snapshot_ar, cros_v8_snapshot_cc, cros_v8_snapshot_cxx, cros_v8_snapshot_ld, cros_v8_snapshot_extra_cflags, cros_v8_snapshot_extra_cppflags, cros_v8_snapshot_extra_cxx_flags, cros_v8_snapshot_extra_ldflags This CL should be backwards-compatible with the existing linux desktop ChromiumOS builds and the amd64-generic simplechrome/ebuild (i.e., it can be landed and reverted w/o requiring any other changes to be made). It is a big hammer intended to un-block the ChromiumOS GN migration while we continue thinking about how to best support ChromiumOS. R=stevenjb@chromium.org, brettw@chromium.org BUG=608596, 595653 Review-Url: https://codereview.chromium.org/1983613002 Cr-Original-Commit-Position: refs/heads/master@{#394534} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: 8ad2f49335feaddddbd3f318fc6f4d13eb52760b
This commit is contained in:
Родитель
8fe3dd493e
Коммит
5cb2ea1147
|
@ -36,36 +36,112 @@ import("//build/toolchain/gcc_toolchain.gni")
|
|||
|
||||
declare_args() {
|
||||
# These must be specified for a board-specific build.
|
||||
cros_target_cc = ""
|
||||
cros_target_cxx = ""
|
||||
cros_target_ar = ""
|
||||
cros_target_ar = "ar"
|
||||
cros_target_cc = "gcc"
|
||||
cros_target_cxx = "g++"
|
||||
cros_target_ld = ""
|
||||
|
||||
# These can be optionally set.
|
||||
cros_target_extra_cflags = ""
|
||||
cros_target_extra_cppflags = ""
|
||||
cros_target_extra_cxxflags = ""
|
||||
cros_target_extra_ldflags = ""
|
||||
|
||||
# is_clang is used instead of cros_target_is_clang
|
||||
|
||||
cros_host_ar = "ar"
|
||||
cros_host_cc = "gcc"
|
||||
cros_host_cxx = "g++"
|
||||
cros_host_ld = ""
|
||||
cros_host_extra_cflags = ""
|
||||
cros_host_extra_cppflags = ""
|
||||
cros_host_extra_cxxflags = ""
|
||||
cros_host_extra_ldflags = ""
|
||||
cros_host_is_clang = false
|
||||
|
||||
cros_v8_snapshot_ar = "ar"
|
||||
cros_v8_snapshot_cc = "gcc"
|
||||
cros_v8_snapshot_cxx = "g++"
|
||||
cros_v8_snapshot_ld = ""
|
||||
cros_v8_snapshot_extra_cflags = ""
|
||||
cros_v8_snapshot_extra_cppflags = ""
|
||||
cros_v8_snapshot_extra_cxxflags = ""
|
||||
cros_v8_snapshot_extra_ldflags = ""
|
||||
cros_v8_snapshot_is_clang = false
|
||||
}
|
||||
|
||||
# TODO(dpranke): Delete this after we get rid of the reference to
|
||||
# build/toolchain/cros:clang_target in BUILDCONFIG.gn
|
||||
clang_toolchain("clang_target") {
|
||||
toolchain_cpu = target_cpu
|
||||
toolchain_os = "linux"
|
||||
}
|
||||
|
||||
gcc_toolchain("target") {
|
||||
# These defaults permit building on a Linux host as described above.
|
||||
cc = "gcc"
|
||||
cxx = "g++"
|
||||
ar = "ar"
|
||||
|
||||
# But to build for a specific board, the cros_* args will need to be defined.
|
||||
if (cros_target_cc != "") {
|
||||
cc = "${cros_target_cc}"
|
||||
}
|
||||
if (cros_target_cxx != "") {
|
||||
cxx = "${cros_target_cxx}"
|
||||
}
|
||||
if (cros_target_ar != "") {
|
||||
ar = "${cros_target_ar}"
|
||||
}
|
||||
# These are args for the template.
|
||||
ar = cros_target_ar
|
||||
cc = cros_target_cc
|
||||
cxx = cros_target_cxx
|
||||
ld = cxx
|
||||
if (cros_target_ld != "") {
|
||||
ld = cros_target_ld
|
||||
}
|
||||
extra_cflags = cros_target_extra_cflags
|
||||
extra_cppflags = cros_target_extra_cppflags
|
||||
extra_cxxflags = cros_target_extra_cxxflags
|
||||
extra_ldflags = cros_target_extra_ldflags
|
||||
|
||||
# These are passed through as toolchain_args.
|
||||
cc_wrapper = ""
|
||||
is_clang = is_clang
|
||||
toolchain_cpu = target_cpu
|
||||
toolchain_os = "linux"
|
||||
is_clang = is_clang
|
||||
cc_wrapper = ""
|
||||
}
|
||||
|
||||
gcc_toolchain("host") {
|
||||
# These are args for the template.
|
||||
ar = cros_host_ar
|
||||
cc = cros_host_cc
|
||||
cxx = cros_host_cxx
|
||||
ld = cxx
|
||||
if (cros_host_ld != "") {
|
||||
ld = cros_host_ld
|
||||
}
|
||||
extra_cflags = cros_host_extra_cflags
|
||||
extra_cppflags = cros_host_extra_cppflags
|
||||
extra_cxxflags = cros_host_extra_cxxflags
|
||||
extra_ldflags = cros_host_extra_ldflags
|
||||
|
||||
# These are passed through as toolchain_args.
|
||||
cc_wrapper = ""
|
||||
is_clang = cros_host_is_clang
|
||||
toolchain_cpu = host_cpu
|
||||
toolchain_os = "linux"
|
||||
use_sysroot = false
|
||||
}
|
||||
|
||||
gcc_toolchain("v8_snapshot") {
|
||||
# These are args for the template.
|
||||
ar = cros_v8_snapshot_ar
|
||||
cc = cros_v8_snapshot_cc
|
||||
cxx = cros_v8_snapshot_cxx
|
||||
ld = cxx
|
||||
if (cros_v8_snapshot_ld != "") {
|
||||
ld = cros_v8_snapshot_ld
|
||||
}
|
||||
extra_cflags = cros_v8_snapshot_extra_cflags
|
||||
extra_cppflags = cros_v8_snapshot_extra_cppflags
|
||||
extra_cxxflags = cros_v8_snapshot_extra_cxxflags
|
||||
extra_ldflags = cros_v8_snapshot_extra_ldflags
|
||||
|
||||
# These are passed through as toolchain_args.
|
||||
cc_wrapper = ""
|
||||
is_clang = cros_v8_snapshot_is_clang
|
||||
if (target_cpu == "x86" || target_cpu == "arm" || target_cpu == "mipsel") {
|
||||
toolchain_cpu = "x86"
|
||||
} else {
|
||||
toolchain_cpu = "x64"
|
||||
}
|
||||
toolchain_os = "linux"
|
||||
use_sysroot = false
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ if (allow_posix_link_time_opt || is_cfi) {
|
|||
# (including clang).
|
||||
#
|
||||
# It requires the following variables specifying the executables to run:
|
||||
# - ar
|
||||
# - cc
|
||||
# - cxx
|
||||
# - ar
|
||||
# - ld
|
||||
# and the following which is used in the toolchain_args
|
||||
# - toolchain_cpu (What "current_cpu" should be set to when invoking a
|
||||
|
@ -34,6 +34,18 @@ if (allow_posix_link_time_opt || is_cfi) {
|
|||
#
|
||||
# Optional parameters that control the tools:
|
||||
#
|
||||
# - extra_cflags
|
||||
# Extra flags to be appended when compiling C files (but not C++ files).
|
||||
# - extra_cppflags
|
||||
# Extra flags to be appended when compiling both C and C++ files. "CPP"
|
||||
# stands for "C PreProcessor" in this context, although it can be
|
||||
# used for non-preprocessor flags as well. Not to be confused with
|
||||
# "CXX" (which follows).
|
||||
# - extra_cxxflags
|
||||
# Extra flags to be appended when compiling C++ files (but not C files).
|
||||
# - extra_ldflags
|
||||
# Extra flags to be appended when linking
|
||||
#
|
||||
# - libs_section_prefix
|
||||
# - libs_section_postfix
|
||||
# The contents of these strings, if specified, will be placed around
|
||||
|
@ -94,9 +106,9 @@ if (allow_posix_link_time_opt || is_cfi) {
|
|||
# toolchain has a custom link step that is not actually using Gold.
|
||||
template("gcc_toolchain") {
|
||||
toolchain(target_name) {
|
||||
assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value")
|
||||
assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value")
|
||||
assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value")
|
||||
assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value")
|
||||
assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value")
|
||||
assert(defined(invoker.toolchain_cpu),
|
||||
"gcc_toolchain() must specify a \"toolchain_cpu\"")
|
||||
|
@ -180,6 +192,30 @@ template("gcc_toolchain") {
|
|||
solink_libs_section_postfix = ""
|
||||
}
|
||||
|
||||
if (defined(invoker.extra_cflags) && invoker.extra_cflags != "") {
|
||||
extra_cflags = " " + invoker.extra_cflags
|
||||
} else {
|
||||
extra_cflags = ""
|
||||
}
|
||||
|
||||
if (defined(invoker.extra_cppflags) && invoker.extra_cppflags != "") {
|
||||
extra_cppflags = " " + invoker.extra_cppflags
|
||||
} else {
|
||||
extra_cppflags = ""
|
||||
}
|
||||
|
||||
if (defined(invoker.extra_cxxflags) && invoker.extra_cxxflags != "") {
|
||||
extra_cxxflags = " " + invoker.extra_cxxflags
|
||||
} else {
|
||||
extra_cxxflags = ""
|
||||
}
|
||||
|
||||
if (defined(invoker.extra_ldflags) && invoker.extra_ldflags != "") {
|
||||
extra_ldflags = " " + invoker.extra_ldflags
|
||||
} else {
|
||||
extra_ldflags = ""
|
||||
}
|
||||
|
||||
# These library switches can apply to all tools below.
|
||||
lib_switch = "-l"
|
||||
lib_dir_switch = "-L"
|
||||
|
@ -189,7 +225,7 @@ template("gcc_toolchain") {
|
|||
|
||||
tool("cc") {
|
||||
depfile = "{{output}}.d"
|
||||
command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}} -c {{source}} -o {{output}}"
|
||||
command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}${extra_cppflags}${extra_cflags} -c {{source}} -o {{output}}"
|
||||
depsformat = "gcc"
|
||||
description = "CC {{output}}"
|
||||
outputs = [
|
||||
|
@ -199,7 +235,7 @@ template("gcc_toolchain") {
|
|||
|
||||
tool("cxx") {
|
||||
depfile = "{{output}}.d"
|
||||
command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}} -c {{source}} -o {{output}}"
|
||||
command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -o {{output}}"
|
||||
depsformat = "gcc"
|
||||
description = "CXX {{output}}"
|
||||
outputs = [
|
||||
|
@ -257,7 +293,7 @@ template("gcc_toolchain") {
|
|||
# .TOC file, overwrite it, otherwise, don't change it.
|
||||
tocfile = sofile + ".TOC"
|
||||
|
||||
link_command = "$ld -shared {{ldflags}} -o \"$unstripped_sofile\" -Wl,-soname=\"$soname\" @\"$rspfile\""
|
||||
link_command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" -Wl,-soname=\"$soname\" @\"$rspfile\""
|
||||
|
||||
assert(defined(readelf), "to solink you must have a readelf")
|
||||
assert(defined(nm), "to solink you must have an nm")
|
||||
|
@ -317,7 +353,7 @@ template("gcc_toolchain") {
|
|||
unstripped_sofile = sofile
|
||||
}
|
||||
|
||||
command = "$ld -shared {{ldflags}} -o \"$unstripped_sofile\" -Wl,-soname=\"$soname\" @\"$rspfile\""
|
||||
command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" -Wl,-soname=\"$soname\" @\"$rspfile\""
|
||||
|
||||
if (defined(invoker.strip)) {
|
||||
strip_command = "${invoker.strip} --strip-unneeded -o \"$sofile\" \"$unstripped_sofile\""
|
||||
|
@ -368,7 +404,7 @@ template("gcc_toolchain") {
|
|||
unstripped_outfile = "{{root_out_dir}}/exe.unstripped/$exename"
|
||||
}
|
||||
|
||||
command = "$ld {{ldflags}} -o \"$unstripped_outfile\" -Wl,--start-group @\"$rspfile\" {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix"
|
||||
command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" -Wl,--start-group @\"$rspfile\" {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix"
|
||||
if (defined(invoker.strip)) {
|
||||
link_wrapper =
|
||||
rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir)
|
||||
|
@ -428,6 +464,9 @@ template("gcc_toolchain") {
|
|||
if (defined(invoker.use_gold)) {
|
||||
use_gold = invoker.use_gold
|
||||
}
|
||||
if (defined(invoker.use_sysroot)) {
|
||||
use_sysroot = invoker.use_sysroot
|
||||
}
|
||||
|
||||
if (defined(invoker.clear_sanitizers) && invoker.clear_sanitizers) {
|
||||
is_asan = false
|
||||
|
|
Загрузка…
Ссылка в новой задаче