[rust] Fix some oddities of rustc_staticlib
Previously, if `name` was unset, `rustc_staticlib`'s outputs would
have long, nonsensical names. This change forwards on the target_name
parameter as `name` when `name` is unset to prevent this.
This change also moves from using `get_target_outputs` to recalculating
the path to the output binary, since `get_target_outputs` would also
include any test binaries generated as part of the build target.
Test: successfully built a rustc_staticlib target that contained
`with_unit_tests = true`.
Change-Id: I45b0f4cf18c064d0159e93497f3931ded0710d7d
diff --git a/rust/rustc_staticlib.gni b/rust/rustc_staticlib.gni
index 9fa0bdf..ff1148d 100644
--- a/rust/rustc_staticlib.gni
+++ b/rust/rustc_staticlib.gni
@@ -51,10 +51,15 @@
rustc_target = "_${target_name}_rustc_artifact"
group_target = "${target_name}"
+ if (defined(invoker.name)) {
+ rustc_artifact_name = invoker.name
+ } else {
+ rustc_artifact_name = target_name
+ }
+
rustc_artifact(rustc_target) {
forward_variables_from(invoker,
[
- "name",
"version",
"deps",
"edition",
@@ -64,6 +69,7 @@
"source_root",
"testonly",
])
+ name = rustc_artifact_name
type = "staticlib"
}
@@ -80,8 +86,12 @@
visibility = [ ":$group_target" ]
}
+ first_party_crate_root = "${root_out_dir}/rust_crates"
+ crate_name = string_replace(rustc_artifact_name, "-", "_")
+ build_output = "${first_party_crate_root}/staticlib${crate_name}.a"
+
config(config_target) {
- libs = get_target_outputs(":${rustc_target}_build")
+ libs = [build_output]
visibility = [ ":$group_target" ]
}