osmaczko 0a6e833b53
feat: implement Client crate and C FFI bindings
Implement a `client` crate that wraps the `libchat` context behind a
simple `ChatClient<D>` API. The delivery strategy is pluggable via a
`DeliveryService` trait, with two implementations provided:

- `InProcessDelivery` — shared `MessageBus` for single-process tests
- `CDelivery` — C function-pointer callback for the FFI layer

Add a `client-ffi` crate that exposes the client as a C API via
`safer-ffi`. A `generate-headers` binary produces the companion C
header.

Include two runnable examples:
- `examples/in-process` — Alice/Bob exchange using in-process delivery
- `examples/c-ffi` — same exchange written entirely in C; smoketested
under valgrind (to catch memory leaks) in CI

iterates: #71
2026-03-30 21:24:29 +02:00

40 lines
1020 B
Makefile

REPO_ROOT := $(shell cd ../.. && pwd)
CARGO_PROFILE ?= debug
LIB_DIR := $(REPO_ROOT)/target/$(CARGO_PROFILE)
INCLUDE_DIR := $(REPO_ROOT)/crates/client-ffi
HEADER := $(INCLUDE_DIR)/client_ffi.h
CC ?= cc
CFLAGS := -Wall -Wextra -std=c11 -I$(INCLUDE_DIR)
LIBS := -L$(LIB_DIR) -lclient_ffi -lpthread -ldl -lm
.PHONY: all run valgrind clean generate-headers _cargo
all: c-client
generate-headers:
cargo run --manifest-path $(REPO_ROOT)/Cargo.toml \
-p client-ffi --bin generate-headers --features headers \
-- $(HEADER)
_cargo:
cargo build --manifest-path $(REPO_ROOT)/Cargo.toml -p client-ffi \
$(if $(filter release,$(CARGO_PROFILE)),--release,)
c-client: src/main.c generate-headers _cargo
$(CC) $(CFLAGS) src/main.c $(LIBS) -o c-client
run: c-client
./c-client
valgrind: c-client
valgrind \
--error-exitcode=1 \
--leak-check=full \
--errors-for-leak-kinds=definite,indirect \
--track-origins=yes \
./c-client
clean:
rm -f c-client $(HEADER)