Repository navigation
Conversation
add_c_abi now also applies to the cppjswasm template, with the layout the cpp template uses: cpp/<name> builds lib<module> with an extern "C" surface, cpp/python holds the pybind11 extension that links it through hatch-cpp depends, and cpp/CMakeLists.txt builds and installs the library without Python. The JavaScript build is unchanged and still compiles the C++ sources with Emscripten. This template binds a class, so the C ABI has an opaque handle for Example with create, free, and accessor functions, and the extension wraps the handle. The C API definitions are excluded from clang-format because their line breaks would depend on the module name's length. extension_cpp.pyi now declares Example, which the extension already exported. A cppjswasm-capi example and gen/test targets exercise the option in CI. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
Windows runners find MinGW gcc before cl, and the program needs the library directory on PATH either way. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
cibuildwheel runs delvewheel on Windows by default, and it cannot find the DLL the wheel already ships. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
build.mjs repeated the extension path, which contains the module name, so oxfmt wrapped two calls once the name passed 25 characters and pnpm lint failed for the cppjswasm-capi example. The path is now a constant. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
add_c_abinow also applies to thecppjswasmtemplate and gives it the layout thecpptemplate got in #220:cpp/<name>/c_api.cppplus the existingexample.cppbuild thegenericlibrary<module>/lib/lib<module>, declared in<module>/include/<module>/<module>.h.cpp/python/extension.cppis the pybind11 extension, linked against the library throughdepends.cpp/CMakeLists.txtbuilds and installs the library without Python.get_*helpers and the Windows DLL directory, cibuildwheel gets the repair exclusions, and Pyodide builds useHATCH_CPP_LIBRARY_SOURCE=direct.Differences from the
cpptemplate:Exampleclass, so the C ABI has an opaque<module>_examplehandle with_new,_free,_stuff, and_set_stuff. Functions that allocate catch exceptions and report failure through the return value. The extension wraps the handle in a small class, so the Python surface is the same with and without the option.c_api.cppare wrapped in// clang-format offandon. Each signature contains the module name twice, so clang-format would break the lines differently per project and a new project could failmake lint. I checked the generated C++ and Python formatting with a 3-character, a 30-character, and a 46-character module name.Two changes also affect the output without
add_c_abi:extension_cpp.pyinow declaresExample. The extension already exported it, andtyrejected the import in the new test.js/build.mjskeeps the extension path in a constant. The path contains the module name and was repeated, so oxfmt wrapped two calls once the name passed 25 characters andpnpm lintfailed for thecppjswasm-capiexample.The Windows consumer test and the
delvewheelexclusion match #223.Checked on macOS with the
cppjswasm-capiexample andSKIP_HATCH_JS=1: C++ and Python lint,make checks, and the five tests pass, and the package builds and imports inexternalmode against the CMake install and indirectmode. I did not run the JavaScript build, Windows, or Pyodide locally.Type of Change
Checklist
make lint)make test)