rs_bindings_from_cc: Add a reproducer that a forward declaration in a different target precludes bindings of actual definition.
PiperOrigin-RevId: 580463296
Change-Id: Id9ff93b5a8ca8b8d2407af18de0d7e1a9cbcc59b
diff --git a/rs_bindings_from_cc/test/forward_declaration/BUILD b/rs_bindings_from_cc/test/forward_declaration/BUILD
new file mode 100644
index 0000000..8bd7b80
--- /dev/null
+++ b/rs_bindings_from_cc/test/forward_declaration/BUILD
@@ -0,0 +1,39 @@
+load("//common:crubit_wrapper_macros_oss.bzl", "crubit_rust_test")
+load("//rs_bindings_from_cc/test:test_bindings.bzl", "crubit_test_cc_library")
+
+package(default_applicable_licenses = ["//:license"])
+
+crubit_test_cc_library(
+ name = "forward_declaration",
+ hdrs = ["forward_declaration.h"],
+)
+
+crubit_test_cc_library(
+ name = "definition_and_forward_declaration_same_cc_library",
+ hdrs = [
+ "definition.h",
+ "forward_declaration.h",
+ ],
+)
+
+crubit_test_cc_library(
+ name = "definition_and_forward_declaration_separate_cc_library",
+ hdrs = [
+ "definition.h",
+ ],
+ deps = [
+ ":forward_declaration",
+ ],
+)
+
+crubit_rust_test(
+ name = "test",
+ srcs = ["test.rs"],
+ cc_deps = [
+ ":definition_and_forward_declaration_same_cc_library",
+ ":definition_and_forward_declaration_separate_cc_library",
+ ],
+ proc_macro_deps = [
+ "//common:item_exists",
+ ],
+)
diff --git a/rs_bindings_from_cc/test/forward_declaration/definition.h b/rs_bindings_from_cc/test/forward_declaration/definition.h
new file mode 100644
index 0000000..d72936a
--- /dev/null
+++ b/rs_bindings_from_cc/test/forward_declaration/definition.h
@@ -0,0 +1,12 @@
+// Part of the Crubit project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#ifndef THIRD_PARTY_CRUBIT_RS_BINDINGS_FROM_CC_TEST_FORWARD_DECLARATION_DEFINITION_H_
+#define THIRD_PARTY_CRUBIT_RS_BINDINGS_FROM_CC_TEST_FORWARD_DECLARATION_DEFINITION_H_
+
+#include "rs_bindings_from_cc/test/forward_declaration/forward_declaration.h"
+
+class A final {};
+
+#endif // THIRD_PARTY_CRUBIT_RS_BINDINGS_FROM_CC_TEST_FORWARD_DECLARATION_DEFINITION_H_
diff --git a/rs_bindings_from_cc/test/forward_declaration/forward_declaration.h b/rs_bindings_from_cc/test/forward_declaration/forward_declaration.h
new file mode 100644
index 0000000..85a1349
--- /dev/null
+++ b/rs_bindings_from_cc/test/forward_declaration/forward_declaration.h
@@ -0,0 +1,10 @@
+// Part of the Crubit project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#ifndef THIRD_PARTY_CRUBIT_RS_BINDINGS_FROM_CC_TEST_FORWARD_DECLARATION_FORWARD_DECLARATION_H_
+#define THIRD_PARTY_CRUBIT_RS_BINDINGS_FROM_CC_TEST_FORWARD_DECLARATION_FORWARD_DECLARATION_H_
+
+class A;
+
+#endif // THIRD_PARTY_CRUBIT_RS_BINDINGS_FROM_CC_TEST_FORWARD_DECLARATION_FORWARD_DECLARATION_H_
diff --git a/rs_bindings_from_cc/test/forward_declaration/test.rs b/rs_bindings_from_cc/test/forward_declaration/test.rs
new file mode 100644
index 0000000..f0958c3
--- /dev/null
+++ b/rs_bindings_from_cc/test/forward_declaration/test.rs
@@ -0,0 +1,20 @@
+// Part of the Crubit project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+#[cfg(test)]
+mod tests {
+ use item_exists::type_exists;
+
+ #[test]
+ fn test_same_library() {
+ assert!(type_exists!(definition_and_forward_declaration_same_cc_library::A));
+ }
+
+ // TODO(b/309614052): Currently Crubit cannot generate bindings if the forward
+ // declaration and definition are from different targets.
+ #[test]
+ fn test_separate_library() {
+ assert!(!type_exists!(definition_and_forward_declaration_separate_cc_library::A));
+ }
+}