2018-07-06 00:58:09 -04:00
|
|
|
stdlib_label = "//build_extra/rust:stdlib"
|
|
|
|
|
|
|
|
template("run_rustc") {
|
2018-07-02 04:59:29 -04:00
|
|
|
action(target_name) {
|
2018-07-06 00:58:09 -04:00
|
|
|
assert(defined(invoker.source_root), "Must specify source_root")
|
2018-07-02 04:59:29 -04:00
|
|
|
forward_variables_from(invoker,
|
|
|
|
[
|
|
|
|
"cfg",
|
|
|
|
"crate_type",
|
|
|
|
"source_root",
|
|
|
|
"deps",
|
2018-07-06 05:33:32 -04:00
|
|
|
"extern",
|
2018-07-02 04:59:29 -04:00
|
|
|
])
|
2018-07-06 00:58:09 -04:00
|
|
|
if (defined(invoker.crate_name)) {
|
|
|
|
crate_name = invoker.crate_name
|
|
|
|
} else {
|
|
|
|
crate_name = target_name
|
|
|
|
}
|
|
|
|
|
2018-07-02 04:59:29 -04:00
|
|
|
sources = [
|
|
|
|
source_root,
|
|
|
|
]
|
|
|
|
outputs = []
|
|
|
|
depfile = "$target_out_dir/$target_name.d"
|
|
|
|
script = "//third_party/v8/tools/run.py"
|
|
|
|
|
|
|
|
args = [
|
|
|
|
"rustc",
|
|
|
|
rebase_path(source_root, root_build_dir),
|
2018-07-06 00:58:09 -04:00
|
|
|
"--crate-name=$crate_name",
|
2018-07-02 04:59:29 -04:00
|
|
|
"--crate-type=$crate_type",
|
|
|
|
"--emit=dep-info=" + rebase_path(depfile, root_build_dir),
|
|
|
|
]
|
|
|
|
|
|
|
|
# We only use staticlib for the special "empty" lib.
|
|
|
|
if (crate_type == "staticlib") {
|
2018-07-06 00:58:09 -04:00
|
|
|
staticlib = "$target_out_dir/$crate_name.a"
|
2018-07-02 04:59:29 -04:00
|
|
|
outputs += [ staticlib ]
|
|
|
|
args += [ "--emit=link=" + rebase_path(staticlib, root_build_dir) ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crate_type == "rlib" || crate_type == "bin") {
|
2018-07-06 00:58:09 -04:00
|
|
|
obj = "$target_out_dir/$crate_name.o"
|
2018-07-02 04:59:29 -04:00
|
|
|
outputs += [ obj ]
|
|
|
|
args += [ "--emit=obj=" + rebase_path(obj, root_build_dir) ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (crate_type == "rlib") {
|
2018-07-06 00:58:09 -04:00
|
|
|
rlib = "$target_out_dir/lib$crate_name.rlib"
|
2018-07-02 04:59:29 -04:00
|
|
|
outputs += [ rlib ]
|
|
|
|
args += [ "--emit=link=" + rebase_path(rlib, root_build_dir) ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_debug) {
|
|
|
|
args += [ "-g" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_official_build) {
|
|
|
|
args += [ "-O" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
if (defined(cfg)) {
|
|
|
|
foreach(c, cfg) {
|
|
|
|
args += [
|
|
|
|
"--cfg",
|
|
|
|
c,
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!defined(deps)) {
|
|
|
|
deps = []
|
|
|
|
}
|
|
|
|
|
2018-07-06 05:33:32 -04:00
|
|
|
if (defined(extern)) {
|
|
|
|
deps += extern
|
|
|
|
foreach(label, extern) {
|
|
|
|
name = get_label_info(label, "name")
|
|
|
|
dir = get_label_info(label, "target_out_dir")
|
|
|
|
rlib = "$dir/lib$name.rlib"
|
2018-07-02 04:59:29 -04:00
|
|
|
args += [
|
|
|
|
"--extern",
|
2018-07-06 05:33:32 -04:00
|
|
|
"$name=" + rebase_path(rlib, root_build_dir),
|
2018-07-02 04:59:29 -04:00
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 00:58:09 -04:00
|
|
|
template("rust_component") {
|
|
|
|
rustc_name = target_name + "_rustc"
|
|
|
|
rustc_label = ":" + rustc_name
|
|
|
|
crate_name = target_name
|
|
|
|
run_rustc(rustc_name) {
|
|
|
|
forward_variables_from(invoker,
|
|
|
|
[
|
|
|
|
"crate_name",
|
|
|
|
"crate_type",
|
2018-07-06 05:33:32 -04:00
|
|
|
"extern",
|
2018-07-06 00:58:09 -04:00
|
|
|
"cfg",
|
|
|
|
"source_root",
|
|
|
|
])
|
|
|
|
if (!defined(invoker.crate_type)) {
|
|
|
|
crate_type = "rlib"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
crate_outputs = get_target_outputs(rustc_label)
|
|
|
|
crate_obj = crate_outputs[0]
|
|
|
|
|
|
|
|
component(target_name) {
|
|
|
|
forward_variables_from(invoker,
|
|
|
|
[
|
|
|
|
"libs",
|
|
|
|
"deps",
|
|
|
|
])
|
|
|
|
if (!defined(deps)) {
|
|
|
|
deps = []
|
|
|
|
}
|
|
|
|
if (!defined(libs)) {
|
|
|
|
libs = []
|
|
|
|
}
|
|
|
|
libs += [ crate_obj ]
|
|
|
|
deps += [ rustc_label ]
|
2018-07-02 04:59:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template("rust_executable") {
|
2018-07-06 00:58:09 -04:00
|
|
|
bin_name = target_name + "_bin"
|
|
|
|
bin_label = ":" + bin_name
|
|
|
|
|
|
|
|
rust_component(bin_name) {
|
2018-07-02 04:59:29 -04:00
|
|
|
crate_type = "bin"
|
|
|
|
forward_variables_from(invoker, "*")
|
|
|
|
}
|
|
|
|
|
|
|
|
executable(target_name) {
|
|
|
|
forward_variables_from(invoker, "*")
|
|
|
|
|
|
|
|
if (!defined(deps)) {
|
|
|
|
deps = []
|
|
|
|
}
|
|
|
|
|
|
|
|
deps += [
|
2018-07-06 00:58:09 -04:00
|
|
|
bin_label,
|
|
|
|
stdlib_label,
|
2018-07-02 04:59:29 -04:00
|
|
|
]
|
|
|
|
|
2018-07-06 05:33:32 -04:00
|
|
|
if (defined(extern)) {
|
|
|
|
deps += extern
|
2018-07-02 04:59:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|