Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cc_bindings_from_rs/generate_bindings/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ fn specializations<'tcx>(db: &crate::BindingsGenerator<'tcx>) -> Rc<[CppTypeSpec
let tcx = db.tcx();
let mut specializations = Vec::new();

let defs_in_crate = db.public_paths_by_def_id(db.source_crate_num());
for (adt_or_alias_def_id, paths) in defs_in_crate {
let all_public_paths = db.all_public_paths_by_def_id();
for (adt_or_alias_def_id, paths) in all_public_paths {
specializations.extend(
std::iter::once(adt_or_alias_def_id)
.chain(
Expand Down
19 changes: 19 additions & 0 deletions cc_bindings_from_rs/test/bazel/cross_crate/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ load(
"@rules_rust//rust:defs.bzl",
"rust_library",
)
load("//cc_bindings_from_rs/bazel_support:cc_bindings_from_rust_library_config_aspect_hint.bzl", "cc_bindings_from_rust_library_config")
load(
"//cc_bindings_from_rs/bazel_support:cc_bindings_from_rust_rule.bzl",
"cc_bindings_from_rust",
Expand All @@ -13,10 +14,27 @@ load("//common:crubit_wrapper_macros_oss.bzl", "crubit_cc_test")

package(default_applicable_licenses = ["//:license"])

cc_bindings_from_rust_library_config(
name = "other_crate_hint",
extra_cc_hdrs = ["other_crate_types.h"],
)

rust_library(
name = "other_crate",
testonly = 1,
srcs = ["other_crate.rs"],
aspect_hints = [
":other_crate_hint",
],
proc_macro_deps = [
"//support:crubit_annotate",
],
)

cc_bindings_from_rust(
name = "other_crate_cc_api",
testonly = 1,
crate = ":other_crate",
)

rust_library(
Expand All @@ -36,6 +54,7 @@ crubit_cc_test(
name = "cross_crate_test",
srcs = ["cross_crate_test.cc"],
deps = [
":other_crate_cc_api",
":test_api_cc_api",
"//testing/base/public:gunit_main",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "cc_bindings_from_rs/test/bazel/cross_crate/other_crate_types.h"
#include "cc_bindings_from_rs/test/bazel/cross_crate/test_api.h"

namespace crubit {
Expand All @@ -17,6 +18,11 @@ TEST(CrossCrateTests, BasicEndToEndTest) {
EXPECT_EQ(123, i);
}

TEST(CrossCrateTests, SpecializationTest) {
crubit::test::MyStatus s = test_api::return_status_from_other_crate();
EXPECT_TRUE(s.ok);
}

// b/292231336
// TEST(CrossCrateTests, RustToolchainCrate) {
// ::alloc::string::String s =
Expand Down
16 changes: 16 additions & 0 deletions cc_bindings_from_rs/test/bazel/cross_crate/other_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,19 @@
//! `other_crate.rs` are used in public API exposed by `test_api.rs`.

pub struct SomeStruct(pub i32);

#[crubit_annotate::cpp_layout_equivalent(
cpp_type = "crubit::test::MyStatusOr<{T}>",
include_path = "cc_bindings_from_rs/test/bazel/cross_crate/other_crate_types.h"
)]
#[repr(C)]
pub struct MyStatusOr<T> {
pub has_value: bool,
pub value: T,
}

#[crubit_annotate::cpp_specialization(
cpp_type = "crubit::test::MyStatus",
include_path = "cc_bindings_from_rs/test/bazel/cross_crate/other_crate_types.h"
)]
pub type MyStatus = MyStatusOr<()>;
24 changes: 24 additions & 0 deletions cc_bindings_from_rs/test/bazel/cross_crate/other_crate_types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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_CC_BINDINGS_FROM_RS_TEST_BAZEL_CROSS_CRATE_OTHER_CRATE_TYPES_H_
#define THIRD_PARTY_CRUBIT_CC_BINDINGS_FROM_RS_TEST_BAZEL_CROSS_CRATE_OTHER_CRATE_TYPES_H_

namespace crubit {
namespace test {

struct MyStatus {
bool ok;
};

template <typename T>
struct MyStatusOr {
bool has_value;
T value;
};

} // namespace test
} // namespace crubit

#endif // THIRD_PARTY_CRUBIT_CC_BINDINGS_FROM_RS_TEST_BAZEL_CROSS_CRATE_OTHER_CRATE_TYPES_H_
4 changes: 4 additions & 0 deletions cc_bindings_from_rs/test/bazel/cross_crate/test_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ pub fn extract_int(s: other_crate::SomeStruct) -> i32 {
pub fn return_a_type_from_a_rust_toolchain_crate() -> String {
"String".to_owned()
}

pub fn return_status_from_other_crate() -> other_crate::MyStatus {
other_crate::MyStatusOr { has_value: true, value: () }
}
Loading