blob: 641953d5d778221bc41a300109162e501ee9e829 [file] [log] [blame]
# Copyright 2018 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/clang/clang.gni")
import("//build/config/compiler.gni")
import("//build/config/sysroot.gni")
import("//build/fidl/toolchain.gni")
default_rust_sysroot =
rebase_path("//prebuilt/third_party/rust/${host_platform}", root_build_dir)
default_rustc_prefix =
rebase_path("//prebuilt/third_party/rust/${host_platform}/bin",
root_build_dir)
_rustc_version = read_file(
"//prebuilt/third_party/rust/${host_platform}/.versions/rust.cipd_version",
"json")
default_rustc_version_string = _rustc_version.instance_id
declare_args() {
# Sets a custom base directory for `rustc` and `cargo`.
# This can be used to test custom Rust toolchains.
rustc_prefix = default_rustc_prefix
# This is a string identifying the particular toolchain version in use. Its
# only purpose is to be unique enough that it changes when switching to a new
# toolchain, so that recompilations with the new compiler can be triggered.
#
# When using the prebuilt, this is ignored and the CIPD instance ID of the
# prebuilt is used.
rustc_version_string = default_rustc_version_string
# Human-readable identifier for the toolchain version.
#
# TODO(tmandry): Make this the same repo/revision info from `rustc --version`.
# e.g., clang_version_description = read_file("$_rustc_lib_dir/VERSION")
rustc_version_description = ""
# Sets a custom base directory for where rust tooling
# looks for the standard library
rust_sysroot = default_rust_sysroot
# Sets the default LTO type for rustc bulids.
rust_lto = ""
# Sets the fuchsia toolchain target triple suffix (after arch)
rust_toolchain_triple_suffix = "fuchsia"
# Sets the maximum lint level.
# "deny" will make all warnings into errors, "warn" preserves them as warnings, and "allow" will
# ignore warnings.
rust_cap_lints = "deny"
# Overrides the optimization level for all Rust builds, regardless of
# debug/release flags or the `force_opt` arg to the rustc_ templates.
# Valid values are 0-3, o, and z.
rust_override_opt = ""
# Overrides the LTO setting for all Rust builds, regardless of
# debug/release flags or the `with_lto` arg to the rustc_ templates.
# Valid values are "none", "thin", and "fat".
rust_override_lto = ""
}
if (rustc_prefix == default_rustc_prefix &&
rustc_version_string != default_rustc_version_string) {
# You almost never want to set this when using a prebuilt, it could result in
# failing to rebuild when the prebuilt updates.
print(
"WARNING: Using prebuilt toolchain, but rustc_version_string is set! Toolchain updates won't be detected.")
}
if (is_fuchsia) {
rust_panic = "abort"
} else {
# Always use panic=unwind on host, or proc macros won't work.
rust_panic = "unwind"
}
assert(
current_os == "mac" || current_os == "linux" || current_os == "fuchsia" ||
(current_os == "unknown" && current_cpu == "wasm32") ||
current_os == "win",
"current_os was neither mac, linux, unknown, nor fuchsia")
assert(
current_cpu == "x64" || current_cpu == "arm64" || current_cpu == "wasm32")
if (current_os == "mac") {
_suffix = "apple-darwin"
} else if (current_os == "linux") {
_suffix = "unknown-linux-gnu"
} else if (current_os == "win") {
_suffix = "windows-msvc"
} else if (current_os == "fuchsia") {
_suffix = rust_toolchain_triple_suffix
}
if (current_cpu == "x64") {
rust_target = "x86_64-${_suffix}"
} else if (current_cpu == "arm64") {
rust_target = "aarch64-${_suffix}"
} else if (current_cpu == "wasm32" && current_os == "unknown") {
rust_target = "wasm32-unknown-unknown"
}