blob: f668bfa972d848ade36e19791d5be2c1727b2bfd [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/rust/toolchain.gni")
import("//build/toolchain/basic_toolchain.gni")
import("//build/toolchain/concurrent_jobs.gni")
declare_args() {
# Maximum number of Rust processes to run in parallel.
#
# We run multiple rustc jobs in parallel, each of which can cause significant
# amount of memory, especially when using LTO. To avoid out-of-memory errors
# we explicitly reduce the number of jobs.
concurrent_rust_jobs = default_concurrent_jobs.rust
}
if (current_toolchain == default_toolchain) {
pool("pool") {
depth = concurrent_rust_jobs
}
}
# A toolchain dedicated to processing Rust code.
# The only targets in this toolchain are action() targets, so it
# has no real tools. But every toolchain needs stamp and copy.
basic_toolchain("rustlang") {
expected_label = rust_toolchain
}
cargo_toml_gen_desc_out = "$target_out_dir/cargo_toml_gen_desc.json"
action("cargo_toml_gen_desc") {
visibility = [ ":cargo_toml_gen" ]
script = "//scripts/generate_cargo_desc.py"
sources = []
inputs = []
outputs = [ cargo_toml_gen_desc_out ]
depfile = "$cargo_toml_gen_desc_out.d"
args = [
"--root_build_dir",
".",
"--fuchsia_dir",
rebase_path("//", root_build_dir),
"--gn_binary",
rebase_path("//prebuilt/third_party/gn/${host_platform}/gn",
root_build_dir),
"--output",
rebase_path(cargo_toml_gen_desc_out, root_build_dir),
"--depfile",
rebase_path("$cargo_toml_gen_desc_out.d", root_build_dir),
]
}
# NOTE: This target is used by "fx set --cargo-toml-gen ..." which
# will do the following:
#
# 1) Ensure that "fx gen" (and "fx build") will pass `--ide-json`
# to `gn gen`, which generates an up-to-date
# `$root_build_dir/project.json` file, used here as input.
#
# 2) Add this target to the base packages list to ensure its
# action script is run by "fx build".
#
# For more details, see docs/development/language/rust/README.md
#
action("cargo_toml_gen") {
# Nothing in-tree should depend on Cargo files.
# TODO(bwb) remove base_packages visibility when auto-generation is disabled
visibility = [
"//:additional_base_packages",
"//:additional_cache_packages",
"//:additional_universe_packages",
]
script = "//scripts/generate_cargo.py"
sources = []
inputs = [ cargo_toml_gen_desc_out ]
outputs = [ "$root_build_dir/cargo/generate_cargo.stamp" ]
depfile = "$root_build_dir/cargo/generate_cargo.stamp.d"
args = [
rebase_path(cargo_toml_gen_desc_out, root_build_dir),
"--root_build_dir",
".",
"--fuchsia_dir",
rebase_path("//", root_build_dir),
]
deps = [ ":cargo_toml_gen_desc" ]
}