blob: 9e7a22faea24c6b3a835b785f1e9bba45fe309d8 [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/rust/rustc_artifact.gni") # for rustc_third_party_artifact
third_party_lock = "//third_party/rust-crates/rustc_deps/Cargo.lock"
third_party_toml = "//third_party/rust-crates/rustc_deps/Cargo.toml"
fuchsia_zircon_dir = "//garnet/public/rust/crates/fuchsia-zircon"
fuchsia_zircon_sys_dir = "${fuchsia_zircon_dir}/fuchsia-zircon-sys"
fuchsia_zircon_src = exec_script(
"//build/rust/list_files_in_dir.py",
["--dir", rebase_path("${fuchsia_zircon_dir}/src")],
"list lines",
# lib.rs will contain `mod` statements for all top-level files
[rebase_path("${fuchsia_zircon_dir}/src/lib.rs")]
)
fuchsia_zircon_sys_src = exec_script(
"//build/rust/list_files_in_dir.py",
["--dir", rebase_path("${fuchsia_zircon_sys_dir}/src")],
"list lines",
# lib.rs will contain `mod` statements for all top-level files
[rebase_path("${fuchsia_zircon_sys_dir}/src/lib.rs")]
)
third_party_crate_names = exec_script(
"//build/rust/list_3p_crates.py",
["--cargo-toml", rebase_path(third_party_toml)],
"list lines",
[third_party_toml]
)
foreach(crate_name, third_party_crate_names) {
rustc_third_party_artifact(crate_name) {
crate_name = crate_name
}
}
# This target is implicitly depended upon by every
# rustc_artifact (rustc_binary or rustc_library) target
action("build-third-party") {
script = "//build/rust/compile_3p_crates.py"
# 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 synthetic argument to the script invocation.
cipd_version = read_file(
"//buildtools/${host_platform}/rust/.versions/rust.cipd_version",
"json")
inputs = [ third_party_lock, third_party_toml ]
inputs += fuchsia_zircon_src
inputs += fuchsia_zircon_sys_src
deps = [ "//garnet/public/sdk:zircon_sysroot_export" ]
if (is_debug) {
opt_level = "0"
} else {
opt_level = "z"
}
assert(
current_os == "mac" || current_os == "linux" || current_os == "fuchsia",
"current_os was neither mac, linux, nor fuchsia"
)
if (current_os == "mac") {
target_triple = "x86_64-apple-darwin"
assert(current_cpu == "x64")
} else if (current_os == "linux") {
assert(current_cpu == "x64")
target_triple = "x86_64-unknown-linux-gnu"
} else if (current_os == "fuchsia") {
assert(current_cpu == "x64" || current_cpu == "arm64")
if (current_cpu == "x64") {
target_triple = "x86_64-unknown-fuchsia"
} else if (current_cpu == "arm64") {
target_triple = "aarch64-unknown-fuchsia"
}
}
out_dir = "${root_out_dir}/rust_third_party"
out_deps_data = "${out_dir}/deps_data.json"
args = [
"--rustc", rebase_path("${rustc_prefix}/rustc"),
"--cipd-version", cipd_version.instance_id,
"--cargo", rebase_path("${rustc_prefix}/cargo"),
"--crate-root", rebase_path("//third_party/rust-crates/rustc_deps"),
"--opt-level", opt_level,
"--out-dir", rebase_path(out_dir),
"--out-deps-data", rebase_path(out_deps_data),
"--target", target_triple,
"--cmake-dir", rebase_path("//buildtools/cmake/bin"),
"--shared-libs-root", rebase_path(
get_label_info("//default($shlib_toolchain)", "root_out_dir")),
"--clang_prefix", rebase_path(clang_prefix, "", root_build_dir),
"--sysroot", rebase_path("$root_build_dir/sdks/zircon_sysroot/arch/$target_cpu/sysroot"),
]
outputs = [ out_deps_data ]
}