Add rustflags to desc and help output

`gn desc` doesn't list a target's / config's rustflags, even though
TargetDescBuilder already has support for it.

This CL adds rustflags support to ConfigDescBuilder as well, and makes
the desc command print them. While we're already at it, it also adds it
to the help command's output.

Bug: None
Change-Id: Iba66a7011b885be914b959aeafbc4d34fba0b080
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/16520
Reviewed-by: Takuto Ikuta <tikuta@google.com>
Commit-Queue: Takuto Ikuta <tikuta@google.com>
Reviewed-by: David Turner <digit@google.com>
diff --git a/docs/reference.md b/docs/reference.md
index fb886f5..feabe8e 100644
--- a/docs/reference.md
+++ b/docs/reference.md
@@ -151,6 +151,7 @@
     *   [public_deps: [label list] Declare public dependencies.](#var_public_deps)
     *   [rebase: [boolean] Rebase collected metadata as files.](#var_rebase)
     *   [response_file_contents: [string list] Contents of .rsp file for actions.](#var_response_file_contents)
+    *   [rustflags: [string list] Flags passed to the Rust compiler.](#var_rustflags)
     *   [script: [file name] Script file for actions.](#var_script)
     *   [sources: [file list] Source files for a target.](#var_sources)
     *   [swiftflags: [string list] Flags passed to the swift compiler.](#var_swiftflags)
@@ -5093,8 +5094,8 @@
   versions of cflags* will be appended on the compiler command line after
   "cflags".
 
-  See also "asmflags" for flags for assembly-language files and "swiftflags"
-  for swift files.
+  See also "asmflags" for flags for assembly-language files, "swiftflags" for
+  swift files, and "rustflags" for Rust files.
 ```
 
 #### **Ordering of flags and values**
@@ -5127,8 +5128,8 @@
   versions of cflags* will be appended on the compiler command line after
   "cflags".
 
-  See also "asmflags" for flags for assembly-language files and "swiftflags"
-  for swift files.
+  See also "asmflags" for flags for assembly-language files, "swiftflags" for
+  swift files, and "rustflags" for Rust files.
 ```
 
 #### **Ordering of flags and values**
@@ -5161,8 +5162,8 @@
   versions of cflags* will be appended on the compiler command line after
   "cflags".
 
-  See also "asmflags" for flags for assembly-language files and "swiftflags"
-  for swift files.
+  See also "asmflags" for flags for assembly-language files, "swiftflags" for
+  swift files, and "rustflags" for Rust files.
 ```
 
 #### **Ordering of flags and values**
@@ -5195,8 +5196,8 @@
   versions of cflags* will be appended on the compiler command line after
   "cflags".
 
-  See also "asmflags" for flags for assembly-language files and "swiftflags"
-  for swift files.
+  See also "asmflags" for flags for assembly-language files, "swiftflags" for
+  swift files, and "rustflags" for Rust files.
 ```
 
 #### **Ordering of flags and values**
@@ -5229,8 +5230,8 @@
   versions of cflags* will be appended on the compiler command line after
   "cflags".
 
-  See also "asmflags" for flags for assembly-language files and "swiftflags"
-  for swift files.
+  See also "asmflags" for flags for assembly-language files, "swiftflags" for
+  swift files, and "rustflags" for Rust files.
 ```
 
 #### **Ordering of flags and values**
@@ -6620,6 +6621,13 @@
     ]
   }
 ```
+### <a name="var_rustflags"></a>**rustflags**: Flags passed to the Rust compiler.
+
+```
+  A list of strings.
+
+  "rustflags" are passed to all invocations of the Rust compiler.
+```
 ### <a name="var_script"></a>**script**: Script file for actions.
 
 ```
diff --git a/src/gn/command_desc.cc b/src/gn/command_desc.cc
index 99f7e45..95652f1 100644
--- a/src/gn/command_desc.cc
+++ b/src/gn/command_desc.cc
@@ -306,6 +306,7 @@
           {variables::kWriteOutputConversion, DefaultHandler},
           {variables::kRustCrateName, DefaultHandler},
           {variables::kRustCrateRoot, DefaultHandler},
+          {variables::kRustflags, DefaultHandler},
           {variables::kSwiftModuleName, DefaultHandler},
           {variables::kSwiftBridgeHeader, DefaultHandler},
           {variables::kMnemonic, DefaultHandler},
@@ -399,6 +400,7 @@
   HandleProperty(variables::kLibDirs, handler_map, v, dict);
   HandleProperty(variables::kDataKeys, handler_map, v, dict);
   HandleProperty(variables::kRebase, handler_map, v, dict);
+  HandleProperty(variables::kRustflags, handler_map, v, dict);
   HandleProperty(variables::kWalkKeys, handler_map, v, dict);
   HandleProperty(variables::kWeakFrameworks, handler_map, v, dict);
   HandleProperty(variables::kWriteOutputConversion, handler_map, v, dict);
@@ -463,6 +465,7 @@
   HandleProperty(variables::kLibDirs, handler_map, v, dict);
   HandleProperty(variables::kPrecompiledHeader, handler_map, v, dict);
   HandleProperty(variables::kPrecompiledSource, handler_map, v, dict);
+  HandleProperty(variables::kRustflags, handler_map, v, dict);
   HandleProperty(variables::kWeakFrameworks, handler_map, v, dict);
 
 #undef HandleProperty
diff --git a/src/gn/desc_builder.cc b/src/gn/desc_builder.cc
index 58bebef..093cad9 100644
--- a/src/gn/desc_builder.cc
+++ b/src/gn/desc_builder.cc
@@ -282,6 +282,7 @@
     CONFIG_VALUE_ARRAY_HANDLER(ldflags, std::string)
     CONFIG_VALUE_ARRAY_HANDLER(lib_dirs, SourceDir)
     CONFIG_VALUE_ARRAY_HANDLER(libs, LibFile)
+    CONFIG_VALUE_ARRAY_HANDLER(rustflags, std::string)
     CONFIG_VALUE_ARRAY_HANDLER(swiftflags, std::string)
 
 #undef CONFIG_VALUE_ARRAY_HANDLER
diff --git a/src/gn/rust_variables.cc b/src/gn/rust_variables.cc
index 651eb07..7474286 100644
--- a/src/gn/rust_variables.cc
+++ b/src/gn/rust_variables.cc
@@ -95,6 +95,17 @@
   only one file.
 )";
 
+const char kRustflags[] = "rustflags";
+const char kRustflags_HelpShort[] =
+    "rustflags: [string list] Flags passed to the Rust compiler.";
+const char kRustflags_Help[] =
+      R"(rustflags: Flags passed to the Rust compiler.
+
+  A list of strings.
+
+  "rustflags" are passed to all invocations of the Rust compiler.
+)";
+
 void InsertRustVariables(VariableInfoMap* info_map) {
   info_map->insert(std::make_pair(
       kRustAliasedDeps,
@@ -108,6 +119,9 @@
   info_map->insert(std::make_pair(
       kRustCrateRoot,
       VariableInfo(kRustCrateRoot_HelpShort, kRustCrateRoot_Help)));
+  info_map->insert(std::make_pair(
+      kRustflags,
+      VariableInfo(kRustflags_HelpShort, kRustflags_Help)));
 }
 
 }  // namespace variables
diff --git a/src/gn/rust_variables.h b/src/gn/rust_variables.h
index ea2da6d..bade18d 100644
--- a/src/gn/rust_variables.h
+++ b/src/gn/rust_variables.h
@@ -31,8 +31,12 @@
 extern const char kRustEdition_HelpShort[];
 extern const char kRustEdition_Help[];
 
+extern const char kRustflags[];
+extern const char kRustflags_HelpShort[];
+extern const char kRustflags_Help[];
+
 void InsertRustVariables(VariableInfoMap* info_map);
 
 }  // namespace variables
 
-#endif  // TOOLS_GN_RUST_VARIABLES_H_
\ No newline at end of file
+#endif  // TOOLS_GN_RUST_VARIABLES_H_
diff --git a/src/gn/variables.cc b/src/gn/variables.cc
index 9cc3398..4949929 100644
--- a/src/gn/variables.cc
+++ b/src/gn/variables.cc
@@ -788,8 +788,8 @@
   versions of cflags* will be appended on the compiler command line after
   "cflags".
 
-  See also "asmflags" for flags for assembly-language files and "swiftflags"
-  for swift files.
+  See also "asmflags" for flags for assembly-language files, "swiftflags" for
+  swift files, and "rustflags" for Rust files.
 )" COMMON_ORDERING_HELP;
 const char* kCflags_Help = kCommonCflagsHelp;