expose `metacall_execution_path` API in Rust Loader
After going through the codebase, metacall_execution_path exists at the C level and is exposed in other language ports, but has never been carried over to the Rust port:
| Layer | Status |
|---|---|
C API (metacall.h) |
✅ Exists |
Loader interface (loader_impl_interface) |
✅ Exists |
Python port (py_port) |
✅ Exposed |
Node.js port (node_port) |
✅ Exposed |
metacall-sys (Rust FFI bindings) |
❌ Missing |
rs_port safe Rust wrapper |
❌ Missing |
This means Rust users currently have no way to configure execution paths for any loader, making it impossible to load scripts that depend on custom or non-standard paths.
Proposed Implementation Plan
Step 1 — metacall-sys: Add the FFI symbol
Bind the raw C function so Rust can call it over FFI:
extern "C" {
pub fn metacall_execution_path(
tag: *const c_char,
path: *const c_char,
) -> c_int;
}
Step 2 — rs_port/src/lib.rs: Add a safe public wrapper
Wrap the unsafe FFI call with proper CString conversion and error handling, matching the ergonomics of the rest of the port's public API:
/// Sets the execution path for a given loader tag.
///
/// This tells a specific loader (identified by `tag`, e.g. `"py"`, `"c"`, `"rb"`)
/// where to look for scripts, packages, or headers at runtime.
/// Must be called after `initialize()` and before loading any files that
/// depend on the path being set.
///
/// # Example
/// ```rust
/// use metacall::{initialize, execution_path};
///
/// let _mc = initialize().unwrap();
/// execution_path("py", "/usr/local/lib/python3.11").unwrap();
/// ```
pub fn execution_path(tag: &str, path: &str) -> Result<(), MetaCallStringConversionError> {
let tag_c = CString::new(tag).map_err(|e| MetaCallStringConversionError::new(tag, e))?;
let path_c = CString::new(path).map_err(|e| MetaCallStringConversionError::new(path, e))?;
unsafe {
bindings::metacall_execution_path(tag_c.as_ptr(), path_c.as_ptr());
}
Ok(())
}
**Why only 2 files?**The Rust port follows a two-layer pattern — metacall-sys owns all raw FFI bindings, and rs_port owns the safe public API on top. Both layers need to be updated together; the change is minimal and self-contained.
Please let me know if this plan looks good or if there are any concerns with the approach @fahdfady . Happy to open a PR once confirmed.
Solved.