Obtain the namespace hierarchy from IR

The `cc_import!` macro is supposed to merge namespaces (== rust modules) across targets. For that, Crubit needs to emit a (JSON) file with the namespace hierarchy for each target.

This cl introduces the mechanism for obtaining the namespace hierarchy.

PiperOrigin-RevId: 471473231
diff --git a/rs_bindings_from_cc/BUILD b/rs_bindings_from_cc/BUILD
index 49ab94b..f6c2490 100644
--- a/rs_bindings_from_cc/BUILD
+++ b/rs_bindings_from_cc/BUILD
@@ -537,3 +537,32 @@
         "@crate_index//:quote",
     ],
 )
+
+cc_library(
+    name = "collect_namespaces",
+    srcs = ["collect_namespaces.cc"],
+    hdrs = ["collect_namespaces.h"],
+    visibility = ["//:__subpackages__"],
+    deps = [
+        ":cc_ir",
+        "@absl//absl/container:btree",
+        "@absl//absl/container:flat_hash_map",
+        "@absl//absl/strings",
+        "@llvm-project//llvm:Support",
+    ],
+)
+
+cc_test(
+    name = "collect_namespaces_test",
+    srcs = ["collect_namespaces_test.cc"],
+    deps = [
+        ":cc_ir",
+        ":collect_namespaces",
+        ":ir_from_cc",
+        "@absl//absl/status",
+        "@absl//absl/status:statusor",
+        "@absl//absl/strings",
+        "@absl//absl/types:span",
+        "@com_google_googletest//:gtest_main",
+    ],
+)