2025-08-09 22:56:44 +02:00
|
|
|
# ffi.nimble
|
|
|
|
|
|
2026-01-23 17:55:43 +01:00
|
|
|
version = "0.1.3"
|
2025-08-09 22:56:44 +02:00
|
|
|
author = "Institute of Free Technology"
|
|
|
|
|
description = "FFI framework with custom header generation"
|
|
|
|
|
license = "MIT or Apache License 2.0"
|
|
|
|
|
|
2026-05-03 15:48:47 +02:00
|
|
|
packageName = "ffi"
|
2025-08-09 22:56:44 +02:00
|
|
|
|
|
|
|
|
requires "nim >= 2.2.4"
|
2026-01-07 00:01:17 +05:30
|
|
|
requires "chronos"
|
2026-01-23 15:01:08 +01:00
|
|
|
requires "chronicles"
|
|
|
|
|
requires "taskpools"
|
2025-08-09 22:56:44 +02:00
|
|
|
|
2026-05-09 10:47:37 -03:00
|
|
|
const nimFlagsOrc = "--mm:orc -d:chronicles_log_level=WARN"
|
|
|
|
|
const nimFlagsRefc = "--mm:refc -d:chronicles_log_level=WARN"
|
2026-04-27 21:22:45 +02:00
|
|
|
|
2026-04-29 23:48:36 +02:00
|
|
|
task buildffi, "Compile the library":
|
2026-05-09 10:47:37 -03:00
|
|
|
exec "nim c " & nimFlagsOrc & " --app:lib --noMain ffi.nim"
|
2026-04-27 21:22:45 +02:00
|
|
|
|
2026-05-09 10:47:37 -03:00
|
|
|
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"
|
2026-05-03 10:01:38 +02:00
|
|
|
exec "nim c -r " & flags & " tests/test_serial.nim"
|
2026-04-27 21:22:45 +02:00
|
|
|
|
2026-05-09 10:47:37 -03:00
|
|
|
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"
|
2026-05-03 10:01:38 +02:00
|
|
|
|
|
|
|
|
task test_serial, "Run serial unit tests":
|
2026-05-10 11:44:27 +02:00
|
|
|
exec "nim c -r " & nimFlagsOrc & " tests/test_serial.nim"
|
|
|
|
|
exec "nim c -r " & nimFlagsRefc & " tests/test_serial.nim"
|
2026-05-03 10:01:38 +02:00
|
|
|
|
|
|
|
|
task genbindings_example, "Generate Rust bindings for the nim_timer example":
|
2026-05-10 11:44:27 +02:00
|
|
|
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"
|
2026-05-03 10:01:38 +02:00
|
|
|
|
2026-05-11 22:11:25 +02:00
|
|
|
# Flags baked into the generated build.rs / CMakeLists.txt so downstream
|
|
|
|
|
# consumers compile the Nim library with the same conventions this example
|
|
|
|
|
# uses. Anything that should NOT be hardcoded into the published bindings
|
|
|
|
|
# goes here, not in the generator.
|
|
|
|
|
const genBakedFlags = "--mm:orc -d:chronicles_log_level=WARN"
|
|
|
|
|
|
2026-05-03 11:11:06 +02:00
|
|
|
task genbindings_rust, "Generate Rust bindings for the nim_timer example":
|
2026-05-10 11:44:27 +02:00
|
|
|
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" &
|
2026-05-11 22:11:25 +02:00
|
|
|
" -d:ffiNimBuildFlags=\"" & genBakedFlags & "\"" &
|
2026-05-10 11:44:27 +02:00
|
|
|
" -o:/dev/null examples/nim_timer/nim_timer.nim"
|
|
|
|
|
exec "nim c " & nimFlagsRefc &
|
2026-05-03 15:48:47 +02:00
|
|
|
" --app:lib --noMain --nimMainPrefix:libnimtimer" &
|
|
|
|
|
" -d:ffiGenBindings -d:targetLang=rust" &
|
|
|
|
|
" -d:ffiOutputDir=examples/nim_timer/rust_bindings" &
|
|
|
|
|
" -d:ffiNimSrcRelPath=../nim_timer.nim" &
|
2026-05-11 22:11:25 +02:00
|
|
|
" -d:ffiNimBuildFlags=\"" & genBakedFlags & "\"" &
|
2026-05-03 15:48:47 +02:00
|
|
|
" -o:/dev/null examples/nim_timer/nim_timer.nim"
|
2026-05-03 11:11:06 +02:00
|
|
|
|
|
|
|
|
task genbindings_cpp, "Generate C++ bindings for the nim_timer example":
|
2026-05-10 11:44:27 +02:00
|
|
|
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" &
|
2026-05-11 22:11:25 +02:00
|
|
|
" -d:ffiNimBuildFlags=\"" & genBakedFlags & "\"" &
|
2026-05-10 11:44:27 +02:00
|
|
|
" -o:/dev/null examples/nim_timer/nim_timer.nim"
|
|
|
|
|
exec "nim c " & nimFlagsRefc &
|
2026-05-03 15:48:47 +02:00
|
|
|
" --app:lib --noMain --nimMainPrefix:libnimtimer" &
|
|
|
|
|
" -d:ffiGenBindings -d:targetLang=cpp" &
|
|
|
|
|
" -d:ffiOutputDir=examples/nim_timer/cpp_bindings" &
|
|
|
|
|
" -d:ffiNimSrcRelPath=../nim_timer.nim" &
|
2026-05-11 22:11:25 +02:00
|
|
|
" -d:ffiNimBuildFlags=\"" & genBakedFlags & "\"" &
|
2026-05-03 15:48:47 +02:00
|
|
|
" -o:/dev/null examples/nim_timer/nim_timer.nim"
|