xref: /aosp_15_r20/external/angle/build/toolchain/toolchain.gni (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2015 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5# Toolchain-related configuration that may be needed outside the context of the
6# toolchain() rules themselves.
7
8import("//build/config/cast.gni")
9import("//build/config/chrome_build.gni")
10import("//build_overrides/build.gni")
11
12declare_args() {
13  # If this is set to true, we use the revision in the llvm repo to determine
14  # the CLANG_REVISION to use, instead of the version hard-coded into
15  # //tools/clang/scripts/update.py. This should only be used in
16  # conjunction with setting the llvm_force_head_revision DEPS variable when
17  # `gclient runhooks` is run as well.
18  llvm_force_head_revision = false
19
20  # Cronet is shipped in AOSP, where it is built using the Android Mainline
21  # Clang. Please refer to go/cronet-builders-with-mainline-clang-design for
22  # more information.
23  # If this arg is set to true, we use the Android Mainline LLVM.
24  llvm_android_mainline = false
25
26  # Used for binary size analysis.
27  generate_linker_map = is_android && is_official_build
28
29  # Whether this toolchain is to be used for building host tools that are
30  # consumed during the build process. That includes proc macros and Cargo build
31  # scripts.
32  toolchain_for_rust_host_build_tools = false
33
34  # If false, the toolchain overrides `use_partition_alloc_as_malloc` in
35  # PartitionAlloc, to allow use of the system allocator.
36  toolchain_allows_use_partition_alloc_as_malloc = true
37}
38
39if (generate_linker_map) {
40  assert(is_official_build || is_castos || is_cast_android,
41         "Linker map files should only be generated when is_official_build = " +
42             "true or is_castos = true or is_cast_android = true")
43  assert(current_os == "android" || current_os == "linux" ||
44             target_os == "android" || target_os == "linux" ||
45             target_os == "chromeos",
46         "Linker map files should only be generated for Android, Linux, " +
47             "or ChromeOS.")
48}
49
50declare_args() {
51  if (llvm_android_mainline) {  # https://crbug.com/1481060
52    clang_version = "17"
53  } else {
54    clang_version = "20"
55  }
56}
57
58# Extension for shared library files (including leading dot).
59if (is_apple) {
60  shlib_extension = ".dylib"
61} else if (is_posix || is_fuchsia) {
62  shlib_extension = ".so"
63} else if (is_win) {
64  shlib_extension = ".dll"
65} else {
66  assert(false, "Platform not supported")
67}
68
69# Same extension but for the host platform. We have significantly fewer host
70# platforms.
71if (host_os == "mac") {
72  host_shlib_extension = ".dylib"
73} else if (host_os == "win") {
74  host_shlib_extension = ".dll"
75} else if (host_os == "linux" || host_os == "aix" || host_os == "zos") {
76  host_shlib_extension = ".so"
77} else {
78  assert(false, "Host platform not supported")
79}
80
81# Prefix for shared library files.
82if (is_posix || is_fuchsia) {
83  shlib_prefix = "lib"
84} else {
85  shlib_prefix = ""
86}
87
88# Directory for shared library files.
89if (is_fuchsia) {
90  shlib_subdir = "/lib"
91} else {
92  shlib_subdir = ""
93}
94
95# While other "tool"s in a toolchain are specific to the target of that
96# toolchain, the "stamp" and "copy" tools are really generic to the host;
97# but each toolchain must define them separately.  GN doesn't allow a
98# template instantiation inside a toolchain definition, so some boilerplate
99# has to be repeated in each toolchain to define these two tools.  These
100# four variables reduce the duplication in that boilerplate.
101stamp_description = "STAMP {{output}}"
102copy_description = "COPY {{source}} {{output}}"
103if (host_os == "win") {
104  _tool_wrapper_path =
105      rebase_path("//build/toolchain/win/tool_wrapper.py", root_build_dir)
106
107  stamp_command = "cmd /c type nul > \"{{output}}\""
108  copy_command = "\"$python_path\" $_tool_wrapper_path recursive-mirror {{source}} {{output}}"
109} else {
110  stamp_command = "touch {{output}}"
111  copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})"
112}
113
114# This variable is true if the current toolchain is one of the target
115# toolchains, i.e. a toolchain which is being used to build the main Chrome
116# binary. This generally means "not the host toolchain", but in the case where
117# we're targeting the host it's true then as well. We do require current_os to
118# match target_os so that for example we avoid considering Android as a target
119# toolchain when targeting CrOS.
120is_a_target_toolchain =
121    (current_toolchain != host_toolchain ||
122     default_toolchain == host_toolchain) && current_os == target_os
123
124# A toolchain for building tools that run on the host machine and need to use
125# the system allocator. This toolchain does not use PartitionAlloc-Everywhere by
126# design. We use a name with `_host` injected into it to avoid colliding with
127# toolchains of the same name (but different path) between different OSes.
128host_system_allocator_toolchain = "${host_toolchain}_host_with_system_allocator"
129
130# A toolchain for building tools that run on the default target machine and need
131# to use the system allocator. This toolchain does not use
132# PartitionAlloc-Everywhere by design.
133default_system_allocator_toolchain =
134    "${default_toolchain}_with_system_allocator"
135