{"record":{"id":"fa7facf63a2c3ace","repo":"oven-sh/bun","slug":"failed-to-build-the-tracer-with-cc-build-stde","errorCode":null,"errorMessage":"failed to build the tracer with ${cc}\n${build.stderr}","messagePattern":"failed to build the tracer with (.+?)\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/orderfile/generate.ts","lineNumber":209,"sourceCode":"\n  // The unstripped binary: its symbol table is what maps addresses back to names.\n  const bunProfile = join(buildDir, options.exeName ?? \"bun-profile\");\n  if (!existsSync(bunProfile)) {\n    throw new Error(`${bunProfile} not found — build it first (bun run build:release)`);\n  }\n\n  const scratch = mkdtempSync(join(tmpdir(), \"bun-orderfile-\"));\n  try {\n    // ── Build the tracer and the pty runner ───────────────────────────────────\n    const tracer = join(scratch, darwin ? \"functrace.dylib\" : \"functrace.so\");\n    const ptyrun = join(scratch, \"ptyrun\");\n    const cc = process.env.CC || \"cc\";\n    const build = runCommand(\n      darwin\n        ? [cc, \"-O2\", \"-dynamiclib\", \"-fPIC\", \"-o\", tracer, join(here, \"functrace.c\")]\n        : [cc, \"-O2\", \"-shared\", \"-fPIC\", \"-o\", tracer, join(here, \"functrace.c\"), \"-ldl\", \"-lpthread\"],\n    );\n    if (build.status !== 0) throw new Error(`failed to build the tracer with ${cc}\\n${build.stderr}`);\n    const pty = runCommand([cc, \"-O2\", \"-o\", ptyrun, join(here, \"ptyrun.c\"), ...(darwin ? [] : [\"-lutil\"])]);\n    if (pty.status !== 0) throw new Error(`failed to build the pty runner with ${cc}\\n${pty.stderr}`);\n\n    // ── Symbol table and function starts ──────────────────────────────────────\n    const symbols = readSymbolTable(bunProfile);\n    const startsPath = join(scratch, \"starts.bin\");\n    writeStarts(\n      startsPath,\n      [...symbols.keys()].sort((a, b) => a - b),\n    );\n\n    // ── Representative workloads ──────────────────────────────────────────────\n    // Order matters: earlier workloads get the densest placement, so the plain\n    // runtime startup path comes first.\n    const fixtures = join(scratch, \"fixtures\");\n    mkdirSync(join(fixtures, \"tests\"), { recursive: true });\n    writeFileSync(\n      join(fixtures, \"hello.ts\"),","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/scripts/orderfile/generate.ts#L191-L227","documentation":"Compiling functrace.c into the injectable tracer (functrace.dylib on macOS, functrace.so on Linux) with $CC failed; the compiler's stderr is appended. The generator shells out to the ambient C toolchain instead of bundling a compiler, so a broken or missing toolchain surfaces here.","triggerScenarios":"No cc on PATH and CC unset (fresh macOS without Xcode CLT, slim Linux without gcc); CC pointing at a wrapper or incompatible compiler; missing C headers/SDK for the -dynamiclib/-shared build.","commonSituations":"Fresh dev machines; minimal CI containers; CC leftovers like a cross-compiler default from another project's env.","solutions":["Read the appended stderr for the actual compile error","Install a toolchain: `xcode-select --install` on macOS, `apt-get install build-essential` (or distro equivalent) on Linux","Set CC to a working compiler (`CC=clang bun scripts/orderfile/generate.ts`)"],"exampleFix":"# before\n$ bun scripts/orderfile/generate.ts\nError: failed to build the tracer with cc\nclang: error: ... \n\n# after\n$ xcode-select --install   # macOS\n$ sudo apt-get install -y build-essential   # Linux\n$ bun scripts/orderfile/generate.ts","handlingStrategy":"try-catch","validationCode":"import { spawnSync } from \"node:child_process\";\n\nconst cc = process.env.CC || \"cc\";\nif (spawnSync(\"which\", [cc]).status !== 0) {\n  throw new Error(`No C compiler (${cc}) — install Xcode CLT or build-essential before generating order files`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  buildTracer();\n} catch (err) {\n  if (/failed to build the tracer/.test(String(err))) {\n    console.error(\"Tracer compile failed — check CC, install a toolchain, read the appended compiler stderr\");\n  }\n  throw err;\n}","preventionTips":["Require a C toolchain in CI images that run orderfile generation","Set CC explicitly to the platform's supported compiler rather than relying on ambient env"],"tags":["compiler","toolchain","orderfile","c"],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}