commit | d5529bdd93c7705305c02ab59089dabf4801e530 | [log] [tgz] |
---|---|---|
author | Devin Jeanpierre <jeanpierreda@google.com> | Thu Aug 22 00:37:41 2024 -0700 |
committer | Copybara-Service <copybara-worker@google.com> | Thu Aug 22 00:38:36 2024 -0700 |
tree | be65c0eee9343b79c090531b5f75cb7fbcd7b423 | |
parent | 9a497cce4fecf99e3503d062491bb4ae778b2874 [diff] |
Fix assert failure: only require that the desugared type is a function. This fixes the following assert failure: ``` F0821 15:29:35.857368 4034 logging.cc:62] assert.h assertion failed at third_party/crubit/lifetime_annotations/type_lifetimes.cc:560 in const FunctionLifetimes &clang::tidy::lifetimes::ValueLifetimes::GetFuncLifetimes() const: clang::isa<clang::FunctionProtoType>(type_) *** Check failure stack trace: *** @ 0x55aaebec8bf4 absl::log_internal::LogMessage::SendToLog() @ 0x55aaebec8950 absl::log_internal::LogMessage::Flush() @ 0x55aaebec90b9 absl::log_internal::LogMessageFatal::~LogMessageFatal() @ 0x55aaebe9a394 __assert_fail @ 0x55aae9e930b8 clang::tidy::lifetimes::ValueLifetimes::GetFuncLifetimes() @ 0x55aae9e555ba crubit::Importer::ConvertUnattributedType() @ 0x55aae9e541a6 crubit::Importer::ConvertType() @ 0x55aae9e57440 crubit::Importer::ConvertQualType() @ 0x55aae9e7ffc0 crubit::FunctionDeclImporter::Import() @ 0x55aae9e824b1 crubit::DeclImporterBase<>::ImportDecl() @ 0x55aae9e4ff87 crubit::Importer::GetDeclItem() @ 0x55aae9e4f6ad crubit::Importer::GetItemIdsInSourceOrder() @ 0x55aae9e76ac0 crubit::CXXRecordDeclImporter::Import() @ 0x55aae9e792a1 crubit::DeclImporterBase<>::ImportDecl() @ 0x55aae9e4ff87 crubit::Importer::GetDeclItem() @ 0x55aae9e5166c crubit::Importer::ImportDeclsFromDeclContext() @ 0x55aae9e50f27 crubit::Importer::Import() @ 0x55aae9e4c7c4 crubit::AstConsumer::HandleTranslationUnit() @ 0x55aaea15f396 clang::ParseAST() @ 0x55aae9f402c4 clang::FrontendAction::Execute() @ 0x55aae9eaff2f clang::CompilerInstance::ExecuteAction() @ 0x55aae9e9cb7b clang::tooling::FrontendActionFactory::runInvocation() @ 0x55aae9e9ca4c clang::tooling::ToolInvocation::runInvocation() @ 0x55aae9e9c024 clang::tooling::ToolInvocation::run() @ 0x55aae9e9b808 clang::tooling::runToolOnCodeWithArgs() @ 0x55aae9e9b4df clang::tooling::runToolOnCodeWithArgs() @ 0x55aae9e48dc5 crubit::IrFromCc() @ 0x55aae9e18802 crubit::GenerateBindingsAndMetadata() @ 0x55aae9e14096 crubit::Main() @ 0x55aae9e14be5 main @ 0x7fb4c65f93d4 __libc_start_main @ 0x55aae9e135ea _start *** SIGABRT received by PID 4034 (TID 4034) on cpu 204 from PID 4034; *** ``` When we're getting the lifetime, the access here is guarded by: ```c++ if (const auto* func_type = pointee_type->getAs<clang::FunctionProtoType>()) { ``` Which is not the same as `isa<clang::FunctionProtoType>()`! I'm really not following the logic, but certainly it seems like both of these asserts should line up, and removing sugar seems as decent a thing to do as anything. Nothing else fails if we do. PiperOrigin-RevId: 666223224 Change-Id: I43c1298bbf316180b67c1751f81282b453ea98bb
NOTE: Crubit currently expects deep integration with the build system, and is difficult to deploy to environments dissimilar to Google's monorepo. We do not have our tooling set up to accept external contributions at this time.
Crubit is a bidirectional bindings generator for C++ and Rust, with the goal of integrating the C++ and Rust ecosystems.
Support for calling FFI-friendly C++ from Rust is in progress.
Support for calling Rust from C++ will arrive in 2024H2.
Consider the following C++ function:
extern "C" bool IsGreater(int lhs, int rhs);
This function, if present in a header file which is processed by Crubit, becomes callable from Rust as if it were defined as:
pub fn IsGreater(lhs: ffi::c_int, rhs: ffi::c_int) -> bool {...}
Note: There are some temporary restrictions on the API shape. For example, functions that are not extern "C"
, or that accept a type like std::string
, can't be called from Rust directly via Crubit. These restrictions will be relaxed over time.
Here are some resources for getting started with Crubit:
Rust Bindings for C++ Libraries is a detailed walkthrough on how to use C++ from Rust using Crubit.
The examples/cpp/
directory has copy-pastable examples of calling C++ from Rust, together with snapshots of what the generated Rust interface looks like.
$ apt install clang lld bazel $ git clone git@github.com:google/crubit.git $ cd crubit $ bazel build --linkopt=-fuse-ld=/usr/bin/ld.lld //rs_bindings_from_cc:rs_bindings_from_cc_impl
$ git clone https://github.com/llvm/llvm-project $ cd llvm-project $ CC=clang CXX=clang++ cmake -S llvm -B build -DLLVM_ENABLE_PROJECTS='clang' -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install $ cmake --build build -j $ # wait... $ cmake --install build $ cd ../crubit $ LLVM_INSTALL_PATH=../llvm-project/install bazel build //rs_bindings_from_cc:rs_bindings_from_cc_impl