1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-29 02:29:06 -05:00
denoland-deno/build_extra/rust/rust.gni
2018-07-12 17:38:51 -04:00

230 lines
5.6 KiB
Text

stdlib_label = "//build_extra/rust:stdlib"
declare_args() {
# Absolute path of rust build files.
rust_build = "//build_extra/rust/"
}
if (is_win) {
executable_suffix = ".exe"
} else {
executable_suffix = ""
}
template("run_rustc") {
action(target_name) {
assert(defined(invoker.source_root), "Must specify source_root")
forward_variables_from(invoker,
[
"cfg",
"crate_type",
"source_root",
"deps",
"extern",
"is_test",
])
if (defined(invoker.testonly)) {
testonly = invoker.testonly
}
if (defined(invoker.crate_name)) {
crate_name = invoker.crate_name
} else {
crate_name = target_name
}
sources = [
source_root,
]
outputs = []
script = "//tools/run_rustc.py"
args = [
rebase_path(source_root, root_build_dir),
"--crate-name=$crate_name",
"--crate-type=$crate_type",
]
if (!is_win) {
args += [ "--color=always" ]
}
if (defined(is_test) && is_test) {
# Test outputs are executables which should be in root_out_dir.
output_file = "$root_out_dir/$crate_name" + executable_suffix
args += [
"--test",
"-o",
rebase_path(output_file, root_build_dir),
]
outputs += [ output_file ]
} else {
# Non-test targets are handled differently.
if (crate_type == "staticlib") {
output_file = "$target_out_dir/$crate_name.a"
emit_type = "link"
} else if (crate_type == "bin") {
output_file = "$target_out_dir/$crate_name.o"
emit_type = "obj"
} else if (crate_type == "rlib") {
output_file = "$target_out_dir/lib$crate_name.rlib"
emit_type = "link"
}
outputs += [ output_file ]
output_file_rel = rebase_path(output_file, root_build_dir)
args += [ "--emit=$emit_type=$output_file_rel" ]
# TODO(ry) For unknown reasons emitting a depfile on tests doesn't work.
depfile = "$target_out_dir/$crate_name.d"
args += [
"--emit=dep-info=" + rebase_path(depfile, root_build_dir),
# The following two args are used by run_rustc.py to fix
# the depfile on the fly. They are not passed thru to rustc.
"--depfile=" + rebase_path(depfile, root_build_dir),
"--output_file=" + output_file_rel,
]
}
if (is_debug) {
args += [ "-g" ]
}
if (is_official_build) {
args += [ "-O" ]
}
if (defined(cfg)) {
foreach(c, cfg) {
args += [
"--cfg",
c,
]
}
}
if (!defined(deps)) {
deps = []
}
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"
args += [
"--extern",
"$name=" + rebase_path(rlib, root_build_dir),
]
# This is needed for transitive dependencies.
args += [
"-L",
"dependency=" + rebase_path(dir, root_build_dir),
]
}
}
}
}
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",
"extern",
"cfg",
"source_root",
"testonly",
])
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",
"testonly",
])
if (!defined(deps)) {
deps = []
}
if (!defined(libs)) {
libs = []
}
libs += [ crate_obj ]
deps += [ rustc_label ]
}
}
template("rust_staticlib") {
rust_component(target_name) {
crate_type = "staticlib"
forward_variables_from(invoker,
[
"crate_name",
"extern",
"cfg",
"source_root",
"testonly",
])
if (current_os == "mac") {
libs = [ "resolv" ]
}
if (current_os == "win") {
libs = [ "userenv.lib" ]
}
}
}
template("rust_executable") {
bin_name = target_name + "_bin"
bin_label = ":" + bin_name
rust_component(bin_name) {
crate_type = "bin"
forward_variables_from(invoker, "*")
}
executable(target_name) {
forward_variables_from(invoker, "*")
if (!defined(deps)) {
deps = []
}
deps += [
bin_label,
stdlib_label,
]
if (defined(extern)) {
deps += extern
}
}
}
template("rust_test") {
run_rustc(target_name) {
crate_name = target_name
crate_type = "bin"
testonly = true
is_test = true
forward_variables_from(invoker,
[
"extern",
"cfg",
"source_root",
])
}
}