xref: /aosp_15_r20/external/angle/build/toolchain/cros/BUILD.gn (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1# Copyright 2014 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
5import("//build/config/compiler/compiler.gni")
6import("//build/config/sysroot.gni")
7import("//build/toolchain/cros/cros_config.gni")
8import("//build/toolchain/cros_toolchain.gni")
9import("//build/toolchain/gcc_toolchain.gni")
10
11# This is mostly identical to gcc_toolchain, but handles relativizing toolchain
12# paths. This is needed for CrOS since these paths often change based on the
13# environment. For example, cxx is a relative path picked up on $PATH in the
14# chroot. But in Simple Chrome, cxx is a system-absolute path.
15template("cros_toolchain") {
16  if (lacros_use_chromium_toolchain) {
17    clang_toolchain(target_name) {
18      forward_variables_from(invoker, "*")
19    }
20  } else {
21    gcc_toolchain(target_name) {
22      forward_variables_from(invoker, "*")
23
24      toolchain_args.cc_wrapper = ""
25      toolchain_args.clang_use_chrome_plugins = false
26
27      # CrOS's target toolchain wrapper prefers to invoke rewrapper itself, so
28      # pass it the rewrapper path via cmd-line arg. Otherwise, for both CrOS's
29      # host wrapper (used in the ebuild) and Chrome's clang (used in Simple
30      # Chrome), prepend rewrapper like normal.
31      if (use_reclient && invoker.needs_rewrapper_path_arg) {
32        extra_cppflags += "--rewrapper-path $reclient_cros_cc_wrapper --rewrapper-cfg ${reclient_cc_cfg_file}"
33      }
34
35      # Relativize path if compiler is specified such that not to lookup from
36      # $PATH and cc/cxx does not contain additional flags.
37      if (cc != get_path_info(cc, "file") &&
38          string_replace(cc, " ", "") == cc) {
39        cc = rebase_path(cc, root_build_dir)
40      }
41      if (cxx != get_path_info(cxx, "file") &&
42          string_replace(cxx, " ", "") == cxx) {
43        cxx = rebase_path(cxx, root_build_dir)
44      }
45      if (ar != get_path_info(ar, "file") &&
46          string_replace(ar, " ", "") == ar) {
47        ar = rebase_path(ar, root_build_dir)
48      }
49      if (ld != get_path_info(ld, "file") &&
50          string_replace(ld, " ", "") == ld) {
51        ld = rebase_path(ld, root_build_dir)
52      }
53    }
54  }
55}
56
57# This is the normal toolchain for most targets.
58cros_toolchain("target") {
59  toolchain_args = {
60    current_cpu = target_cpu
61    current_os = "chromeos"
62    sysroot = target_sysroot
63  }
64
65  if (!lacros_use_chromium_toolchain) {
66    ar = cros_target_ar
67    cc = cros_target_cc
68    cxx = cros_target_cxx
69    ld = cros_target_ld
70
71    if (cros_target_nm != "") {
72      nm = cros_target_nm
73    }
74    if (cros_target_readelf != "") {
75      readelf = cros_target_readelf
76    }
77    extra_cflags = cros_target_extra_cflags
78    extra_cppflags = cros_target_extra_cppflags
79    extra_cxxflags = cros_target_extra_cxxflags
80    extra_ldflags = cros_target_extra_ldflags
81
82    needs_rewrapper_path_arg = true
83  }
84}
85
86# This is a special toolchain needed just for the nacl_bootstrap target in
87# //native_client/src/trusted/service_runtime/linux. It is identical
88# to ":target" except that it forces `use_debug_fission1 and `use_sysroot` off,
89# and allows the user to set different sets of extra flags.
90cros_toolchain("nacl_bootstrap") {
91  toolchain_args = {
92    if (target_cpu == "arm64") {
93      current_cpu = "arm"
94    } else {
95      current_cpu = target_cpu
96    }
97    current_os = "chromeos"
98    use_debug_fission = false
99    use_sysroot = false
100  }
101
102  if (!lacros_use_chromium_toolchain) {
103    ar = cros_target_ar
104    cc = cros_target_cc
105    cxx = cros_target_cxx
106    ld = cros_target_ld
107
108    if (cros_target_nm != "") {
109      nm = cros_target_nm
110    }
111    if (cros_target_readelf != "") {
112      readelf = cros_target_readelf
113    }
114    extra_cflags = cros_nacl_bootstrap_extra_cflags
115    extra_cppflags = cros_nacl_bootstrap_extra_cppflags
116    extra_cxxflags = cros_nacl_bootstrap_extra_cxxflags
117    extra_ldflags = cros_nacl_bootstrap_extra_ldflags
118
119    needs_rewrapper_path_arg = true
120  }
121
122  # We build for ARM32, even when the rest of the build targets ARM64.
123  if (target_cpu == "arm64") {
124    ar = cros_nacl_helper_arm32_ar
125    cc = cros_nacl_helper_arm32_cc
126    cxx = cros_nacl_helper_arm32_cxx
127    ld = cros_nacl_helper_arm32_ld
128
129    # Avoid accidental use of Arm64 sysroot because of SYSROOT
130    # env variable set in ChromeOS builds.
131    toolchain_args.sysroot = cros_nacl_helper_arm32_sysroot
132  }
133}
134
135# This is a special toolchain needed just for the nacl_helper target for
136# building an Arm32 nacl_helper binary on Arm64 ChromeOS targets.
137cros_toolchain("nacl_helper_arm32") {
138  toolchain_args = {
139    current_cpu = "arm"
140    current_os = "chromeos"
141    use_debug_fission = false
142    sysroot = cros_nacl_helper_arm32_sysroot
143
144    # Disable some uses of libraries that this build does not require. The
145    # sysroot for this build does not provide them, and they would be pulled in
146    # by indirect dependencies of nacl_helper otherwise.
147    use_cras = false
148    use_nss_certs = false
149    use_system_libdrm = false
150    use_system_libsync = false
151  }
152  ar = cros_nacl_helper_arm32_ar
153  cc = cros_nacl_helper_arm32_cc
154  cxx = cros_nacl_helper_arm32_cxx
155  ld = cros_nacl_helper_arm32_ld
156  readelf = cros_nacl_helper_arm32_readelf
157
158  extra_cflags = ""
159  extra_cppflags = ""
160  extra_cxxflags = ""
161  extra_ldflags = ""
162
163  if (!lacros_use_chromium_toolchain) {
164    needs_rewrapper_path_arg = true
165  }
166}
167
168cros_toolchain("host") {
169  toolchain_args = {
170    current_cpu = host_cpu
171    current_os = "linux"
172    sysroot = cros_host_sysroot
173  }
174
175  if (!lacros_use_chromium_toolchain) {
176    # These are args for the template.
177    ar = cros_host_ar
178    cc = cros_host_cc
179    cxx = cros_host_cxx
180    ld = cros_host_ld
181
182    if (cros_host_nm != "") {
183      nm = cros_host_nm
184    }
185    if (cros_host_readelf != "") {
186      readelf = cros_host_readelf
187    }
188    extra_cflags = cros_host_extra_cflags
189    extra_cppflags = cros_host_extra_cppflags
190    extra_cxxflags = cros_host_extra_cxxflags
191    extra_ldflags = cros_host_extra_ldflags
192
193    needs_rewrapper_path_arg = false
194  }
195}
196
197cros_toolchain("v8_snapshot") {
198  toolchain_args = {
199    if (target_cpu == "x86" || target_cpu == "arm" || target_cpu == "mipsel") {
200      current_cpu = "x86"
201    } else {
202      current_cpu = "x64"
203    }
204    v8_current_cpu = v8_target_cpu
205    current_os = "linux"
206    sysroot = cros_v8_snapshot_sysroot
207  }
208
209  if (!lacros_use_chromium_toolchain) {
210    # These are args for the template.
211    ar = cros_v8_snapshot_ar
212    cc = cros_v8_snapshot_cc
213    cxx = cros_v8_snapshot_cxx
214    ld = cros_v8_snapshot_ld
215
216    if (cros_v8_snapshot_nm != "") {
217      nm = cros_v8_snapshot_nm
218    }
219    if (cros_v8_snapshot_readelf != "") {
220      readelf = cros_v8_snapshot_readelf
221    }
222    extra_cflags = cros_v8_snapshot_extra_cflags
223    extra_cppflags = cros_v8_snapshot_extra_cppflags
224    extra_cxxflags = cros_v8_snapshot_extra_cxxflags
225    extra_ldflags = cros_v8_snapshot_extra_ldflags
226
227    needs_rewrapper_path_arg = false
228  }
229}
230