1*6777b538SAndroid Build Coastguard Worker# Copyright 2021 The Chromium Project. All rights reserved. 2*6777b538SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be 3*6777b538SAndroid Build Coastguard Worker# found in the LICENSE file. 4*6777b538SAndroid Build Coastguard Worker 5*6777b538SAndroid Build Coastguard Workerimport("//build/config/chrome_build.gni") 6*6777b538SAndroid Build Coastguard Workerimport("//build/config/compiler/compiler.gni") 7*6777b538SAndroid Build Coastguard Workerimport("//build/config/sanitizers/sanitizers.gni") 8*6777b538SAndroid Build Coastguard Workerimport("//build/toolchain/toolchain.gni") 9*6777b538SAndroid Build Coastguard Worker 10*6777b538SAndroid Build Coastguard Workerif (is_android) { 11*6777b538SAndroid Build Coastguard Worker import("//build/config/android/config.gni") 12*6777b538SAndroid Build Coastguard Worker} 13*6777b538SAndroid Build Coastguard Worker 14*6777b538SAndroid Build Coastguard Workerif (is_ios) { 15*6777b538SAndroid Build Coastguard Worker import("//build/config/ios/config.gni") # For `target_environment` 16*6777b538SAndroid Build Coastguard Worker import("//build/config/ios/ios_sdk.gni") # For `xcode_version_int` 17*6777b538SAndroid Build Coastguard Worker} 18*6777b538SAndroid Build Coastguard Worker 19*6777b538SAndroid Build Coastguard Workerdeclare_args() { 20*6777b538SAndroid Build Coastguard Worker # Rust is available in the Chromium build but 3p repos that use //build may 21*6777b538SAndroid Build Coastguard Worker # not use Rust and thus won't want to depend on having the Rust toolchain 22*6777b538SAndroid Build Coastguard Worker # present, so this defaults to off in those cases. 23*6777b538SAndroid Build Coastguard Worker # 24*6777b538SAndroid Build Coastguard Worker # Chromium-based projects that are built for for architectures Chrome does not 25*6777b538SAndroid Build Coastguard Worker # support may need to disable this as well, though they may need to replace 26*6777b538SAndroid Build Coastguard Worker # code with C/C++ to get a functional product. 27*6777b538SAndroid Build Coastguard Worker enable_rust = build_with_chromium 28*6777b538SAndroid Build Coastguard Worker 29*6777b538SAndroid Build Coastguard Worker # The CXX tool is in //third_party/rust which is not shared with downstream 30*6777b538SAndroid Build Coastguard Worker # projects yet. So they need to copy the required dependencies and GN files 31*6777b538SAndroid Build Coastguard Worker # into their project to enable CXX there. 32*6777b538SAndroid Build Coastguard Worker enable_cxx = build_with_chromium 33*6777b538SAndroid Build Coastguard Worker 34*6777b538SAndroid Build Coastguard Worker # The chromium prelude crate provides the `chromium::import!` macro which 35*6777b538SAndroid Build Coastguard Worker # is needed to depend on first-party rust libraries. Third-party libraries 36*6777b538SAndroid Build Coastguard Worker # are specified with cargo_crate and do not get imported through this macro. 37*6777b538SAndroid Build Coastguard Worker # 38*6777b538SAndroid Build Coastguard Worker # The macro requires //third_party/rust for syn, quote, and proc_macro2. 39*6777b538SAndroid Build Coastguard Worker # Downstream projects that want to use //build for the rust GN templates but 40*6777b538SAndroid Build Coastguard Worker # don't want to enable the chromium prelude can disable it here, and should 41*6777b538SAndroid Build Coastguard Worker # specify a globally unique `crate_name` in their rust library GN rules 42*6777b538SAndroid Build Coastguard Worker # instead. Note that using a `crate_name` is strongly discouraged inside 43*6777b538SAndroid Build Coastguard Worker # Chromium, and is also discouraged for downstream projects when possible. 44*6777b538SAndroid Build Coastguard Worker enable_chromium_prelude = build_with_chromium 45*6777b538SAndroid Build Coastguard Worker 46*6777b538SAndroid Build Coastguard Worker # As we incrementally enable Rust on mainstream builders, we want to enable 47*6777b538SAndroid Build Coastguard Worker # the toolchain (by switching 'enable_rust' to true) while still disabling 48*6777b538SAndroid Build Coastguard Worker # almost all Rust features). Yet we still want to have some builders with 49*6777b538SAndroid Build Coastguard Worker # all Rust features enabled. 50*6777b538SAndroid Build Coastguard Worker enable_all_rust_features = false 51*6777b538SAndroid Build Coastguard Worker 52*6777b538SAndroid Build Coastguard Worker # Chromium provides a Rust toolchain in //third_party/rust-toolchain. 53*6777b538SAndroid Build Coastguard Worker # 54*6777b538SAndroid Build Coastguard Worker # To use a custom toolchain instead, specify an absolute path to the root of 55*6777b538SAndroid Build Coastguard Worker # a Rust sysroot, which will have a 'bin' directory and others. Commonly 56*6777b538SAndroid Build Coastguard Worker # <home dir>/.rustup/toolchains/nightly-<something>-<something> 57*6777b538SAndroid Build Coastguard Worker rust_sysroot_absolute = "" 58*6777b538SAndroid Build Coastguard Worker 59*6777b538SAndroid Build Coastguard Worker # If you're using a Rust toolchain as specified by rust_sysroot_absolute, 60*6777b538SAndroid Build Coastguard Worker # set this to the output of `rustc -V`. Changing this string will cause all 61*6777b538SAndroid Build Coastguard Worker # Rust targets to be rebuilt, which allows you to update your toolchain and 62*6777b538SAndroid Build Coastguard Worker # not break incremental builds. 63*6777b538SAndroid Build Coastguard Worker rustc_version = "" 64*6777b538SAndroid Build Coastguard Worker 65*6777b538SAndroid Build Coastguard Worker # If you're using a Rust toolchain as specified by rust_sysroot_absolute, 66*6777b538SAndroid Build Coastguard Worker # you can specify whether it supports nacl here. 67*6777b538SAndroid Build Coastguard Worker rust_toolchain_supports_nacl = false 68*6777b538SAndroid Build Coastguard Worker 69*6777b538SAndroid Build Coastguard Worker # Whether artifacts produced by the Rust compiler can participate in ThinLTO. 70*6777b538SAndroid Build Coastguard Worker # 71*6777b538SAndroid Build Coastguard Worker # One important consideration is whether the linker uses the same LLVM 72*6777b538SAndroid Build Coastguard Worker # version as `rustc` (i.e. if it can understand the LLVM-IR from the 73*6777b538SAndroid Build Coastguard Worker # compilation artifacts produced by `rustc`). In LaCrOS and ash builds this 74*6777b538SAndroid Build Coastguard Worker # may not be true - see b/299483903. 75*6777b538SAndroid Build Coastguard Worker # 76*6777b538SAndroid Build Coastguard Worker # TODO(https://crbug.com/1482525): Re-enable ThinLTO for Rust on LaCrOS 77*6777b538SAndroid Build Coastguard Worker # TODO(b/300937673): Re-enable ThinLTO for Rust on ash-chrome 78*6777b538SAndroid Build Coastguard Worker toolchain_supports_rust_thin_lto = !is_chromeos 79*6777b538SAndroid Build Coastguard Worker 80*6777b538SAndroid Build Coastguard Worker # Any extra std rlibs in your Rust toolchain, relative to the standard 81*6777b538SAndroid Build Coastguard Worker # Rust toolchain. Typically used with 'rust_sysroot_absolute' 82*6777b538SAndroid Build Coastguard Worker added_rust_stdlib_libs = [] 83*6777b538SAndroid Build Coastguard Worker 84*6777b538SAndroid Build Coastguard Worker # Any removed std rlibs in your Rust toolchain, relative to the standard 85*6777b538SAndroid Build Coastguard Worker # Rust toolchain. Typically used with 'rust_sysroot_absolute' 86*6777b538SAndroid Build Coastguard Worker removed_rust_stdlib_libs = [] 87*6777b538SAndroid Build Coastguard Worker 88*6777b538SAndroid Build Coastguard Worker # Non-rlib libs provided in the toolchain sysroot. Usually this is empty, but 89*6777b538SAndroid Build Coastguard Worker # e.g. the Android Rust Toolchain provides a libunwind.a that rustc expects. 90*6777b538SAndroid Build Coastguard Worker extra_sysroot_libs = [] 91*6777b538SAndroid Build Coastguard Worker 92*6777b538SAndroid Build Coastguard Worker # Force-enable `--color=always` for rustc, even when it would be disabled for 93*6777b538SAndroid Build Coastguard Worker # a platform. Mostly applicable to Windows, where new versions can handle ANSI 94*6777b538SAndroid Build Coastguard Worker # escape sequences but it's not reliable in general. 95*6777b538SAndroid Build Coastguard Worker force_rustc_color_output = false 96*6777b538SAndroid Build Coastguard Worker} 97*6777b538SAndroid Build Coastguard Worker 98*6777b538SAndroid Build Coastguard Worker# Use a separate declare_args so these variables' defaults can depend on the 99*6777b538SAndroid Build Coastguard Worker# ones above. 100*6777b538SAndroid Build Coastguard Workerdeclare_args() { 101*6777b538SAndroid Build Coastguard Worker # Individual Rust components. 102*6777b538SAndroid Build Coastguard Worker 103*6777b538SAndroid Build Coastguard Worker # Conversions between Rust types and C++ types. 104*6777b538SAndroid Build Coastguard Worker enable_rust_base_conversions = enable_rust 105*6777b538SAndroid Build Coastguard Worker 106*6777b538SAndroid Build Coastguard Worker # The base::JSONReader implementation. Requires base conversions. 107*6777b538SAndroid Build Coastguard Worker enable_rust_json = enable_rust && enable_all_rust_features 108*6777b538SAndroid Build Coastguard Worker 109*6777b538SAndroid Build Coastguard Worker # Support for chrome://crash-rust to check crash dump collection works. 110*6777b538SAndroid Build Coastguard Worker enable_rust_crash = enable_rust 111*6777b538SAndroid Build Coastguard Worker 112*6777b538SAndroid Build Coastguard Worker # Support for Rust mojo bindings. 113*6777b538SAndroid Build Coastguard Worker enable_rust_mojo = enable_rust && enable_all_rust_features 114*6777b538SAndroid Build Coastguard Worker 115*6777b538SAndroid Build Coastguard Worker # Rust gtest interop. 116*6777b538SAndroid Build Coastguard Worker enable_rust_gtest_interop = enable_rust 117*6777b538SAndroid Build Coastguard Worker 118*6777b538SAndroid Build Coastguard Worker # Enable experimental Fontations Rust font stack. 119*6777b538SAndroid Build Coastguard Worker use_typeface_fontations = enable_rust 120*6777b538SAndroid Build Coastguard Worker} 121*6777b538SAndroid Build Coastguard Worker 122*6777b538SAndroid Build Coastguard Worker# Use the Rust toolchain built in-tree. When false, we use the prebuilt Rust 123*6777b538SAndroid Build Coastguard Worker# stdlibs that come with the specified custom toolchain. 124*6777b538SAndroid Build Coastguard Workeruse_chromium_rust_toolchain = rust_sysroot_absolute == "" 125*6777b538SAndroid Build Coastguard Worker 126*6777b538SAndroid Build Coastguard Worker# Platform support for the Rust toolchain. 127*6777b538SAndroid Build Coastguard Workerchromium_toolchain_supports_platform = !is_nacl 128*6777b538SAndroid Build Coastguard Workercustom_toolchain_supports_platform = !is_nacl || rust_toolchain_supports_nacl 129*6777b538SAndroid Build Coastguard Worker 130*6777b538SAndroid Build Coastguard Worker# Not all target triples (GN toolchains) are supported by the Rust compiler. 131*6777b538SAndroid Build Coastguard Worker# Define if we support the current GN toolchain. 132*6777b538SAndroid Build Coastguard Workertoolchain_has_rust = false 133*6777b538SAndroid Build Coastguard Worker 134*6777b538SAndroid Build Coastguard Worker# The rustc_revision is used to introduce a dependency on the toolchain version 135*6777b538SAndroid Build Coastguard Worker# (so e.g. rust targets are rebuilt, and the standard library is re-copied when 136*6777b538SAndroid Build Coastguard Worker# the toolchain changes). It is left empty for custom toolchains. 137*6777b538SAndroid Build Coastguard Workerrustc_revision = "" 138*6777b538SAndroid Build Coastguard Worker 139*6777b538SAndroid Build Coastguard Workerif (enable_rust) { 140*6777b538SAndroid Build Coastguard Worker if (use_chromium_rust_toolchain) { 141*6777b538SAndroid Build Coastguard Worker toolchain_has_rust = chromium_toolchain_supports_platform 142*6777b538SAndroid Build Coastguard Worker if (toolchain_has_rust) { 143*6777b538SAndroid Build Coastguard Worker update_rust_args = [ "--print-package-version" ] 144*6777b538SAndroid Build Coastguard Worker rustc_revision = exec_script("//tools/rust/update_rust.py", 145*6777b538SAndroid Build Coastguard Worker update_rust_args, 146*6777b538SAndroid Build Coastguard Worker "trim string") 147*6777b538SAndroid Build Coastguard Worker } 148*6777b538SAndroid Build Coastguard Worker 149*6777b538SAndroid Build Coastguard Worker # The same as written in `config.toml.template`. 150*6777b538SAndroid Build Coastguard Worker rust_channel = "dev" 151*6777b538SAndroid Build Coastguard Worker } else { 152*6777b538SAndroid Build Coastguard Worker toolchain_has_rust = custom_toolchain_supports_platform 153*6777b538SAndroid Build Coastguard Worker rustc_revision = rustc_version 154*6777b538SAndroid Build Coastguard Worker } 155*6777b538SAndroid Build Coastguard Worker} 156*6777b538SAndroid Build Coastguard Worker 157*6777b538SAndroid Build Coastguard Worker# TODO(crbug.com/1278030): To build unit tests for Android we need to build 158*6777b538SAndroid Build Coastguard Worker# them as a dylib and put them into an APK. We should reuse all the same logic 159*6777b538SAndroid Build Coastguard Worker# for gtests from the `//testing/test:test` template. 160*6777b538SAndroid Build Coastguard Workercan_build_rust_unit_tests = toolchain_has_rust && !is_android 161*6777b538SAndroid Build Coastguard Worker 162*6777b538SAndroid Build Coastguard Worker# We want to store rust_sysroot as a source-relative variable for ninja 163*6777b538SAndroid Build Coastguard Worker# portability. In practice if an external toolchain was specified, it might 164*6777b538SAndroid Build Coastguard Worker# be an absolute path, but we'll do our best. 165*6777b538SAndroid Build Coastguard Workerif (enable_rust) { 166*6777b538SAndroid Build Coastguard Worker if (use_chromium_rust_toolchain) { 167*6777b538SAndroid Build Coastguard Worker rust_sysroot = "//third_party/rust-toolchain" 168*6777b538SAndroid Build Coastguard Worker } else { 169*6777b538SAndroid Build Coastguard Worker rust_sysroot = get_path_info(rust_sysroot_absolute, "abspath") 170*6777b538SAndroid Build Coastguard Worker } 171*6777b538SAndroid Build Coastguard Worker 172*6777b538SAndroid Build Coastguard Worker # Prebuilt toolchains won't come with bindgen, so we unconditionally use the 173*6777b538SAndroid Build Coastguard Worker # bindgen we ship with the Rust toolchain. This could be made configurable 174*6777b538SAndroid Build Coastguard Worker # if folks want to supply a bindgen with their toolchain. 175*6777b538SAndroid Build Coastguard Worker rust_bindgen_root = "//third_party/rust-toolchain" 176*6777b538SAndroid Build Coastguard Worker} 177*6777b538SAndroid Build Coastguard Worker 178*6777b538SAndroid Build Coastguard Worker# Figure out the Rust target triple (aka 'rust_abi_target') 179*6777b538SAndroid Build Coastguard Worker# 180*6777b538SAndroid Build Coastguard Worker# This is here rather than in the toolchain files because it's used also by 181*6777b538SAndroid Build Coastguard Worker# //build/rust/std to find the Rust standard library and construct a sysroot for 182*6777b538SAndroid Build Coastguard Worker# rustc invocations. 183*6777b538SAndroid Build Coastguard Worker# 184*6777b538SAndroid Build Coastguard Worker# The list of architectures supported by Rust is here: 185*6777b538SAndroid Build Coastguard Worker# https://doc.rust-lang.org/nightly/rustc/platform-support.html. We map Chromium 186*6777b538SAndroid Build Coastguard Worker# targets to Rust targets comprehensively despite not having official support 187*6777b538SAndroid Build Coastguard Worker# (see '*_toolchain_supports_platform above') to enable experimentation with 188*6777b538SAndroid Build Coastguard Worker# other toolchains. 189*6777b538SAndroid Build Coastguard Workerrust_abi_target = "" 190*6777b538SAndroid Build Coastguard Workerif (is_linux || is_chromeos) { 191*6777b538SAndroid Build Coastguard Worker if (current_cpu == "arm64") { 192*6777b538SAndroid Build Coastguard Worker rust_abi_target = "aarch64-unknown-linux-gnu" 193*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "x86") { 194*6777b538SAndroid Build Coastguard Worker rust_abi_target = "i686-unknown-linux-gnu" 195*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "x64") { 196*6777b538SAndroid Build Coastguard Worker rust_abi_target = "x86_64-unknown-linux-gnu" 197*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "arm") { 198*6777b538SAndroid Build Coastguard Worker if (arm_float_abi == "hard") { 199*6777b538SAndroid Build Coastguard Worker float_suffix = "hf" 200*6777b538SAndroid Build Coastguard Worker } else { 201*6777b538SAndroid Build Coastguard Worker float_suffix = "" 202*6777b538SAndroid Build Coastguard Worker } 203*6777b538SAndroid Build Coastguard Worker if (arm_arch == "armv7-a" || arm_arch == "armv7") { 204*6777b538SAndroid Build Coastguard Worker # No way to inform Rust about the -a suffix. 205*6777b538SAndroid Build Coastguard Worker rust_abi_target = "armv7-unknown-linux-gnueabi" + float_suffix 206*6777b538SAndroid Build Coastguard Worker } else { 207*6777b538SAndroid Build Coastguard Worker rust_abi_target = "arm-unknown-linux-gnueabi" + float_suffix 208*6777b538SAndroid Build Coastguard Worker } 209*6777b538SAndroid Build Coastguard Worker } else { 210*6777b538SAndroid Build Coastguard Worker # Best guess for other future platforms. 211*6777b538SAndroid Build Coastguard Worker rust_abi_target = current_cpu + "-unknown-linux-gnu" 212*6777b538SAndroid Build Coastguard Worker } 213*6777b538SAndroid Build Coastguard Worker} else if (is_android) { 214*6777b538SAndroid Build Coastguard Worker import("//build/config/android/abi.gni") 215*6777b538SAndroid Build Coastguard Worker rust_abi_target = android_abi_target 216*6777b538SAndroid Build Coastguard Worker if (rust_abi_target == "arm-linux-androideabi") { 217*6777b538SAndroid Build Coastguard Worker # Android clang target specifications mostly match Rust, but this 218*6777b538SAndroid Build Coastguard Worker # is an exception 219*6777b538SAndroid Build Coastguard Worker rust_abi_target = "armv7-linux-androideabi" 220*6777b538SAndroid Build Coastguard Worker } 221*6777b538SAndroid Build Coastguard Worker} else if (is_fuchsia) { 222*6777b538SAndroid Build Coastguard Worker if (current_cpu == "arm64") { 223*6777b538SAndroid Build Coastguard Worker rust_abi_target = "aarch64-fuchsia" 224*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "x64") { 225*6777b538SAndroid Build Coastguard Worker rust_abi_target = "x86_64-fuchsia" 226*6777b538SAndroid Build Coastguard Worker } else { 227*6777b538SAndroid Build Coastguard Worker assert(false, "Architecture not supported") 228*6777b538SAndroid Build Coastguard Worker } 229*6777b538SAndroid Build Coastguard Worker} else if (is_ios) { 230*6777b538SAndroid Build Coastguard Worker if (current_cpu == "arm64") { 231*6777b538SAndroid Build Coastguard Worker if (target_environment == "simulator") { 232*6777b538SAndroid Build Coastguard Worker rust_abi_target = "aarch64-apple-ios-sim" 233*6777b538SAndroid Build Coastguard Worker } else if (target_environment == "catalyst") { 234*6777b538SAndroid Build Coastguard Worker rust_abi_target = "aarch64-apple-ios-macabi" 235*6777b538SAndroid Build Coastguard Worker } else { 236*6777b538SAndroid Build Coastguard Worker rust_abi_target = "aarch64-apple-ios" 237*6777b538SAndroid Build Coastguard Worker } 238*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "arm") { 239*6777b538SAndroid Build Coastguard Worker # There's also an armv7s-apple-ios, which targets a more recent ARMv7 240*6777b538SAndroid Build Coastguard Worker # generation CPU found in later iPhones. We'll go with the older one for 241*6777b538SAndroid Build Coastguard Worker # maximal compatibility. As we come to support all the different platforms 242*6777b538SAndroid Build Coastguard Worker # with Rust, we might want to be more precise here. 243*6777b538SAndroid Build Coastguard Worker rust_abi_target = "armv7-apple-ios" 244*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "x64") { 245*6777b538SAndroid Build Coastguard Worker if (target_environment == "catalyst") { 246*6777b538SAndroid Build Coastguard Worker rust_abi_target = "x86_64-apple-ios-macabi" 247*6777b538SAndroid Build Coastguard Worker } else { 248*6777b538SAndroid Build Coastguard Worker rust_abi_target = "x86_64-apple-ios" 249*6777b538SAndroid Build Coastguard Worker } 250*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "x86") { 251*6777b538SAndroid Build Coastguard Worker rust_abi_target = "i386-apple-ios" 252*6777b538SAndroid Build Coastguard Worker } else { 253*6777b538SAndroid Build Coastguard Worker assert(false, "Architecture not supported") 254*6777b538SAndroid Build Coastguard Worker } 255*6777b538SAndroid Build Coastguard Worker} else if (is_mac) { 256*6777b538SAndroid Build Coastguard Worker if (current_cpu == "arm64") { 257*6777b538SAndroid Build Coastguard Worker rust_abi_target = "aarch64-apple-darwin" 258*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "x64") { 259*6777b538SAndroid Build Coastguard Worker rust_abi_target = "x86_64-apple-darwin" 260*6777b538SAndroid Build Coastguard Worker } else { 261*6777b538SAndroid Build Coastguard Worker assert(false, "Architecture not supported") 262*6777b538SAndroid Build Coastguard Worker } 263*6777b538SAndroid Build Coastguard Worker} else if (is_win) { 264*6777b538SAndroid Build Coastguard Worker if (current_cpu == "arm64") { 265*6777b538SAndroid Build Coastguard Worker rust_abi_target = "aarch64-pc-windows-msvc" 266*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "x64") { 267*6777b538SAndroid Build Coastguard Worker rust_abi_target = "x86_64-pc-windows-msvc" 268*6777b538SAndroid Build Coastguard Worker } else if (current_cpu == "x86") { 269*6777b538SAndroid Build Coastguard Worker rust_abi_target = "i686-pc-windows-msvc" 270*6777b538SAndroid Build Coastguard Worker } else { 271*6777b538SAndroid Build Coastguard Worker assert(false, "Architecture not supported") 272*6777b538SAndroid Build Coastguard Worker } 273*6777b538SAndroid Build Coastguard Worker} 274*6777b538SAndroid Build Coastguard Worker 275*6777b538SAndroid Build Coastguard Workerassert(!toolchain_has_rust || rust_abi_target != "") 276*6777b538SAndroid Build Coastguard Worker 277*6777b538SAndroid Build Coastguard Worker# This variable is passed to the Rust libstd build. 278*6777b538SAndroid Build Coastguard Workerrust_target_arch = "" 279*6777b538SAndroid Build Coastguard Workerif (current_cpu == "x86") { 280*6777b538SAndroid Build Coastguard Worker rust_target_arch = "x86" 281*6777b538SAndroid Build Coastguard Worker} else if (current_cpu == "x64") { 282*6777b538SAndroid Build Coastguard Worker rust_target_arch = "x86_64" 283*6777b538SAndroid Build Coastguard Worker} else if (current_cpu == "arm") { 284*6777b538SAndroid Build Coastguard Worker rust_target_arch = "arm" 285*6777b538SAndroid Build Coastguard Worker} else if (current_cpu == "arm64") { 286*6777b538SAndroid Build Coastguard Worker rust_target_arch = "aarch64" 287*6777b538SAndroid Build Coastguard Worker} else if (current_cpu == "mipsel") { 288*6777b538SAndroid Build Coastguard Worker rust_target_arch = "mips" 289*6777b538SAndroid Build Coastguard Worker} else if (current_cpu == "mips64el") { 290*6777b538SAndroid Build Coastguard Worker rust_target_arch = "mips64" 291*6777b538SAndroid Build Coastguard Worker} else if (current_cpu == "s390x") { 292*6777b538SAndroid Build Coastguard Worker rust_target_arch = "s390x" 293*6777b538SAndroid Build Coastguard Worker} else if (current_cpu == "ppc64") { 294*6777b538SAndroid Build Coastguard Worker rust_target_arch = "powerpc64" 295*6777b538SAndroid Build Coastguard Worker} else if (current_cpu == "riscv64") { 296*6777b538SAndroid Build Coastguard Worker rust_target_arch = "riscv64" 297*6777b538SAndroid Build Coastguard Worker} 298*6777b538SAndroid Build Coastguard Worker 299*6777b538SAndroid Build Coastguard Workerassert(!toolchain_has_rust || rust_target_arch != "") 300*6777b538SAndroid Build Coastguard Worker 301*6777b538SAndroid Build Coastguard Worker# Arguments for Rust invocation. 302*6777b538SAndroid Build Coastguard Worker# This is common between gcc/clang, Mac and Windows toolchains so specify once, 303*6777b538SAndroid Build Coastguard Worker# here. This is not the complete command-line: toolchains should add -o 304*6777b538SAndroid Build Coastguard Worker# and probably --emit arguments too. 305*6777b538SAndroid Build Coastguard Workerrustc_common_args = "--crate-name {{crate_name}} {{source}} --crate-type {{crate_type}} {{rustflags}}" 306*6777b538SAndroid Build Coastguard Worker 307*6777b538SAndroid Build Coastguard Worker# Rust procedural macros are shared objects loaded into a prebuilt host rustc 308*6777b538SAndroid Build Coastguard Worker# binary. To build them, we obviously need to build for the host. Not only 309*6777b538SAndroid Build Coastguard Worker# that, but because the host rustc is prebuilt, it lacks the machinery to be 310*6777b538SAndroid Build Coastguard Worker# able to load shared objects built using sanitizers (ASAN etc.). For that 311*6777b538SAndroid Build Coastguard Worker# reason, we need to use a host toolchain that lacks sanitizers. Additionally, 312*6777b538SAndroid Build Coastguard Worker# proc macros should use panic=unwind, which means they need a stdlib that is 313*6777b538SAndroid Build Coastguard Worker# compiled the same way, as is the stdlib that we ship with the compiler. 314*6777b538SAndroid Build Coastguard Workerif (toolchain_for_rust_host_build_tools) { 315*6777b538SAndroid Build Coastguard Worker rust_macro_toolchain = current_toolchain 316*6777b538SAndroid Build Coastguard Worker} else { 317*6777b538SAndroid Build Coastguard Worker rust_macro_toolchain = "${host_toolchain}_for_rust_host_build_tools" 318*6777b538SAndroid Build Coastguard Worker} 319*6777b538SAndroid Build Coastguard Worker 320*6777b538SAndroid Build Coastguard Worker# When this is true, a prebuilt Rust stdlib will be used. This has implications 321*6777b538SAndroid Build Coastguard Worker# such as that the panic strategy (unwind, abort) must match how the stdlib is 322*6777b538SAndroid Build Coastguard Worker# compiled, which is typically as unwind. 323*6777b538SAndroid Build Coastguard Workerrust_prebuilt_stdlib = 324*6777b538SAndroid Build Coastguard Worker !use_chromium_rust_toolchain || toolchain_for_rust_host_build_tools 325