-
-
Notifications
You must be signed in to change notification settings - Fork 69
Add a new target which generates a C-only API shared library, compatible with MSVC #211
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
base: main
Are you sure you want to change the base?
Conversation
This can be compiled for both Linux and Windows. If the chosen target is a Windows DLL, the library is compatible with MSVC and It is self-contained, i.e. there are no other DLL dependencies (other than the kernel) and exceptions and memory allocations do not cross the DLL boundary. Signed-off-by: Fabio Cannizzo <[email protected]>
Signed-off-by: Fabio Cannizzo <[email protected]>
Signed-off-by: Fabio Cannizzo <[email protected]>
…ments, to prevent registers spill to the stack in Windows ABI mode Signed-off-by: Fabio Cannizzo <[email protected]>
Hi @fabiocannizzo, I had a quick question: is the purpose of this PR to build this library on Windows? If that’s the case, do we also need to expose all the APIs in C? The library is primarily written in C++, and I’m not sure we have the bandwidth right now to fully support a C interface. |
Also:
Unfortunately, this creates a compatibility issue: NumPy, one of the main users of this library, is still on C++17. We can't move to C++-20 just yet. |
The upgrade to C++20 has purely cosmetic reason, to handle the |
The purpose is to build it the library for Windows and use it with MSVC. The C-API is provided as an auto-generated minimally intrusive light-weight wrapper. I would be happy to schedule a f2f session and walk you through, if that is useful. |
See #220. I was able to update meson.build to build the library with MSVC. Its still work in progress and doesnt build tests and benchmarks yet. But I think we can build with MSVC without having to expose C-APIs. |
@fabiocannizzo could you try #220 and see if you can build on windows using MSVC? |
@r-devulap, I will test and revert. What is the meson configuration command line to use? In which shell on windows should it run: the MSVC x86 native cmd prompt? |
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.