Since it is imported and not included like cImport() has to, reordering will work as expected.
Running nim c src/genwrapper.nim on this file doesn't work, and neither does import wrap on another file:
import nimterop/[cimport, build, paths]
cIncludeDir("/usr/include/apr-1")
cPlugin:
import strutils
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
sym.name = sym.name.strip(chars = {'_'})
sym.name = sym.name.replace("__", "_")
if sym.name == "APR_NO_FILE":
sym.name = "APR_NO_FILE_DEF"
cImport(
@[
"/usr/include/apr-1/apr.h"
],
recurse = true, nimfile = "wrap.nim")
Both fail with
Error: undeclared identifier: 'apr_size_t'
since one of the constants uses apr_size_t which comes before the type definition. What's the correct strategy here?
Looks like {.experimental: "codeReordering".} doesn't work on devel for some reason. I tried 1.2.6 and it worked fine. Might want to open a Nim defect on that.
Meanwhile, since this is a simple case, you can also just do:
static:
cSkipSymbol(@["apr_size_t"])
type
apr_size_t* {.importc.} = uint
Before your cImport() call and it should work.
Hold on, it wasn't really broken on devel either, I mistook the missing socklen_t as the issue. import wrap works for me.
What version of Nim are you using and which OS/distro?
Yeah, now I'm getting the socklen_t issue. I'm using nimterop 0.6.11 and Nim 1.2.6 from choosenim on Arch Linux.
Has someone already written a solution for dealing with lower-level wrapping, like under /usr/include/sys? This seems like duplicated effort.