-
Notifications
You must be signed in to change notification settings - Fork 244
Description
π Feature
Add an optional config map parameter to metacall_load_from_X functions so callers can pass explicit compiler flags, include paths, and library paths directly β replacing the current fragile path-guessing approach.
Is your feature request related to a problem?
metacall_load_from_package and related functions have no way to accept loader-specific configuration. The C loader works around this by guessing paths from execution_paths, which breaks whenever headers and libraries are in different directories. There is also no way to pass compiler flags (-std=c++17, -DFOO, etc.) or extra include/library paths at call time.
This was directly exposed by #631 where load_from_package failed to find libloadtest.so and loadtest.h because they were in different locations than the loader expected.
Describe the solution you'd like
Add an optional void *config parameter (a metacall_value map) to the load functions:
// Current
int metacall_load_from_package(const char *tag, const char *name, void **handle);
// Proposed
int metacall_load_from_package(const char *tag, const char *name, void **handle, void *config);The config map is loader-defined. For the C loader, supported keys would be:
| Key | Maps to |
|---|---|
"include_paths" |
-I /path/to/include |
"library_paths" |
-L /path/to/lib |
"compiler_flags" |
-std=c++17, -DFOO, etc. |
Passing NULL preserves the current behavior for backward compatibility.
Files to change: metacall_loaders.h, metacall_loaders.c, the loader interface in source/loader/, and c_loader_impl.cpp to consume the keys. Other loaders can add their own keys incrementally.
Describe alternatives you've considered
- Keep using
execution_pathsguessing β already proven fragile (metacall-c-lib-test fails: C loader load_from_package cannot reliably find .so and .h via execution_pathsΒ #631). Not scalable. - Environment variables (
LOADER_LIBRARY_PATH, etc.) β global and not per-call. Can't pass per-invocation flags. - Separate config API call before load β adds state and ordering requirements, less clean than a single call.
Additional context
This was discussed with @viferga as the next planned contribution after the immediate fix in #631. The config map approach is already part of the broader design direction for the metacall_load_from_X API.