Closed
Description
The current mono public embedding API headers are awkward to work with both for runtime developers and for embedding hosts that wish to dynamically load the runtime:
- The API headers are in the same directory as the Mono implementation and the internal Mono headers, making it difficult to understand which headers constitute the public API surface without reading the cmake files. Additionally, other runtimes implementing the mono embedding API cannot easily share the headers.
- The API headers declare mono API functions with
MONO_API return_type function_name (args...)
, which is reasonable for embedding hosts that link to the runtime at compile time, but are not suitable for hosts that use late binding (dlopen
+dlsym
) to access the mono symbols. We should reorganize the headers to support late binding. (One idea: define API functions asMONO_API(return_type, function_name, (args...))
and allow users of the headers to re-define theMONO_API
macro and include the header multiple times. That would allow C compile-time "code generation" of typedefs anddlsym
boilerplate. - One client of the new headers would be a testsuite of the embedding API. Previously in github.com/mono/mono, the tests (src/mono/mono/tests/libtest.c) had to duplicate the API function signatures just to declare the function pointers storing the dynamically loaded symbols.
Tasks:
- move public API headers to
src/native/include/mono-2.0
(ie:src/native/include/mono-2.0/mono/metadata/object.h
src/native/include/mono-2.0//mono/mini/jit.h
etc) [build] Move Mono API headers under src/native/public #64569 - Define
MONO_API_FUNCTION(return_type,name,args_sig)
and factor the public headers into "implementation details" headers; move type definitions to separate details headers from function definitions; allow the function definitions headers to be included multiple times and to re-defineMONO_API_FUNCTION (r,n,a)
[MonoAPI] Split type and function headers, add MONO_API_FUNCTION macro #65446 - Move the
libtest.c
and existing embedding API testing code fromsrc/mono/mono/tests
tosrc/tests/Interop/MonoAPI
and run the tests on desktop mono configurations. Includes switching the tests to use the newMONO_API_FUNCTION
late binding approach. [tests] Add MonoApi runtime tests #65221