mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-20 16:29:31 +00:00
The C codegen already emitted `my_timer.h` / `my_timer_cbor.h`, but the example had no runnable driver. Add `example.c` exercising the native ABI end-to-end (ctor with a struct param, string-returning version, struct-param echo, and a deeply nested ComplexRequest), plus a Makefile that builds the Nim dylib from the repo root — where the vendored Nimble deps resolve — and links the driver. Native is the same-process path; the companion CBOR headers are for crossing a process/machine boundary (see the forthcoming ipc example). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
41 lines
1.0 KiB
Makefile
41 lines
1.0 KiB
Makefile
# Build the native (same-process) C example for the timer library.
|
|
#
|
|
# make run # build the Nim dylib + the C driver, then run it
|
|
# make clean
|
|
#
|
|
# The Nim library is compiled from the repository root so its vendored Nimble
|
|
# dependencies resolve, exactly like the CMake-based C++ example does.
|
|
|
|
REPO_ROOT := $(abspath ../../..)
|
|
NIM_SRC := $(REPO_ROOT)/examples/timer/timer.nim
|
|
|
|
UNAME_S := $(shell uname -s)
|
|
ifeq ($(UNAME_S),Darwin)
|
|
LIBNAME := libmy_timer.dylib
|
|
RPATH := -Wl,-rpath,.
|
|
else
|
|
LIBNAME := libmy_timer.so
|
|
RPATH := -Wl,-rpath,'$$ORIGIN'
|
|
endif
|
|
|
|
CC ?= cc
|
|
CFLAGS ?= -std=c11 -Wall -Wextra -O2
|
|
NIMFLAGS := --mm:orc -d:chronicles_log_level=WARN --app:lib --noMain \
|
|
--nimMainPrefix:libmy_timer
|
|
|
|
.PHONY: all run clean
|
|
|
|
all: example
|
|
|
|
$(LIBNAME):
|
|
cd $(REPO_ROOT) && nim c $(NIMFLAGS) -o:$(CURDIR)/$(LIBNAME) $(NIM_SRC)
|
|
|
|
example: example.c my_timer.h $(LIBNAME)
|
|
$(CC) $(CFLAGS) -I. example.c -L. -lmy_timer $(RPATH) -o example
|
|
|
|
run: example
|
|
./example
|
|
|
|
clean:
|
|
rm -f example $(LIBNAME)
|