mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-07-25 17:23:09 +00:00
A nim-ffi library is loaded into a foreign host (Go/Rust/...) that must own OS signal handling; if the Nim runtime installs its own handlers it clobbers the host's (e.g. Go's SIGSEGV -> sigpanic recovery, stack growth, goroutine preemption), turning recoverable faults into hard process crashes. The flag can only be set on the consumer's final build command, so a dependency cannot inject it -- but it CAN refuse to compile without it. Add a compile-time guard so any consumer that omits -d:noSignalHandler fails the build with an actionable message instead of crashing at runtime (the cause of a real status-go regression). Standalone Nim binaries (nim-ffi's own tests) build with -d:ffiAllowSignalHandler. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
72 lines
3.1 KiB
Nim
72 lines
3.1 KiB
Nim
# ffi.nimble
|
|
|
|
version = "0.1.6"
|
|
author = "Institute of Free Technology"
|
|
description = "FFI framework with custom header generation"
|
|
license = "MIT or Apache License 2.0"
|
|
|
|
packageName = "ffi"
|
|
|
|
requires "nim >= 2.2.4"
|
|
requires "chronos"
|
|
requires "chronicles"
|
|
requires "taskpools"
|
|
|
|
const nimFlagsOrc = "--mm:orc -d:chronicles_log_level=WARN -d:ffiAllowSignalHandler"
|
|
const nimFlagsRefc = "--mm:refc -d:chronicles_log_level=WARN -d:ffiAllowSignalHandler"
|
|
|
|
task buildffi, "Compile the library":
|
|
exec "nim c " & nimFlagsOrc & " --app:lib --noMain ffi.nim"
|
|
|
|
task test, "Run all tests under --mm:orc and --mm:refc":
|
|
for flags in [nimFlagsOrc, nimFlagsRefc]:
|
|
exec "nim c -r " & flags & " tests/test_alloc.nim"
|
|
exec "nim c -r " & flags & " tests/test_ffi_context.nim"
|
|
exec "nim c -r " & flags & " tests/test_gc_compat.nim"
|
|
exec "nim c -r " & flags & " tests/test_serial.nim"
|
|
exec "nim c -r " & flags & " tests/test_ctx_validation.nim"
|
|
|
|
task test_alloc, "Run alloc unit tests under --mm:orc and --mm:refc":
|
|
exec "nim c -r " & nimFlagsOrc & " tests/test_alloc.nim"
|
|
exec "nim c -r " & nimFlagsRefc & " tests/test_alloc.nim"
|
|
|
|
task test_ffi, "Run FFI context integration tests under --mm:orc and --mm:refc":
|
|
exec "nim c -r " & nimFlagsOrc & " tests/test_ffi_context.nim"
|
|
exec "nim c -r " & nimFlagsRefc & " tests/test_ffi_context.nim"
|
|
|
|
task test_serial, "Run serial unit tests":
|
|
exec "nim c -r " & nimFlagsOrc & " tests/test_serial.nim"
|
|
exec "nim c -r " & nimFlagsRefc & " tests/test_serial.nim"
|
|
|
|
task genbindings_example, "Generate Rust bindings for the nim_timer example":
|
|
exec "nim c " & nimFlagsOrc & " --app:lib --noMain --nimMainPrefix:libnimtimer -d:ffiGenBindings -o:/dev/null examples/nim_timer/nim_timer.nim"
|
|
exec "nim c " & nimFlagsRefc & " --app:lib --noMain --nimMainPrefix:libnimtimer -d:ffiGenBindings -o:/dev/null examples/nim_timer/nim_timer.nim"
|
|
|
|
task genbindings_rust, "Generate Rust bindings for the nim_timer example":
|
|
exec "nim c " & nimFlagsOrc &
|
|
" --app:lib --noMain --nimMainPrefix:libnimtimer" &
|
|
" -d:ffiGenBindings -d:targetLang=rust" &
|
|
" -d:ffiOutputDir=examples/nim_timer/rust_bindings" &
|
|
" -d:ffiNimSrcRelPath=../nim_timer.nim" &
|
|
" -o:/dev/null examples/nim_timer/nim_timer.nim"
|
|
exec "nim c " & nimFlagsRefc &
|
|
" --app:lib --noMain --nimMainPrefix:libnimtimer" &
|
|
" -d:ffiGenBindings -d:targetLang=rust" &
|
|
" -d:ffiOutputDir=examples/nim_timer/rust_bindings" &
|
|
" -d:ffiNimSrcRelPath=../nim_timer.nim" &
|
|
" -o:/dev/null examples/nim_timer/nim_timer.nim"
|
|
|
|
task genbindings_cpp, "Generate C++ bindings for the nim_timer example":
|
|
exec "nim c " & nimFlagsOrc &
|
|
" --app:lib --noMain --nimMainPrefix:libnimtimer" &
|
|
" -d:ffiGenBindings -d:targetLang=cpp" &
|
|
" -d:ffiOutputDir=examples/nim_timer/cpp_bindings" &
|
|
" -d:ffiNimSrcRelPath=../nim_timer.nim" &
|
|
" -o:/dev/null examples/nim_timer/nim_timer.nim"
|
|
exec "nim c " & nimFlagsRefc &
|
|
" --app:lib --noMain --nimMainPrefix:libnimtimer" &
|
|
" -d:ffiGenBindings -d:targetLang=cpp" &
|
|
" -d:ffiOutputDir=examples/nim_timer/cpp_bindings" &
|
|
" -d:ffiNimSrcRelPath=../nim_timer.nim" &
|
|
" -o:/dev/null examples/nim_timer/nim_timer.nim"
|