blob: 3dc34b265ca43947453f40fc62954e670f56a885 [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/sysroot.gni")
if (is_mac) {
# For mac_sdk_min:
import("//build/config/mac/mac_sdk.gni")
}
default_rustc_prefix = rebase_path("//sysroot/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 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 = ""
}
_sysroot = sysroot
sysroot_deps = []
# TODO(fxbug.dev/3039): 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.
"//sdk/lib/fdio",
"//zircon/public/lib/backtrace",
]
}
_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"
}
}
_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=$target",
"-print-resource-dir",
],
"trim string",
[])
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 = [
"//sysroot/.versions/rust.cipd_version",
]