summaryrefslogtreecommitdiff
path: root/build_extra/rust/rust.gni
diff options
context:
space:
mode:
Diffstat (limited to 'build_extra/rust/rust.gni')
-rw-r--r--build_extra/rust/rust.gni153
1 files changed, 153 insertions, 0 deletions
diff --git a/build_extra/rust/rust.gni b/build_extra/rust/rust.gni
new file mode 100644
index 000000000..e3c412be2
--- /dev/null
+++ b/build_extra/rust/rust.gni
@@ -0,0 +1,153 @@
+stdlib_label = "//build_extra/rust:stdlib"
+
+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",
+ "rust_deps",
+ ])
+ if (defined(invoker.crate_name)) {
+ crate_name = invoker.crate_name
+ } else {
+ crate_name = target_name
+ }
+
+ 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),
+ "--crate-name=$crate_name",
+ "--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") {
+ staticlib = "$target_out_dir/$crate_name.a"
+ outputs += [ staticlib ]
+ args += [ "--emit=link=" + rebase_path(staticlib, root_build_dir) ]
+ }
+
+ if (crate_type == "rlib" || crate_type == "bin") {
+ obj = "$target_out_dir/$crate_name.o"
+ outputs += [ obj ]
+ args += [ "--emit=obj=" + rebase_path(obj, root_build_dir) ]
+ }
+
+ if (crate_type == "rlib") {
+ rlib = "$target_out_dir/lib$crate_name.rlib"
+ 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 = []
+ }
+
+ if (defined(rust_deps)) {
+ deps += rust_deps
+ foreach(dep_label, rust_deps) {
+ dep_name = get_label_info(dep_label, "name")
+ dep_dir = get_label_info(dep_label, "target_out_dir")
+ dep_rlib = "$dep_dir/lib$dep_name.rlib"
+ args += [
+ "--extern",
+ "$dep_name=" + rebase_path(dep_rlib, 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",
+ "rust_deps",
+ "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 ]
+ }
+}
+
+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(rust_deps)) {
+ deps += rust_deps
+ }
+ }
+}