Create the skeleton of a round-trip test for C++ types. This also functions as a test case for b/271498109. PiperOrigin-RevId: 542483945
diff --git a/common/test/bidirectional_deps/BUILD b/common/test/bidirectional_deps/BUILD index 7dc2a10..507aaaf 100644 --- a/common/test/bidirectional_deps/BUILD +++ b/common/test/bidirectional_deps/BUILD
@@ -33,3 +33,29 @@ ":leaf_rs_lib", ], ) + +crubit_test_cc_library( + name = "leaf_cc_lib", + hdrs = ["leaf_cc_lib.h"], +) + +rust_library( + name = "middle_rs_lib", + srcs = ["middle_rs_lib.rs"], + cc_deps = [":leaf_cc_lib"], +) + +cc_bindings_from_rust( + name = "middle_rs_lib_cc_api", + crate = ":middle_rs_lib", +) + +cc_test( + name = "cc_test", + srcs = ["cc_test.cc"], + deps = [ + ":leaf_cc_lib", + "@com_google_googletest//:gtest_main", + "//common:rust_allocator_shims", + ], +)
diff --git a/common/test/bidirectional_deps/cc_test.cc b/common/test/bidirectional_deps/cc_test.cc new file mode 100644 index 0000000..ce47c69 --- /dev/null +++ b/common/test/bidirectional_deps/cc_test.cc
@@ -0,0 +1,11 @@ +// 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 + +#include "common/test/bidirectional_deps/leaf_cc_lib.h" + +namespace { + +// TODO(b/274834739): Test that CcType(RsType(X)) == X + +} // namespace
diff --git a/common/test/bidirectional_deps/leaf_cc_lib.h b/common/test/bidirectional_deps/leaf_cc_lib.h new file mode 100644 index 0000000..4dbd6ef --- /dev/null +++ b/common/test/bidirectional_deps/leaf_cc_lib.h
@@ -0,0 +1,16 @@ +// 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_COMMON_TEST_BIDIRECTIONAL_DEPS_LEAF_CC_LIB_H_ +#define THIRD_PARTY_CRUBIT_COMMON_TEST_BIDIRECTIONAL_DEPS_LEAF_CC_LIB_H_ + +struct LeafCcType { + unsigned char field; +}; + +LeafCcType Wrap(unsigned char x) { return LeafCcType{x}; } + +unsigned char Unwrap(LeafCcType x) { return x.field; } + +#endif // THIRD_PARTY_CRUBIT_COMMON_TEST_BIDIRECTIONAL_DEPS_LEAF_CC_LIB_H_
diff --git a/common/test/bidirectional_deps/middle_rs_lib.rs b/common/test/bidirectional_deps/middle_rs_lib.rs new file mode 100644 index 0000000..4e7be42 --- /dev/null +++ b/common/test/bidirectional_deps/middle_rs_lib.rs
@@ -0,0 +1,5 @@ +// 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 + +// TODO(b/274834739): Provide helpers to test that CcType(RsType(X)) == X.