Experimental: Compile ISO C11 source code using TinyCC, and make symbols available as functions to JavaScript.
Symbol
cc
function cc<Fns extends Record<string, FFIFunction>>(options: { define: Record<string, string>; flags: string | string[]; include: string | string[]; library: string | string[]; source: string | URL | BunFile; symbols: Fns }): Library<Fns>
@returns
Library<Fns>
Hello, World!
JavaScript:
import { cc } from "bun:ffi";
import source from "./hello.c" with {type: "file"};
const {symbols: {hello}} = cc({
source,
symbols: {
hello: {
returns: "cstring",
args: [],
},
},
});
// "Hello, World!"
console.log(hello());
./hello.c
:
#include <stdio.h>
const char* hello() {
return "Hello, World!";
}