blob: c4523e8f61284ddba205bb62949a927bc5810a18 [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/config.gni") # for rust_build_{args,deps,inputs}
import("//build/rust/rustc_artifact.gni") # for rustc_third_party_artifact
third_party_lock = "//third_party/rust_crates/Cargo.lock"
third_party_toml = "//third_party/rust_crates/Cargo.toml"
third_party_map = "//third_party/rust_crates/crate_map.json"
fuchsia_cprng_dir = "//garnet/public/rust/fuchsia-cprng"
fuchsia_cprng_src =
exec_script("//build/rust/list_files_in_dir.py",
[
"--dir",
rebase_path("${fuchsia_cprng_dir}/src"),
],
"list lines",
# lib.rs will contain `mod` statements for all top-level files
[ rebase_path("${fuchsia_cprng_dir}/src/lib.rs") ])
all_third_party_packages = read_file(third_party_map, "json")
if (is_fuchsia) {
third_party_packages = all_third_party_packages.fuchsia_packages
} else {
third_party_packages = all_third_party_packages.host_packages
}
foreach(package, third_party_packages) {
rustc_third_party_artifact(package.package_name) {
package_name = package.package_name
crate_name = package.crate_name
crate_type = package.crate_type
}
}
# 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"
inputs = [
third_party_lock,
third_party_toml,
]
inputs += fuchsia_cprng_src
out_dir = "${root_out_dir}/rust_third_party_crates"
out_deps_data = "${out_dir}/deps_data.json"
args = [
"--cargo",
rebase_path("${rustc_prefix}/cargo"),
"--crate-root",
rebase_path("//third_party/rust_crates"),
"--host",
host,
"--out-dir",
rebase_path(out_dir),
"--out-deps-data",
rebase_path(out_deps_data),
]
args += rust_build_args
deps = rust_build_deps
inputs += rust_build_inputs
if (rust_override_opt != "") {
rust_opt_level = rust_override_opt
} else if (is_debug) {
rust_opt_level = "0"
} else {
rust_opt_level = "z"
}
args += [
"--opt-level",
rust_opt_level,
]
outputs = [ out_deps_data ]
foreach(package, third_party_packages) {
package_name = package.package_name
crate_name = package.crate_name
if (package.crate_type == "lib") {
ext = ".rlib"
} else if (package.crate_type == "proc-macro") {
if (host_os == "mac") {
ext = ".dylib"
} else {
ext = ".so"
}
} else {
assert(false, "unsupported third-party crate type: " + crate_type)
}
outputs += [ "${root_out_dir}/rust_third_party_crates/lib${crate_name}-${package_name}${ext}" ]
}
}
# Add all the search paths from cargo's output we should look in for deps
config("search_path_config") {
search_path_suffixes = [
"debug/deps",
"release/deps",
]
targets = [
"x86_64-fuchsia",
"aarch64-fuchsia",
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
]
# add in e.g. x86_64-unknown-linux/release/deps
search_path_suffixes_p2 = []
foreach(target, targets) {
foreach(suffix, search_path_suffixes) {
search_path_suffixes_p2 += [ suffix ]
search_path_suffixes_p2 += [ target + "/" + suffix ]
}
}
# both of these xxx_crate_root variables are from rustc_artifact.gni
rebased_3p_root = rebase_path(third_party_crate_root, root_build_dir)
search_paths = [
rebase_path(first_party_crate_root, root_build_dir),
rebased_3p_root,
]
foreach(suffix, search_path_suffixes_p2) {
search_paths += [ rebased_3p_root + "/" + suffix ]
}
rustflags = []
foreach(search_path, search_paths) {
rustflags += [ "-Ldependency=" + search_path ]
}
shared_out_dir = get_label_info(":bogus($shlib_toolchain)", "root_out_dir")
lib_dirs = [ shared_out_dir ]
}