Skip to content

Sketch out merging the C/C++ APIs #10600

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

Merged
merged 2 commits into from
Apr 21, 2025

Conversation

alexcrichton
Copy link
Member

With the merging of the C++ API into this repository in #10582 it opens up some interesting questions about how to organize the C++ API. Externally it was all entirely a single file, but naturally this isn't great for evolution as it's just one giant tangled header. Instead this commit sketches out a possible different path forward which is to provide the C++ API as a sibling to the C API in preexisting header files. For example this moves the Error class to the error.h header file as an example.

My rough hope would be that in the long-term we could deprecate/remove the wasmtime.hh header file and instead "just" have all the C++ APIs in the normal header files (e.g. wasmtime.h). Additionally the split of the C API in separate header files would be amenable to a similar split of the C++ API too where the API you see is basically conditional on the language mode of whatever's including the headers.

I'll note though I've not seen prior art in doing this. I'm not aware of any other project which exports both a C and C++ API in its header files. That being said I'm not sure how many other projects would fall in such a bucket.

@alexcrichton alexcrichton requested a review from a team as a code owner April 16, 2025 20:17
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team April 16, 2025 20:17
@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Apr 16, 2025
Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a fan of splitting up the monolith C++ header and also the tests, but I am less sold on sharing headers for C and C++. What do you think of having

  • foo.h -- the C API for foo things
  • foo.hh -- includes the C API, adds the C++ layer on top

?

But that said, this is just a soft preference, and I also don't have a ton of experience designing C/C++ libraries, so if there is a better way I am also all ears.

@ac000
Copy link

ac000 commented Apr 18, 2025

I'm a fan of splitting up the monolith C++ header and also the tests, but I am less sold on sharing headers for C and C++. What do you think of having

* `foo.h` -- the C API for `foo` things

* `foo.hh` -- includes the C API, adds the C++ layer on top

FWIW that's probably the way I'd go...

With the merging of the C++ API into this repository in bytecodealliance#10582 it opens
up some interesting questions about how to organize the C++ API.
Externally it was all entirely a single file, but naturally this isn't
great for evolution as it's just one giant tangled header. Instead this
commit sketches out a possible different path forward which is to
provide the C++ API as a sibling to the C API in preexisting header
files. For example this moves the `Error` class to the `error.h` header
file as an example.

My rough hope would be that in the long-term we could deprecate/remove
the `wasmtime.hh` header file and instead "just" have all the C++ APIs
in the normal header files (e.g. `wasmtime.h`). Additionally the split
of the C API in separate header files would be amenable to a similar
split of the C++ API too where the API you see is basically conditional
on the language mode of whatever's including the headers.

I'll note though I've not seen prior art in doing this. I'm not aware of
any other project which exports both a C and C++ API in its header
files. That being said I'm not sure how many other projects would fall
in such a bucket.
@alexcrichton
Copy link
Member Author

Sounds reasonable to me, updated!

Copy link
Member

@fitzgen fitzgen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THanks!

@fitzgen fitzgen added this pull request to the merge queue Apr 21, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 21, 2025
@alexcrichton alexcrichton added this pull request to the merge queue Apr 21, 2025
Merged via the queue into bytecodealliance:main with commit 0467d6f Apr 21, 2025
43 checks passed
@alexcrichton alexcrichton deleted the split-cpp-headers branch April 21, 2025 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:c-api Issues pertaining to the C API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants