| OLD | NEW |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import("//build/config/clang/clang.gni") | 5 import("//build/config/clang/clang.gni") |
| 6 import("//build/config/nacl/config.gni") | 6 import("//build/config/nacl/config.gni") |
| 7 import("//build/config/sanitizers/sanitizers.gni") | 7 import("//build/config/sanitizers/sanitizers.gni") |
| 8 import("//build/config/v8_target_cpu.gni") | 8 import("//build/config/v8_target_cpu.gni") |
| 9 import("//build/toolchain/cc_wrapper.gni") | 9 import("//build/toolchain/cc_wrapper.gni") |
| 10 import("//build/toolchain/goma.gni") | 10 import("//build/toolchain/goma.gni") |
| 11 import("//build/toolchain/toolchain.gni") | 11 import("//build/toolchain/toolchain.gni") |
| 12 | 12 |
| 13 # This template defines a toolchain for something that works like gcc | 13 # This template defines a toolchain for something that works like gcc |
| 14 # (including clang). | 14 # (including clang). |
| 15 # | 15 # |
| 16 # It requires the following variables specifying the executables to run: | 16 # It requires the following variables specifying the executables to run: |
| 17 # - ar | 17 # - ar |
| 18 # - cc | 18 # - cc |
| 19 # - cxx | 19 # - cxx |
| 20 # - ld | 20 # - ld |
| 21 # and the following which is used in the toolchain_args | |
| 22 # - toolchain_cpu (What "current_cpu" should be set to when invoking a | |
| 23 # build using this toolchain.) | |
| 24 # - toolchain_os (What "current_os" should be set to when invoking a | |
| 25 # build using this toolchain.) | |
| 26 # | 21 # |
| 27 # Optional parameters that control the tools: | 22 # Optional parameters that control the tools: |
| 28 # | 23 # |
| 29 # - extra_cflags | 24 # - extra_cflags |
| 30 # Extra flags to be appended when compiling C files (but not C++ files). | 25 # Extra flags to be appended when compiling C files (but not C++ files). |
| 31 # - extra_cppflags | 26 # - extra_cppflags |
| 32 # Extra flags to be appended when compiling both C and C++ files. "CPP" | 27 # Extra flags to be appended when compiling both C and C++ files. "CPP" |
| 33 # stands for "C PreProcessor" in this context, although it can be | 28 # stands for "C PreProcessor" in this context, although it can be |
| 34 # used for non-preprocessor flags as well. Not to be confused with | 29 # used for non-preprocessor flags as well. Not to be confused with |
| 35 # "CXX" (which follows). | 30 # "CXX" (which follows). |
| (...skipping 29 matching lines...) Expand all Loading... |
| 65 # to the toolchain. It can be used to force recompiles whenever a | 60 # to the toolchain. It can be used to force recompiles whenever a |
| 66 # toolchain is updated. | 61 # toolchain is updated. |
| 67 # - shlib_extension | 62 # - shlib_extension |
| 68 # If this string is specified it will be used for the file extension | 63 # If this string is specified it will be used for the file extension |
| 69 # for a shared library, rather than default value specified in | 64 # for a shared library, rather than default value specified in |
| 70 # toolchain.gni | 65 # toolchain.gni |
| 71 # - strip | 66 # - strip |
| 72 # Location of the strip executable. When specified, strip will be run on | 67 # Location of the strip executable. When specified, strip will be run on |
| 73 # all shared libraries and executables as they are built. The pre-stripped | 68 # all shared libraries and executables as they are built. The pre-stripped |
| 74 # artifacts will be put in lib.unstripped/ and exe.unstripped/. | 69 # artifacts will be put in lib.unstripped/ and exe.unstripped/. |
| 75 # | |
| 76 # Optional build argument controls. | |
| 77 # | |
| 78 # - clear_sanitizers | |
| 79 # When set to true, is_asan, is_msan, etc.will all be set to false. Often | |
| 80 # secondary toolchains do not want to run with sanitizers. | |
| 81 # - is_clang | |
| 82 # Whether to use clang instead of gcc. | |
| 83 # - is_component_build | |
| 84 # Whether to forcibly enable or disable component builds for this | |
| 85 # toolchain; if not specified, the toolchain will inherit the | |
| 86 # default setting. | |
| 87 # - is_nacl_glibc | |
| 88 # Whether NaCl code is built using Glibc instead of Newlib. | |
| 89 # - cc_wrapper | |
| 90 # Override the global cc_wrapper setting. e.g. "ccache" or "icecc". | |
| 91 # useful to opt-out of cc_wrapper in a particular toolchain by setting | |
| 92 # cc_wrapper = "" in it. | |
| 93 # - use_debug_fission | |
| 94 # Override the global use_debug_fission setting, useful if the particular | |
| 95 # toolchain should not be generating split-dwarf code. | |
| 96 # - use_goma | |
| 97 # Override the global use_goma setting, useful to opt-out of goma in a | |
| 98 # particular toolchain by setting use_gome = false in it. | |
| 99 # - use_gold | |
| 100 # Override the global use_gold setting, useful if the particular | |
| 101 # toolchain has a custom link step that is not actually using Gold. | |
| 102 # - v8_toolchain_cpu | |
| 103 # If defined, set v8_current_cpu to this, else set v8_current_cpu | |
| 104 # to current_cpu. | |
| 105 template("gcc_toolchain") { | 70 template("gcc_toolchain") { |
| 106 toolchain(target_name) { | 71 toolchain(target_name) { |
| 107 assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value") | 72 assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value") |
| 108 assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") | 73 assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") |
| 109 assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") | 74 assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") |
| 110 assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value") | 75 assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value") |
| 111 assert(defined(invoker.toolchain_cpu), | |
| 112 "gcc_toolchain() must specify a \"toolchain_cpu\"") | |
| 113 assert(defined(invoker.toolchain_os), | |
| 114 "gcc_toolchain() must specify a \"toolchain_os\"") | |
| 115 | |
| 116 if (defined(invoker.cc_wrapper)) { | |
| 117 cc_wrapper = invoker.cc_wrapper | |
| 118 } | |
| 119 if (defined(invoker.use_goma)) { | |
| 120 use_goma = invoker.use_goma | |
| 121 } | |
| 122 if (use_goma) { | |
| 123 assert(cc_wrapper == "", "Goma and cc_wrapper can't be used together.") | |
| 124 compiler_prefix = "$goma_dir/gomacc " | |
| 125 } else if (cc_wrapper != "") { | |
| 126 compiler_prefix = cc_wrapper + " " | |
| 127 } else { | |
| 128 compiler_prefix = "" | |
| 129 } | |
| 130 | 76 |
| 131 # This define changes when the toolchain changes, forcing a rebuild. | 77 # This define changes when the toolchain changes, forcing a rebuild. |
| 132 # Nothing should ever use this define. | 78 # Nothing should ever use this define. |
| 133 if (defined(invoker.rebuild_define)) { | 79 if (defined(invoker.rebuild_define)) { |
| 134 rebuild_string = "-D" + invoker.rebuild_define + " " | 80 rebuild_string = "-D" + invoker.rebuild_define + " " |
| 135 } else { | 81 } else { |
| 136 rebuild_string = "" | 82 rebuild_string = "" |
| 137 } | 83 } |
| 138 | 84 |
| 85 # GN's syntax can't handle more than one scope dereference at once, like |
| 86 # "invoker.toolchain_args.foo", so make a temporary to hold the toolchain |
| 87 # args so we can do "invoker_toolchain_args.foo". |
| 88 assert(defined(invoker.toolchain_args), |
| 89 "Toolchains must specify toolchain_args") |
| 90 invoker_toolchain_args = invoker.toolchain_args |
| 91 assert(defined(invoker_toolchain_args.current_cpu), |
| 92 "toolchain_args must specify a current_cpu") |
| 93 assert(defined(invoker_toolchain_args.current_os), |
| 94 "toolchain_args must specify a current_os") |
| 95 |
| 96 # When invoking this toolchain not as the default one, these args will be |
| 97 # passed to the build. They are ignored when this is the default toolchain. |
| 98 toolchain_args = { |
| 99 # Populate toolchain args from the invoker. |
| 100 forward_variables_from(invoker_toolchain_args, "*") |
| 101 |
| 102 # These values need to be passed through unchanged to all secondary |
| 103 # toolchains. BUILDCONFIG.gn sets some defaults based on the values of |
| 104 # the operating system and compiler, and we want to force the values to |
| 105 # be consistent if re-running the computation in another context leads |
| 106 # to different defaults. |
| 107 host_toolchain = host_toolchain |
| 108 target_os = target_os |
| 109 target_cpu = target_cpu |
| 110 |
| 111 if (!defined(invoker_toolchain_args.v8_current_cpu)) { |
| 112 v8_current_cpu = invoker_toolchain_args.current_cpu |
| 113 } |
| 114 } |
| 115 |
| 116 # When the invoker has explicitly overridden use_goma or cc_wrapper in the |
| 117 # toolchain args, use those values, otherwise default to the global one. |
| 118 # This works because the only reasonable override that toolchains might |
| 119 # supply for these values are to force-disable them. |
| 120 if (defined(toolchain_args.use_goma)) { |
| 121 toolchain_uses_goma = toolchain_args.use_goma |
| 122 } else { |
| 123 toolchain_uses_goma = use_goma |
| 124 } |
| 125 if (defined(toolchain_args.cc_wrapper)) { |
| 126 toolchain_cc_wrapper = toolchain_args.cc_wrapper |
| 127 } else { |
| 128 toolchain_cc_wrapper = cc_wrapper |
| 129 } |
| 130 |
| 131 # Compute the compiler prefix. |
| 132 if (toolchain_uses_goma) { |
| 133 assert(toolchain_cc_wrapper == "", |
| 134 "Goma and cc_wrapper can't be used together.") |
| 135 compiler_prefix = "$goma_dir/gomacc " |
| 136 } else if (toolchain_cc_wrapper != "") { |
| 137 compiler_prefix = toolchain_cc_wrapper + " " |
| 138 } else { |
| 139 compiler_prefix = "" |
| 140 } |
| 141 |
| 139 cc = compiler_prefix + invoker.cc | 142 cc = compiler_prefix + invoker.cc |
| 140 cxx = compiler_prefix + invoker.cxx | 143 cxx = compiler_prefix + invoker.cxx |
| 141 ar = invoker.ar | 144 ar = invoker.ar |
| 142 ld = invoker.ld | 145 ld = invoker.ld |
| 143 if (defined(invoker.readelf)) { | 146 if (defined(invoker.readelf)) { |
| 144 readelf = invoker.readelf | 147 readelf = invoker.readelf |
| 145 } else { | 148 } else { |
| 146 readelf = "readelf" | 149 readelf = "readelf" |
| 147 } | 150 } |
| 148 if (defined(invoker.nm)) { | 151 if (defined(invoker.nm)) { |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 # See //build/toolchain/toolchain.gni for details. | 430 # See //build/toolchain/toolchain.gni for details. |
| 428 tool("stamp") { | 431 tool("stamp") { |
| 429 command = stamp_command | 432 command = stamp_command |
| 430 description = stamp_description | 433 description = stamp_description |
| 431 } | 434 } |
| 432 tool("copy") { | 435 tool("copy") { |
| 433 command = copy_command | 436 command = copy_command |
| 434 description = copy_description | 437 description = copy_description |
| 435 } | 438 } |
| 436 | 439 |
| 437 # When invoking this toolchain not as the default one, these args will be | |
| 438 # passed to the build. They are ignored when this is the default toolchain. | |
| 439 toolchain_args() { | |
| 440 current_cpu = invoker.toolchain_cpu | |
| 441 current_os = invoker.toolchain_os | |
| 442 | |
| 443 # These values need to be passed through unchanged. | |
| 444 host_toolchain = host_toolchain | |
| 445 target_os = target_os | |
| 446 target_cpu = target_cpu | |
| 447 | |
| 448 if (defined(invoker.is_clang)) { | |
| 449 is_clang = invoker.is_clang | |
| 450 } | |
| 451 if (defined(invoker.is_component_build)) { | |
| 452 is_component_build = invoker.is_component_build | |
| 453 } | |
| 454 if (defined(invoker.is_nacl_glibc)) { | |
| 455 is_nacl_glibc = invoker.is_nacl_glibc | |
| 456 } | |
| 457 if (defined(invoker.symbol_level)) { | |
| 458 symbol_level = invoker.symbol_level | |
| 459 } | |
| 460 if (defined(invoker.use_allocator)) { | |
| 461 use_allocator = invoker.use_allocator | |
| 462 } | |
| 463 if (defined(invoker.use_debug_fission)) { | |
| 464 use_debug_fission = invoker.use_debug_fission | |
| 465 } | |
| 466 if (defined(invoker.use_gold)) { | |
| 467 use_gold = invoker.use_gold | |
| 468 } | |
| 469 if (defined(invoker.use_sysroot)) { | |
| 470 use_sysroot = invoker.use_sysroot | |
| 471 } | |
| 472 if (defined(invoker.v8_toolchain_cpu)) { | |
| 473 v8_current_cpu = invoker.v8_toolchain_cpu | |
| 474 } else { | |
| 475 v8_current_cpu = current_cpu | |
| 476 } | |
| 477 } | |
| 478 | |
| 479 forward_variables_from(invoker, [ "deps" ]) | 440 forward_variables_from(invoker, [ "deps" ]) |
| 480 } | 441 } |
| 481 } | 442 } |
| 482 | 443 |
| 483 # This is a shorthand for gcc_toolchain instances based on the | 444 # This is a shorthand for gcc_toolchain instances based on the Chromium-built |
| 484 # Chromium-built version of Clang. Only the toolchain_cpu and | 445 # version of Clang. Only the toolchain_cpu and toolchain_os variables need to |
| 485 # toolchain_os variables need to be specified by the invoker, and | 446 # be specified by the invoker, and optionally toolprefix if it's a |
| 486 # optionally toolprefix if it's a cross-compile case. Note that for | 447 # cross-compile case. Note that for a cross-compile case this toolchain |
| 487 # a cross-compile case this toolchain requires a config to pass the | 448 # requires a config to pass the appropriate -target option, or else it will |
| 488 # appropriate -target option, or else it will actually just be doing | 449 # actually just be doing a native compile. The invoker can optionally override |
| 489 # a native compile. The invoker can optionally override use_gold too. | 450 # use_gold too. |
| 490 template("clang_toolchain") { | 451 template("clang_toolchain") { |
| 491 assert(defined(invoker.toolchain_cpu), | |
| 492 "clang_toolchain() must specify a \"toolchain_cpu\"") | |
| 493 assert(defined(invoker.toolchain_os), | |
| 494 "clang_toolchain() must specify a \"toolchain_os\"") | |
| 495 if (defined(invoker.toolprefix)) { | 452 if (defined(invoker.toolprefix)) { |
| 496 toolprefix = invoker.toolprefix | 453 toolprefix = invoker.toolprefix |
| 497 } else { | 454 } else { |
| 498 toolprefix = "" | 455 toolprefix = "" |
| 499 } | 456 } |
| 500 | 457 |
| 501 gcc_toolchain(target_name) { | 458 gcc_toolchain(target_name) { |
| 502 prefix = rebase_path("$clang_base_path/bin", root_build_dir) | 459 prefix = rebase_path("$clang_base_path/bin", root_build_dir) |
| 503 cc = "$prefix/clang" | 460 cc = "$prefix/clang" |
| 504 cxx = "$prefix/clang++" | 461 cxx = "$prefix/clang++" |
| 505 ld = cxx | 462 ld = cxx |
| 506 is_clang = true | |
| 507 | 463 |
| 508 readelf = "${toolprefix}readelf" | 464 readelf = "${toolprefix}readelf" |
| 509 ar = "${toolprefix}ar" | 465 ar = "${toolprefix}ar" |
| 510 nm = "${toolprefix}nm" | 466 nm = "${toolprefix}nm" |
| 511 | 467 |
| 512 forward_variables_from(invoker, | 468 forward_variables_from(invoker, [ "strip" ]) |
| 513 [ | |
| 514 "strip", | |
| 515 "toolchain_cpu", | |
| 516 "toolchain_os", | |
| 517 "use_gold", | |
| 518 "v8_toolchain_cpu", | |
| 519 ]) | |
| 520 | 469 |
| 470 toolchain_args = { |
| 471 if (defined(invoker.toolchain_args)) { |
| 472 forward_variables_from(invoker.toolchain_args, "*") |
| 473 } |
| 474 is_clang = true |
| 475 } |
| 476 |
| 477 # Backwards-compatible handling for toolchain definitions in the Native |
| 478 # Client repo. |
| 479 # |
| 480 # TODO(brettw) bug 634446 remove this when |
| 481 # //native_client/src/trusted/service_runtime/linux/BUILD.gn is updated to |
| 482 # use the new-style toolchain_args. |
| 483 if (defined(invoker.toolchain_cpu)) { |
| 484 assert(!defined(toolchain_args.current_cpu)) |
| 485 toolchain_args.current_cpu = invoker.toolchain_cpu |
| 486 } |
| 487 if (defined(invoker.toolchain_os)) { |
| 488 assert(!defined(toolchain_args.current_os)) |
| 489 toolchain_args.current_os = invoker.toolchain_os |
| 490 } |
| 521 if (defined(invoker.use_debug_fission)) { | 491 if (defined(invoker.use_debug_fission)) { |
| 522 use_debug_fission = invoker.use_debug_fission | 492 assert(!defined(toolchain_args.use_debug_fission)) |
| 493 toolchain_args.use_debug_fission = invoker.use_debug_fission |
| 494 } |
| 495 if (defined(invoker.use_gold)) { |
| 496 assert(!defined(toolchain_args.use_gold)) |
| 497 toolchain_args.use_gold = invoker.use_gold |
| 523 } | 498 } |
| 524 } | 499 } |
| 525 } | 500 } |
| OLD | NEW |