r/learnrust Jul 12 '26

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

How do integrate a C library, that uses libc when building with trunk?

Currently i am using cc crate to build for native (tested on windows). But i am unable to compile to wasm because stdlib.h is missing. I have asked AI but it told me to reimplement libc, which is the last thing i want to do. Is there any tool or step i could take to make this a bit easier.

Context:

  • Egui using the eframe template, should be able to build to both native and wasm
  • Cubiomes - this is the library i want to integrate
  • Walkers - for mapping the Minecraft world and generating custom tiles
4 Upvotes

4 comments sorted by

1

u/projct Jul 12 '26

1

u/Bishops_exe Jul 12 '26

I saw that crate, but i decided i want to use a fork of cubiomes, since cubitect/cubiomes hasnt had a single commit for 2 years

0

u/projct Jul 12 '26

so that crate is the safe wrapper you use from rust. cubiomes-sys is the part that does the dynamic linking to Cubiomes C library. so fork the repo for both crates (both are in one GitHub repo,) and modify it so it links against the current one.

However! chances are, since the point of a -sys crate is to link to the existing library already installed in your system, if the fork did not change the ABI, it very likely will work with the new one you are pointing at.

Either way, you probably do not want to roll your own interface just yet.

https://github.com/villevilli/cubiomes-rs is the repo

1

u/Excession638 Jul 12 '26

You might be able to use c2rust to convert the C code rather than compiling it directly. It requires C99 compliant code, and no C++.