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