Skip to content

c-api: Bring wasmtime-cpp into this repository #10582

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 6 commits into from
Apr 16, 2025

Conversation

MangoPeachGrape
Copy link
Contributor

@MangoPeachGrape MangoPeachGrape commented Apr 15, 2025

See discussion in #10566 for more context.

Folloving files have been moved without edits:

  • wasmtime-cpp/include/wasmtime.hh -> /crates/c-api/include/
  • wasmtime-cpp/tests/* -> /crates/c-api/tests/
  • wasmtime-cpp/examples/* -> /examples/

The CMakeLists.txt content is copied to /crates/c-api/CMakeLists.txt with slight adjustments. I haven't fully gone through and checked if everything from the old CMake file still makes sense.

The tests inside /crates/c-api/tests/ seem to run when examples ("Test C-API" from CI) is executed.

Added a CMake option to disable tests, feel free to let me know if this is not desired.

`wasmtime-cpp/include/wasmtime.hh` -> `/crates/c-api/include/`
`wasmtime-cpp/tests/*` -> `/crates/c-api/tests/`
`wasmtime-cpp/examples/*` -> `/examples/`

See discussion in bytecodealliance#10566 for more context.
@MangoPeachGrape MangoPeachGrape requested a review from a team as a code owner April 15, 2025 00:09
@MangoPeachGrape MangoPeachGrape requested review from fitzgen and removed request for a team April 15, 2025 00:09
@github-actions github-actions bot added the wasmtime:c-api Issues pertaining to the C API. label Apr 15, 2025
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks for this! This looks pretty good to me, but I'd also want to test some more integration-y things before landing. To that end can you try a few things:

  • Add a commit to this PR with "prtest:full" somewhere in the commit message so we can see the full CI run
  • With a full run I want to double-check that the header file is present in the installation artifacts
  • Mind updating crates/c-api/README.md with a mention that the C++ API is present as well? I can also do this as a follow-up if you'd prefer.
  • With a full run I want to double-check that the docs here are present in the c-api docs.

@alexcrichton
Copy link
Member

Also, after merging, I'll take on the bits of archiving the old repo.

@MangoPeachGrape MangoPeachGrape requested a review from a team as a code owner April 15, 2025 19:58
@MangoPeachGrape
Copy link
Contributor Author

CI doesn't seem to have C++ compiler? Should a C++ compiler be a requirement, even when we don't build any C++ code?

@alexcrichton
Copy link
Member

Could this be updated to only require a C++ compiler for tests? For a normal build it shouldn't be required I think?

@alexcrichton
Copy link
Member

Ok nice looks like everything's integrated well, I can see the C++ tests running and I see wasmtime.hh in the distribution artifacts as well. Can you double-check the docs though? I don't see the doxygen docs for the C++ API in the gh-pages artifact, just the C API. I suspect we need to tweak doxygen.conf a bit?

This requires disabling warnings on undocumented, as `wasm.hh` has
undocumeted structures

Also fix urls in `wasmtime.hh`
@MangoPeachGrape
Copy link
Contributor Author

Would it be preferred to only silence the undocumented warnings from wasm.hh instead of disabling it all together?

@alexcrichton
Copy link
Member

If possible, yeah, although I'm not sure if it's easy to configure doxygen as such.

@MangoPeachGrape
Copy link
Contributor Author

I was thinking of EXCLUDE = wasm.hh, but now I realize that it obviously removes it from the output as well. What's better, exclude wasm.hh and enable the warning, or keep it like it is now?

@alexcrichton
Copy link
Member

Excluding in this case I think may actually be ok because while it works I think we'll still want to steer users towards wasmtime.hh. It's not like the C API where some utilities come from the wasm.h API and others from wasmtime.h

This required excluding `wasm.hh`, `wasmtime::detail` namespace, and some
macros.

Also documented two overloads to `Func::call()`
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Nice docs are looking great. Thank you again for working on this!

@alexcrichton alexcrichton added this pull request to the merge queue Apr 16, 2025
Merged via the queue into bytecodealliance:main with commit 13ebd6f Apr 16, 2025
160 checks passed
@MangoPeachGrape MangoPeachGrape deleted the c-api/cpp branch April 16, 2025 19:12
alexcrichton added a commit to alexcrichton/wasmtime that referenced this pull request Apr 16, 2025
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 added a commit to alexcrichton/wasmtime that referenced this pull request Apr 21, 2025
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.
github-merge-queue bot pushed a commit that referenced this pull request Apr 21, 2025
* Sketch out merging the C/C++ APIs

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.

* Split out `error.hh` to its own file
BasGeertsema pushed a commit to BasGeertsema/wasmtime-dotnet that referenced this pull request Jul 1, 2025
No breaking changes in C-Api.

All tests pass.

Note that this release adds the C++ header files from wasmtime-cpp and
split large header files into smaller files, so a lot of files have been
added and changes to the c-api directory in wasmtime. However, there
are no breaking changes to the c-api itself.

bytecodealliance/wasmtime#10582
jsturtevant pushed a commit to bytecodealliance/wasmtime-dotnet that referenced this pull request Jul 11, 2025
No breaking changes in C-Api.

All tests pass.

Note that this release adds the C++ header files from wasmtime-cpp and
split large header files into smaller files, so a lot of files have been
added and changes to the c-api directory in wasmtime. However, there
are no breaking changes to the c-api itself.

bytecodealliance/wasmtime#10582
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.

2 participants