Calling & Building / FFI & Export
FFI & Export
extern "C": Calling C Functions
extern "C" fn strlen(s: str) -> i64;
print(strlen("hello")); // 5Declare an external C function and call it directly.
#[export]: Exporting C ABI Symbols
Turn a function into a C ABI symbol visible in a dynamic library, combined with --shared:
#[export]
fn add(a: i64, b: i64) -> i64 {
return a + b;
}Constraints
| No generics | must be monomorphized |
| Cannot be mixed with extern "C" | — |
| Parameter restrictions | i32 / i64 / f64 / bool / str / String / *T |
| Return value | same as above, or no return |
#[py_export]: Exporting Python
On top of #[export] it auto-generates a CPython glue layer; see Exporting Python Modules for details.
Linking External Libraries
[dependencies]
sqlite = { path = "../deps/aero-sqlite" }
[link]
lib_paths = ["../deps/aero-sqlite"]
libs = ["sqlite3"]Use relative paths for FFI dependency paths to keep them portable across machines. aero-sqlite bundles libsqlite3.a, so it works right after install without a C toolchain.