FFI call c code #215
-
|
is it possible to call c code ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Yes — Perry has a first-class FFI mechanism for calling native code (Rust, Swift on Apple, JNI on Android, and via Rust → C anything that compiles to a static library). It's called native extensions and the full docs live at For pure C, the cleanest path is to wrap your C in a tiny Rust 1. Project layout2. The C code —
|
Beta Was this translation helpful? Give feedback.
-
|
Hey, thanks for your answer |
Beta Was this translation helpful? Give feedback.
Yes — Perry has a first-class FFI mechanism for calling native code (Rust, Swift on Apple, JNI on Android, and via Rust → C anything that compiles to a static library). It's called native extensions and the full docs live at
https://docs.perryts.com/plugins/native-extensions.html.For pure C, the cleanest path is to wrap your C in a tiny Rust
staticlib(Cargo'scccrate compiles the.cfile for you inbuild.rs), declare the C functions on the TypeScript side withdeclare function, and let Perry's--bundle-extensionsflag link everything in. Here's a minimal, complete example.1. Project layout