blob: 4228fff899a2f2023896bcf99af4de0377be0c64 [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")
if (is_mac) {
# For mac_sdk_min:
import("//build/config/mac/mac_sdk.gni")
}
default_rustc_prefix =
rebase_path("//prebuilt/third_party/rust/${host_platform}/bin",
root_build_dir)
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
# Sets the default LTO type for rustc bulids.
rust_lto = ""
# Sets the panic type for Rust on fuchsia.
# Valid values are "unwind" and "abort".
rust_panic = "abort"
# 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 = ""
}
assert(rust_panic == "unwind" || rust_panic == "abort",
"rust_panic was neither 'unwind' nor 'panic'")
# Always use panic=unwind on host, or proc macros won't work.
if (!is_fuchsia) {
rust_panic = "unwind"
}
_sysroot = sysroot
sysroot_deps = []
# TODO(BLD-230): sysroot.gni should provide the correct label and path to the Fuchsia sysroot.
if (is_fuchsia) {
sysroot_deps = [ "//sdk:zircon_sysroot_export" ]
_sysroot = rebase_path(
"$root_out_dir/sdk/exported/zircon_sysroot/arch/$target_cpu/sysroot")
}
std_deps = []
if (is_fuchsia) {
std_deps += [
# These libraries are required by libstd.
"//zircon/public/lib/backtrace",
"//zircon/public/lib/fdio",
]
}
_platform_args = []
if (is_mac) {
_platform_args += [
"--mmacosx-version-min",
mac_sdk_min,
]
}
assert(current_os == "mac" || current_os == "linux" || current_os == "fuchsia",
"current_os was neither mac, linux, nor fuchsia")
assert(current_cpu == "x64" || current_cpu == "arm64")
if (current_os == "mac") {
_suffix = "apple-darwin"
} else if (current_os == "linux") {
_suffix = "unknown-linux-gnu"
} 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}"
}
_host_os_cpu = "${host_os}-${host_cpu}"
if ("linux-x64" == _host_os_cpu) {
host = "x86_64-unknown-linux-gnu"
} else if ("linux-arm64" == _host_os_cpu) {
host = "aarch64-unknown-linux-gnu"
} else if ("mac-x64" == _host_os_cpu) {
host = "x86_64-apple-darwin"
} else {
assert(false, "Unsupported host os/cpu: ${_host_os_cpu}")
}
clang_prefix_rebased = rebase_path(clang_prefix, "", root_build_dir)
clang_resource_dir = exec_script(rebase_path("$clang_prefix_rebased/clang"),
[
"--target=$rust_target",
"-print-resource-dir",
],
"trim string",
[])
# rust_config collects common arguments and dependencies for rustc builds
cmake_dir = rebase_path("//prebuilt/third_party/cmake/${host_platform}/bin")
rust_build_args =
[
"--rustc",
"$rustc_prefix/rustc",
"--cmake-dir",
cmake_dir,
"--lib-dir",
rebase_path(get_label_info(":any($shlib_toolchain)", "root_out_dir")),
"--target",
rust_target,
"--sysroot",
_sysroot,
"--clang_prefix",
clang_prefix_rebased,
"--clang-resource-dir",
clang_resource_dir,
"--symbol-level",
"$symbol_level",
"--panic",
rust_panic,
] + _platform_args
rust_build_deps = sysroot_deps + std_deps
# We want to force a recompile of the Rust world whenever Rust toolchain
# changes since artifacts from an older version of the toolchain may or
# may not be compatible with newer ones.
# To achieve this, we insert a build dependency on the rust version.
rust_build_inputs = [
"//prebuilt/third_party/rust/${host_platform}/.versions/rust.cipd_version",
]