[rust-project] Add "proc_macro" as dep for proc macro targets

This CL also fixes a bug in the rust_tool selection.

Change-Id: Ib7a87aaa83f72a332158c56f12f70cdfed05cf98
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/9620
Commit-Queue: Petr Hosek <phosek@google.com>
Reviewed-by: Petr Hosek <phosek@google.com>
diff --git a/src/gn/rust_project_writer.cc b/src/gn/rust_project_writer.cc
index 2e17eb4..e4ad28f 100644
--- a/src/gn/rust_project_writer.cc
+++ b/src/gn/rust_project_writer.cc
@@ -281,7 +281,7 @@
   // Check what sysroot this target needs.  Add it to the crate list if it
   // hasn't already been added.
   auto rust_tool =
-      target->toolchain()->GetToolForSourceTypeAsRust(SourceFile::SOURCE_RS);
+      target->toolchain()->GetToolForTargetFinalOutputAsRust(target);
   auto current_sysroot = rust_tool->GetSysroot();
   if (current_sysroot != "" && sysroot_lookup.count(current_sysroot) == 0) {
     AddSysroot(build_settings, current_sysroot, sysroot_lookup, crate_list);
@@ -332,6 +332,12 @@
     AddSysrootDependencyToCrate(&crate, sysroot, "core");
     AddSysrootDependencyToCrate(&crate, sysroot, "alloc");
     AddSysrootDependencyToCrate(&crate, sysroot, "std");
+
+    // Proc macros have the proc_macro crate as a direct dependency
+    if (std::string_view(rust_tool->name()) ==
+        std::string_view(RustTool::kRsToolMacro)) {
+      AddSysrootDependencyToCrate(&crate, sysroot, "proc_macro");
+    }
   }
 
   // Add the rest of the crate dependencies.