Cease to specify extern dirs for proc macro deps.

Previously, if we had this arrangement:

  [Rust binary]
   -> depends on ->
  [Rust proc macro]
   -> depends on ->
  [Rust library]

then the Rust library would be stored as a transitive dependency of the
Rust binary. This was unnecessary because Rust procedural macros are
complete standalone .so files, with no further references to the rlibs
from which they are composed.

The practical implication here is just a few extra unnecessary
  -Ldependency
arguments to specify where to find such rlibs.

However, subsequent commits use the list of transitive dependencies for
more purposes, and this problem becomes more serious.

Change-Id: I0310d60db1cab97fa6a808c9a08f663e53eba2ad
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/8300
Commit-Queue: Brett Wilson <brettw@chromium.org>
Reviewed-by: Brett Wilson <brettw@chromium.org>
diff --git a/src/gn/ninja_rust_binary_target_writer_unittest.cc b/src/gn/ninja_rust_binary_target_writer_unittest.cc
index 7cfd63d..be19f3b 100644
--- a/src/gn/ninja_rust_binary_target_writer_unittest.cc
+++ b/src/gn/ninja_rust_binary_target_writer_unittest.cc
@@ -566,6 +566,19 @@
   Err err;
   TestWithScope setup;
 
+  Target procmacrodep(setup.settings(),
+                      Label(SourceDir("//baz/"), "mymacrodep"));
+  procmacrodep.set_output_type(Target::RUST_LIBRARY);
+  procmacrodep.visibility().SetPublic();
+  SourceFile bazlib("//baz/lib.rs");
+  procmacrodep.sources().push_back(SourceFile("//baz/mylib.rs"));
+  procmacrodep.sources().push_back(bazlib);
+  procmacrodep.source_types_used().Set(SourceFile::SOURCE_RS);
+  procmacrodep.rust_values().set_crate_root(bazlib);
+  procmacrodep.rust_values().crate_name() = "mymacrodep";
+  procmacrodep.SetToolchain(setup.toolchain());
+  ASSERT_TRUE(procmacrodep.OnResolved(&err));
+
   Target procmacro(setup.settings(), Label(SourceDir("//bar/"), "mymacro"));
   procmacro.set_output_type(Target::RUST_PROC_MACRO);
   procmacro.visibility().SetPublic();
@@ -576,6 +589,9 @@
   procmacro.rust_values().set_crate_root(barlib);
   procmacro.rust_values().crate_name() = "mymacro";
   procmacro.rust_values().set_crate_type(RustValues::CRATE_PROC_MACRO);
+  // Add a dependency to the procmacro so we can be sure its output
+  // directory is not propagated downstream beyond the proc macro.
+  procmacro.private_deps().push_back(LabelTargetPair(&procmacrodep));
   procmacro.SetToolchain(setup.toolchain());
   ASSERT_TRUE(procmacro.OnResolved(&err));
 
@@ -596,9 +612,9 @@
         "target_output_name = libmymacro\n"
         "\n"
         "build obj/bar/libmymacro.so: rust_macro ../../bar/lib.rs | "
-        "../../bar/mylib.rs ../../bar/lib.rs\n"
-        "  externs =\n"
-        "  rustdeps =\n";
+        "../../bar/mylib.rs ../../bar/lib.rs obj/baz/libmymacrodep.rlib\n"
+        "  externs = --extern mymacrodep=obj/baz/libmymacrodep.rlib\n"
+        "  rustdeps = -Ldependency=obj/baz\n";
     std::string out_str = out.str();
     EXPECT_EQ(expected, out_str) << expected << "\n" << out_str;
   }
diff --git a/src/gn/target.cc b/src/gn/target.cc
index ef91167..115ab8e 100644
--- a/src/gn/target.cc
+++ b/src/gn/target.cc
@@ -630,8 +630,7 @@
     inherited_libraries_.Append(dep, is_public);
   }
 
-  if (dep->output_type() == RUST_LIBRARY ||
-      dep->output_type() == RUST_PROC_MACRO) {
+  if (dep->output_type() == RUST_LIBRARY) {
     rust_values().transitive_libs().Append(dep, is_public);
     rust_values().transitive_libs().AppendInherited(
         dep->rust_values().transitive_libs(), is_public);
@@ -646,6 +645,11 @@
                                     is_public && inherited.second);
       }
     }
+  } else if (dep->output_type() == RUST_PROC_MACRO) {
+    // We will need to specify the path to find a procedural macro,
+    // but have no need to specify the paths to find its dependencies
+    // as the procedural macro is now a complete .so.
+    rust_values().transitive_libs().Append(dep, is_public);
   } else if (dep->output_type() == SHARED_LIBRARY) {
     // Shared library dependendencies are inherited across public shared
     // library boundaries.