I would like to be able to build a shared library/DLL that only exports the C-API and hides everything else (either as part of LLVM/MLIR itself or as part of a larger project). I believe the relatively normal way to do this for this kind of project is something like:
- On Windows:
- Apply
declspec(dllexport)
to functions if building a library - Apply
declspec(dllimport)
to functions if depending on a library
- Apply
- On Others:
- Apply
__attribute__((__visibility__("default")))
to functions - Build the project with
-fvisibility=hidden
- Apply
There are many things and permutations that can be done if such annotations are applied correctly, and as a first step, we should decide on the macro and use it appropriately.
Libcxx has more complicated needs, but the basic structure and knobs from libcxx/include/__config
provides the right recipe. I propose adding a _MLIR_CAPI_EXPORTED
macro to a new mlir-c/Config.h
and defining it roughly like the libcxx
macro is defined (above). We can elaborate on the knobs and additional build setup to fully leverage it later.