[rust-project] Add "test" and "debug_assertion" to target crates For all non-sysroot crates (those that are targets), add the "test" and "debug_assertion" cfg options. These have been removed from the default config options in rust-analyzer. Change-Id: I4bf6ee2995caf0249964710dd8e2e68cc7a3a1f0 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/8760 Commit-Queue: Aaron Wood <aaronwood@google.com> Reviewed-by: Petr Hosek <phosek@google.com> Reviewed-by: Tyler Mandry <tmandry@google.com>
diff --git a/src/gn/rust_project_writer.cc b/src/gn/rust_project_writer.cc index 1dc9f7a..1845aee 100644 --- a/src/gn/rust_project_writer.cc +++ b/src/gn/rust_project_writer.cc
@@ -169,6 +169,8 @@ Crate sysroot_crate = Crate(SourceFile(crate_path), crate_index, std::string(crate), "2018"); + sysroot_crate.AddConfigItem("debug_assertions"); + if (deps_lookup != sysroot_deps_map.end()) { auto deps = (*deps_lookup).second; for (auto dep : deps) { @@ -255,6 +257,9 @@ Crate crate = Crate(crate_root, crate_id, crate_label, edition); + crate.AddConfigItem("test"); + crate.AddConfigItem("debug_assertions"); + for (auto& cfg : cfgs) { crate.AddConfigItem(cfg); }
diff --git a/src/gn/rust_project_writer_helpers_unittest.cc b/src/gn/rust_project_writer_helpers_unittest.cc index 19501c4..23657ee 100644 --- a/src/gn/rust_project_writer_helpers_unittest.cc +++ b/src/gn/rust_project_writer_helpers_unittest.cc
@@ -123,6 +123,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -137,6 +138,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -147,6 +149,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -157,6 +160,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -183,6 +187,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -193,6 +198,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -203,6 +209,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -213,6 +220,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -223,6 +231,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -233,6 +242,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -243,6 +253,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -253,6 +264,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -263,6 +275,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -273,6 +286,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -283,6 +297,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -293,6 +308,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -303,6 +319,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -313,6 +330,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -323,6 +341,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -333,6 +352,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -343,6 +363,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -353,6 +374,7 @@ " ],\n" " \"edition\": \"2018\",\n" " \"cfg\": [\n" + " \"debug_assertions\"\n" " ]\n" " }\n" " ]\n"
diff --git a/src/gn/rust_project_writer_unittest.cc b/src/gn/rust_project_writer_unittest.cc index a1910e7..7891576 100644 --- a/src/gn/rust_project_writer_unittest.cc +++ b/src/gn/rust_project_writer_unittest.cc
@@ -54,6 +54,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\",\n" " \"feature=\\\"foo_enabled\\\"\"\n" " ]\n" " }\n" @@ -112,6 +114,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -126,6 +130,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\"\n" " ]\n" " }\n" " ]\n" @@ -195,6 +201,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -205,6 +213,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -223,6 +233,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\"\n" " ]\n" " }\n" " ]\n" @@ -306,6 +318,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -316,6 +330,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\"\n" " ]\n" " },\n" " {\n" @@ -334,6 +350,8 @@ " ],\n" " \"edition\": \"2015\",\n" " \"cfg\": [\n" + " \"test\",\n" + " \"debug_assertions\"\n" " ]\n" " }\n" " ]\n"