How do i use a C library when building with trunk-rs?

2026-07-12

Stack Overflow: View Question

Tags: tooling-recommendation, c, rust, webassembly, trunk-rs

Score: 1 | Views: 6

The asker wants to consume a C library (a fork of cubiomes, a Minecraft world-generation library that depends on libc) from a Rust web app built with trunk-rs and eframe/egui, targeting wasm32-unknown-unknown. They know a Rust cubiomes crate exists, but want the newer C fork.

Why this is genuinely hard. Trunk is only orchestration — it invokes cargo build --target wasm32-unknown-unknown and bundles the result. The real problem lives one layer down: you need a C toolchain that emits WebAssembly, and wasm32-unknown-unknown deliberately has no libc. Any C code that includes <stdio.h>, <stdlib.h>, malloc, or file I/O will fail to link because the symbols don't exist in that target.

The direction I'd take.

Gotchas:

The challenge: Trunk is a red herring — the real problem is cross-compiling C to a wasm target that has no libc, and threading that through cc/bindgen in build.rs.

All newsletters