C Runtime
Technical deep-dive on how the .polybench C runtime project works
This page documents how the .polybench/runtime-env/c/ project is set up, how codegen works, and how execution is performed.
The C runtime uses clang (not gcc). With zero C dependencies, it compiles directly with clang. When C dependencies are present — for example, OpenSSL via vcpkg — it uses CMake and a vcpkg manifest. The runtime crate is runtimes-c; templates come from poly-bench-project. C cannot be auto-installed during init; clang must be installed manually.
When you run poly-bench init --languages c, poly-bench:
.polybench/runtime-env/c/main.c with a minimal int main(void) { return 0; } stubNo dependencies, no vcpkg, no CMake at init. The minimal main.c exists so the directory has a valid C file. When you run benchmarks, codegen writes bench_standalone.c and the executor compiles that directly with clang. main.c is never compiled by poly-bench — it is a placeholder for the scaffold. With deps, vcpkg.json and CMakeLists.txt are created by poly-bench add --c and poly-bench build.
When you run poly-bench build or poly-bench install with C dependencies in polybench.toml:
vcpkg.json if C deps exist (e.g. openssl@3.2)CMakeLists.txt with find_package for each dep and vcpkg toolchainVCPKG_ROOT or CMAKE_TOOLCHAIN_FILE)With zero C deps, build does not create vcpkg or CMake. The executor compiles bench_standalone.c directly with clang -o polybench_runner.
clang, not gcc, for consistent flags across platforms.clang, not gcc. Clang is widely available (macOS Xcode, Linux packages) and has consistent flags across platforms.clang invocation. With deps → CMake + vcpkg. This avoids pulling in CMake/vcpkg for simple benchmarks that need no external libraries.clang, cmake, vcpkg) cannot be installed by poly-bench. The user must install them manually. See Requirements — C for details.When you run poly-bench init --languages c or poly-bench build, the following is created in .polybench/runtime-env/c/:
| File | Source | Purpose |
|---|---|---|
main.c | Placeholder | Minimal stub; used when no deps |
vcpkg.json | When deps added | vcpkg manifest for dependencies |
CMakeLists.txt | When deps added | CMake build with vcpkg toolchain |
No deps: Only main.c exists. poly-bench compiles with clang directly.
With deps: vcpkg.json and CMakeLists.txt are created. Requires VCPKG_ROOT or CMAKE_TOOLCHAIN_FILE. Default paths: ~/vcpkg, /opt/homebrew/share/vcpkg, etc.
When poly-bench run executes a benchmark, the C runtime:
bench_standalone.c (run) or bench_check_<name>.c (check)Generated filenames:
bench_standalone.cbench_check_<suite>_<bench>.cBuild output: polybench_runner binary (or polybench_check for check).
| Scenario | Build Command | Output |
|---|---|---|
| No deps | clang -o polybench_runner bench_standalone.c | polybench_runner |
| With deps | CMake configure + build with vcpkg toolchain | build/polybench_runner or similar |
The executor loads C config from polybench.toml ([c] section, standard, dependencies). If runtime-env is used, it can also parse vcpkg.json for dependency names.
bench_standalone.c, compile with clang or CMake, cache binary path./polybench_runner <benchmark_name> <iterations> as a subprocessclang, not gcc.openssl@3.2), poly-bench uses vcpkg + CMake. Requires VCPKG_ROOT or CMAKE_TOOLCHAIN_FILE.cmake must be on PATH when using deps.openssl maps to find_package(OpenSSL REQUIRED COMPONENTS SSL Crypto). vcpkg installs it; no system OpenSSL needed when using vcpkg.See Requirements — C for user-facing setup and gotchas.