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 gomacc itself, so pass 28 # it the gomacc path via cmd-line arg. Otherwise, for both CrOS's host 29 # wrapper (used in the ebuild) and Chrome's clang (used in Simple Chrome), 30 # prepend gomacc like normal. 31 if (use_goma && invoker.needs_gomacc_path_arg) { 32 extra_cppflags += " --gomacc-path $goma_dir/gomacc" 33 } 34 if (use_remoteexec && invoker.needs_gomacc_path_arg) { 35 extra_cppflags += "--rewrapper-path $rbe_cros_cc_wrapper --rewrapper-cfg ${rbe_cc_cfg_file}" 36 } 37 38 # Relativize path if compiler is specified such that not to lookup from 39 # $PATH and cc/cxx does not contain additional flags. 40 if (cc != get_path_info(cc, "file") && 41 string_replace(cc, " ", "") == cc) { 42 cc = rebase_path(cc, root_build_dir) 43 } 44 if (cxx != get_path_info(cxx, "file") && 45 string_replace(cxx, " ", "") == cxx) { 46 cxx = rebase_path(cxx, root_build_dir) 47 } 48 if (ar != get_path_info(ar, "file") && 49 string_replace(ar, " ", "") == ar) { 50 ar = rebase_path(ar, root_build_dir) 51 } 52 if (ld != get_path_info(ld, "file") && 53 string_replace(ld, " ", "") == ld) { 54 ld = rebase_path(ld, root_build_dir) 55 } 56 } 57 } 58} 59 60# This is the normal toolchain for most targets. 61cros_toolchain("target") { 62 toolchain_args = { 63 current_cpu = target_cpu 64 current_os = "chromeos" 65 sysroot = target_sysroot 66 } 67 68 if (!lacros_use_chromium_toolchain) { 69 ar = cros_target_ar 70 cc = cros_target_cc 71 cxx = cros_target_cxx 72 ld = cros_target_ld 73 74 if (cros_target_nm != "") { 75 nm = cros_target_nm 76 } 77 if (cros_target_readelf != "") { 78 readelf = cros_target_readelf 79 } 80 extra_cflags = cros_target_extra_cflags 81 extra_cppflags = cros_target_extra_cppflags 82 extra_cxxflags = cros_target_extra_cxxflags 83 extra_ldflags = cros_target_extra_ldflags 84 85 needs_gomacc_path_arg = true 86 } 87} 88 89# This is a special toolchain needed just for the nacl_bootstrap target in 90# //native_client/src/trusted/service_runtime/linux. It is identical 91# to ":target" except that it forces use_debug_fission, use_gold, and 92# use_sysroot off, and allows the user to set different sets of extra flags. 93cros_toolchain("nacl_bootstrap") { 94 toolchain_args = { 95 if (target_cpu == "arm64") { 96 current_cpu = "arm" 97 } else { 98 current_cpu = target_cpu 99 } 100 current_os = "chromeos" 101 use_debug_fission = false 102 use_gold = false 103 use_sysroot = false 104 } 105 106 if (!lacros_use_chromium_toolchain) { 107 ar = cros_target_ar 108 cc = cros_target_cc 109 cxx = cros_target_cxx 110 ld = cros_target_ld 111 112 if (cros_target_nm != "") { 113 nm = cros_target_nm 114 } 115 if (cros_target_readelf != "") { 116 readelf = cros_target_readelf 117 } 118 extra_cflags = cros_nacl_bootstrap_extra_cflags 119 extra_cppflags = cros_nacl_bootstrap_extra_cppflags 120 extra_cxxflags = cros_nacl_bootstrap_extra_cxxflags 121 extra_ldflags = cros_nacl_bootstrap_extra_ldflags 122 123 needs_gomacc_path_arg = true 124 } 125 126 # We build for ARM32, even when the rest of the build targets ARM64. 127 if (target_cpu == "arm64") { 128 ar = cros_nacl_helper_arm32_ar 129 cc = cros_nacl_helper_arm32_cc 130 cxx = cros_nacl_helper_arm32_cxx 131 ld = cros_nacl_helper_arm32_ld 132 133 # Avoid accidental use of Arm64 sysroot because of SYSROOT 134 # env variable set in ChromeOS builds. 135 toolchain_args.sysroot = cros_nacl_helper_arm32_sysroot 136 } 137} 138 139# This is a special toolchain needed just for the nacl_helper target for 140# building an Arm32 nacl_helper binary on Arm64 ChromeOS targets. 141cros_toolchain("nacl_helper_arm32") { 142 toolchain_args = { 143 current_cpu = "arm" 144 current_os = "chromeos" 145 use_debug_fission = false 146 use_gold = false 147 sysroot = cros_nacl_helper_arm32_sysroot 148 149 # Disable some uses of libraries that this build does not require. The 150 # sysroot for this build does not provide them, and they would be pulled in 151 # by indirect dependencies of nacl_helper otherwise. 152 use_cras = false 153 use_nss_certs = false 154 use_system_libdrm = false 155 use_system_libsync = false 156 } 157 ar = cros_nacl_helper_arm32_ar 158 cc = cros_nacl_helper_arm32_cc 159 cxx = cros_nacl_helper_arm32_cxx 160 ld = cros_nacl_helper_arm32_ld 161 readelf = cros_nacl_helper_arm32_readelf 162 163 extra_cflags = "" 164 extra_cppflags = "" 165 extra_cxxflags = "" 166 extra_ldflags = "" 167 168 if (!lacros_use_chromium_toolchain) { 169 needs_gomacc_path_arg = true 170 } 171} 172 173cros_toolchain("host") { 174 toolchain_args = { 175 current_cpu = host_cpu 176 current_os = "linux" 177 sysroot = cros_host_sysroot 178 } 179 180 if (!lacros_use_chromium_toolchain) { 181 # These are args for the template. 182 ar = cros_host_ar 183 cc = cros_host_cc 184 cxx = cros_host_cxx 185 ld = cros_host_ld 186 187 if (cros_host_nm != "") { 188 nm = cros_host_nm 189 } 190 if (cros_host_readelf != "") { 191 readelf = cros_host_readelf 192 } 193 extra_cflags = cros_host_extra_cflags 194 extra_cppflags = cros_host_extra_cppflags 195 extra_cxxflags = cros_host_extra_cxxflags 196 extra_ldflags = cros_host_extra_ldflags 197 198 needs_gomacc_path_arg = false 199 } 200} 201 202cros_toolchain("v8_snapshot") { 203 toolchain_args = { 204 if (target_cpu == "x86" || target_cpu == "arm" || target_cpu == "mipsel") { 205 current_cpu = "x86" 206 } else { 207 current_cpu = "x64" 208 } 209 v8_current_cpu = v8_target_cpu 210 current_os = "linux" 211 sysroot = cros_v8_snapshot_sysroot 212 } 213 214 if (!lacros_use_chromium_toolchain) { 215 # These are args for the template. 216 ar = cros_v8_snapshot_ar 217 cc = cros_v8_snapshot_cc 218 cxx = cros_v8_snapshot_cxx 219 ld = cros_v8_snapshot_ld 220 221 if (cros_v8_snapshot_nm != "") { 222 nm = cros_v8_snapshot_nm 223 } 224 if (cros_v8_snapshot_readelf != "") { 225 readelf = cros_v8_snapshot_readelf 226 } 227 extra_cflags = cros_v8_snapshot_extra_cflags 228 extra_cppflags = cros_v8_snapshot_extra_cppflags 229 extra_cxxflags = cros_v8_snapshot_extra_cxxflags 230 extra_ldflags = cros_v8_snapshot_extra_ldflags 231 232 needs_gomacc_path_arg = false 233 } 234} 235 236# This toolchain is used when we want to build Lacros using alternate toolchain. 237# To use this, you need to set gn arg 'also_build_lacros_chrome_for_architecture'. 238# See build/config/chromeos/ui_mode.gni 239if (also_build_lacros_chrome_for_architecture != "") { 240 cros_toolchain("lacros_clang") { 241 if (also_build_lacros_chrome_for_architecture == "amd64") { 242 lacros_args = 243 read_file("//build/args/chromeos/amd64-generic-crostoolchain.gni", 244 "scope") 245 } else if (also_build_lacros_chrome_for_architecture == "arm") { 246 lacros_args = 247 read_file("//build/args/chromeos/arm-generic-crostoolchain.gni", 248 "scope") 249 } else if (also_build_lacros_chrome_for_architecture == "arm64") { 250 lacros_args = 251 read_file("//build/args/chromeos/arm64-generic-crostoolchain.gni", 252 "scope") 253 } else { 254 assert(false, 255 "also_build_lacros_chrome_for_architecture is not " + 256 "one of the supported architectures.") 257 } 258 259 toolchain_args = { 260 forward_variables_from(lacros_args, "*") 261 262 # TODO(crbug.com/1298821) Change to a better way to set gn args. 263 # The following gn args are present in ash config like 264 # //build/args/chromeos/atlas.gni but not in 265 # //build/args/chromeos/amd64-generic-crostoolchain.gni. 266 # So we need to reset them to the default value where Lacros needs. 267 # Starts from here. 268 ozone_auto_platforms = true 269 ozone_platform = "" 270 ozone_platform_gbm = -1 271 ozone_platform_headless = false 272 273 # Ends here. 274 275 current_os = "chromeos" 276 target_os = "chromeos" 277 current_cpu = current_cpu 278 also_build_lacros_chrome_for_architecture = "" 279 chromeos_is_browser_only = true 280 use_clang_coverage = false 281 282 # Do not propagate AFDO settings from Ash build to Lacros build. 283 # Specifically, Lacros uses PGO by default, so this would 284 # conflict. 285 clang_use_default_sample_profile = false 286 clang_sample_profile_path = "" 287 } 288 if (!lacros_use_chromium_toolchain) { 289 # These are args for the template. 290 ar = lacros_args.cros_target_ar 291 cc = lacros_args.cros_target_cc 292 cxx = lacros_args.cros_target_cxx 293 ld = lacros_args.cros_target_ld 294 295 if (defined(lacros_args.cros_target_nm) && 296 lacros_args.cros_target_nm != "") { 297 nm = lacros_args.cros_target_nm 298 } 299 if (defined(lacros_args.cros_target_readelf) && 300 lacros_args.cros_target_readelf != "") { 301 readelf = lacros_args.cros_target_readelf 302 } 303 extra_cflags = lacros_args.cros_target_extra_cflags 304 extra_cppflags = lacros_args.cros_target_extra_cppflags 305 extra_cxxflags = lacros_args.cros_target_extra_cxxflags 306 extra_ldflags = lacros_args.cros_target_extra_ldflags 307 308 needs_gomacc_path_arg = true 309 } 310 } 311} 312