Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic C++ to C++ API generation #269

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

nx10
Copy link

@nx10 nx10 commented Mar 16, 2022

This PR adds functionality to generate C/C++ APIs which can be accessed from other packages.

Motivation

  • Fast communication between packages
  • Manually creating the required registration and headers is cumbersome, error-prone and violates DRY principles

Implementation

Functions annotated with [[cpp11::external]] are registered in src/cpp11.cpp and a header inst/include/{package}_api.h is created which can be included in other packages after LinkingTo: and importing the package.

The generated code is inspired by similar APIs in systemfonts and some other packages.

Features:

  • There are two optional parameters for renaming the exported function and adding a doc comment [[cpp11::external("other_name", "Some documentation comment")]]
  • inst/include/{package}_types.h will be included in the header if it exists.

ToDo

  • Unit testing

Discussion

Please let me know if this is in scope for cpp11 (I hope so), or if you have any comments or suggestions.

Also thank you for your work on the cpp11 package!

@jimhester
Copy link
Member

cc @thomasp85 who might have interest in this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants