blob: 4d86928ff2295e4d1b85f3531b713c1c788f7c01 [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/config.gni")
}
declare_args() {
# Sets a custom base directory for `rustc` and `cargo`.
# This can be used to test custom Rust toolchains.
rustc_prefix = "//buildtools/${host_platform}/rust/bin"
# Sets the default LTO type for rustc bulids.
rust_lto = "unset"
# Sets the fuchsia toolchain target triple suffix (after arch)
rust_toolchain_triple_suffix = "fuchsia"
# Sets whether Rust compiler warnings cause errors or not.
# "deny" will make all warnings into errors, while "allow" will ignore warnings
rust_warnings = "deny"
}
_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 = [ "//garnet/public/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")
if (current_os == "mac") {
_target = "x86_64-apple-darwin"
assert(current_cpu == "x64")
} else if (current_os == "linux") {
assert(current_cpu == "x64")
_target = "x86_64-unknown-linux-gnu"
} else if (current_os == "fuchsia") {
assert(current_cpu == "x64" || current_cpu == "arm64")
if (current_cpu == "x64") {
_target = "x86_64-$rust_toolchain_triple_suffix"
} else if (current_cpu == "arm64") {
_target = "aarch64-$rust_toolchain_triple_suffix"
}
}
if (is_debug) {
_rust_opt_level = "0"
} else {
_rust_opt_level = "z"
}
clang_prefix_rebased = rebase_path(clang_prefix, "", root_build_dir)
clang_resource_dir = exec_script(rebase_path("$clang_prefix_rebased/clang"),
[
"--target=$_target",
"-print-resource-dir",
],
"trim string",
[])
# rust_config collects common arguments and dependencies for rustc builds
rust_build_args = [
"--rustc",
rebase_path("$rustc_prefix/rustc"),
"--cmake-dir",
rebase_path("//buildtools/cmake/bin"),
"--shared-libs-root",
rebase_path(get_label_info("//default($shlib_toolchain)",
"root_out_dir")),
"--target",
_target,
"--sysroot",
_sysroot,
"--clang_prefix",
rebase_path(clang_prefix_rebased, "", root_build_dir),
"--clang-resource-dir",
clang_resource_dir,
"--opt-level",
_rust_opt_level,
"--symbol-level",
"$symbol_level",
] + _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 =
[ "//buildtools/${host_platform}/rust/.versions/rust.cipd_version" ]