I'm avoiding doing useful things at the moment. So I tweaked the source filters in the compiler to include raw C files.
Here's an example:
import hashes
include "testing.c"
proc add(a, b: cint): cint {.importc.}
echo add(1, 2)
Actually you can do this in pure Nim, something like:
import hashes
const cfile = "testing.c"
const chash* = staticRead(cfile).hash()
{.emit: "#include <testing.c>".}
proc cversion*(): Hash {.exportc: "cversion_" & $cfile.hash() & "_" & $chash.} =
## hack to force Nim to keep this
chash
proc add*(a, b: cint): cint {.importc.}
proc add(a, b: cint): cint {.importc.}
echo add(1, 2)
For completeness, the C file is:
int add(int a, int b) {
return a + b + 2000;
}