---
title: "Compile and run C in JavaScript"
description: "Bun v1.1.28 adds experimental `cc` in `bun:ffi`, which uses TinyCC to compile, link and relocate C in memory and generates inline wrappers that convert between JavaScriptCore values and C primitives with no dynamic dispatch."
url: "https://swe.quest/articles/compile-and-run-c-in-javascript-951e10ff9004c507"
canonical: "https://bun.com/blog/compile-and-run-c-in-js"
source: "Bun"
published: "2024-09-18"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 8
tags: ["javascript","c-cpp","runtimes","performance"]
---

# Compile and run C in JavaScript

A post on [Bun](https://swe.quest/sources/bun.md), published 2024-09-18, 8 min read, Announcement. Original: [https://bun.com/blog/compile-and-run-c-in-js](https://bun.com/blog/compile-and-run-c-in-js)

## Summary

Bun v1.1.28 adds experimental \`cc\` in \`bun:ffi\`, which uses TinyCC to compile, link and relocate C in memory and generates inline wrappers that convert between JavaScriptCore values and C primitives with no dynamic dispatch. It is pitched as an alternative to N-API addons, which need node-gyp builds or prebuilt platform matrices and cost 7–15ns per call versus 2ns for the JavaScriptCore C++ API, and to WebAssembly, which cannot make system calls and must copy data across its isolated memory. Benchmarks show about 5ms to compile a small file and roughly 2ns of per-call overhead over native C. It suits glue code for C and system libraries such as ffmpeg or the macOS Keychain, not large projects needing Clang/GCC-level optimization.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [C & C++](https://swe.quest/tags/c-cpp.md) (Languages)
- [Runtimes & VMs](https://swe.quest/tags/runtimes.md) (Compilers & runtimes)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)

## Prerequisites

- C basics
- JavaScript FFI concepts ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- native addons in Node.js ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))

## Keywords

Bun, bun:ffi, TinyCC, N-API, JavaScriptCore, WebAssembly, node-gyp

## Related posts

- [Bun v1.1.29](https://swe.quest/articles/bun-v1-1-29-a5b176ea3eb640ea.md): Bun · 2024-09-20 · Medium · 3 min read · Runtimes & VMs, JavaScript, C & C++, Performance engineering
  Bun v1.1.29 adds N-API support to its \`cc\` C compilation feature, letting C code return JavaScript strings, objects and arrays, which also works for shared libraries loaded via \`dlopen\` in \`bun:ffi\`.
- [Bun v0.1.9](https://swe.quest/articles/bun-v0-1-9-4ecfe167e5b29929.md): Bun · 2022-08-18 · Medium · 3 min read · Runtimes & VMs, JavaScript, Zig, Performance engineering, Compilers
  Bun v0.1.9 starts using JavaScriptCore's DOMJIT API to JIT-optimize native functions, making \`ptr()\` in \`bun:ffi\` 6-10x faster and \`TextEncoder.encodeInto\` 1.5-5x faster.
- [Bun v1.3.7](https://swe.quest/articles/bun-v1-3-7-c2527b00781a4168.md): Bun · 2026-01-27 · Medium · 20 min read · JavaScript, Runtimes & VMs, Performance engineering, Developer tools
  Bun v1.3.7 upgrades JavaScriptCore, which brings faster async/await (35%), Array.from, padStart/padEnd, array.flat and better ARM64 codegen using ccmp/ccmn chains.
- [Bun v1.1.19](https://swe.quest/articles/bun-v1-1-19-00c26890132a72c3.md): Bun · 2024-07-12 · Medium · 8 min read · JavaScript, Runtimes & VMs, Performance engineering
  Bun v1.1.19 enables JavaScriptCore's FTL JIT on Windows for the first time in nine years, making Object.entries about 20% faster and cutting Array.map overhead roughly in half.
- [Bun v0.3.0](https://swe.quest/articles/bun-v0-3-0-ce34b4df06ef614a.md): Bun · 2022-12-07 · Medium · 8 min read · JavaScript, Runtimes & VMs, Performance engineering
  Bun v0.3.0 focuses on stability and Node.js/Web API compatibility, cutting memory use 3-5x under load by scheduling garbage collection in coordination with the event loop and speeding up TextEncoder.encodeInto() 3x via simdutf.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
