Add a new target which generates a C-only API shared library, compatible with MSVC #211
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.
This PR allows to use and link the library both in Linux and Windows (also compatible with MSVC).
It exports most of the functions using a
extern-C
api, so there are no issue with inconsistent name mangling used by different compilers. Exceptions and memory allocations do not cross the shared library boundary, avoiding possible inconsistency of binary API.When the target is Windows, the compiler of choice is
clang
withmingw
. Compiling withgcc
is not a viable option because of a long standing bug related to alignment of objects requiring 32-bytes alignment (see mingw-w64/mingw-w64#115). The generated DLL is self-contained, i.e. there are no other DLL dependencies (other than the kernel ones), so there is no need to distributemingw
toolchain DLLs.The C++ standard is upgraded to C+20, which allows to use more portable version for the
unlikely
attribute.There are a few more explicit uses of
force inline
. These are generally redundant, but, in some cases, they may help a bit when compiling for Windows platform, where by default AVX2 registers are not passed via registers.Instructions on how to compile and available targets and cross compilation host platforms are in
README.md
.A test file
smoke.cpp
to use the API is available in themake-c-api
folder.Github workflow files are also provided, to test various way to build the library and run the test.