mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-20 16:29:31 +00:00
46 lines
1.5 KiB
Nim
46 lines
1.5 KiB
Nim
## Compile-time metadata types for FFI binding generation.
|
|
## Populated by the {.ffiCtor.} and {.ffi.} macros and consumed by codegen.
|
|
|
|
type
|
|
FFIParamMeta* = object
|
|
name*: string # Nim param name, e.g. "req"
|
|
typeName*: string # Nim type name, e.g. "EchoRequest"
|
|
isPtr*: bool # true if the type is `ptr T`
|
|
|
|
FFIKind* {.pure.} = enum
|
|
FFI
|
|
CTOR
|
|
DTOR
|
|
|
|
FFIProcMeta* = object
|
|
procName*: string # e.g. "timer_echo"
|
|
libName*: string # library name, e.g. "timer"
|
|
kind*: FFIKind
|
|
libTypeName*: string # e.g. "Timer"
|
|
extraParams*: seq[FFIParamMeta] # all params except the lib param
|
|
returnTypeName*: string # e.g. "EchoResponse", "string", "pointer"
|
|
returnIsPtr*: bool # true if return type is ptr T
|
|
|
|
FFIFieldMeta* = object
|
|
name*: string # e.g. "delayMs"
|
|
typeName*: string # e.g. "int"
|
|
|
|
FFITypeMeta* = object
|
|
name*: string
|
|
fields*: seq[FFIFieldMeta]
|
|
|
|
# Compile-time registries populated by the macros
|
|
var ffiProcRegistry* {.compileTime.}: seq[FFIProcMeta]
|
|
var ffiTypeRegistry* {.compileTime.}: seq[FFITypeMeta]
|
|
var currentLibName* {.compileTime.}: string
|
|
|
|
# Target language for binding generation; override with -d:targetLang=cpp
|
|
const targetLang* {.strdefine.} = "rust"
|
|
|
|
# Output directory for generated bindings; set with -d:ffiOutputDir=path/to/dir
|
|
const ffiOutputDir* {.strdefine.} = ""
|
|
|
|
# Nim source path (relative to outputDir) embedded in generated build files;
|
|
# set with -d:ffiSrcPath=../relative/path.nim
|
|
const ffiSrcPath* {.strdefine.} = ""
|