Ivan FB a3e68333ab
refactor(codegen): reconcile C++ header names with the native/cbor convention
Aligns the C++ generators with the C generator and the symbol naming: the
native (zero-serialization, same-process) wrapper is the bare `<lib>.hpp` and
the CBOR (inter-process) wrapper carries the `_cbor` suffix — mirroring the C
headers (`<lib>.h` / `<lib>_cbor.h`) and the `<name>` / `<name>_cbor` exports.

Previously native was `<lib>_native.hpp` and CBOR was the bare `<lib>.hpp`,
which is backwards from the symbol convention and would collide on the native
`<lib>.h` when both ABIs emit into one dir (ffiMode=both). With the flip, a
single `genbindings_cpp` run now drops `<lib>.hpp` + `<lib>_cbor.hpp` side by
side, exactly like c_bindings holds both `.h` headers.

Consumers updated to match: the CBOR cpp_bindings driver and the C++ e2e suite
include `*_cbor.hpp`; the native example includes the bare `<lib>.hpp`.

Validated: native example runs on `my_timer.hpp`; C++ e2e suite 19/19 on the
`_cbor.hpp` headers; check_bindings_cpp regen is deterministic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 19:31:39 +02:00

40 lines
1.4 KiB
Markdown

# C++ Bindings for nim-timer
## Purpose
This folder contains **auto-generated C++ bindings** for the `my_timer` Nim library. It is generated from `../timer.nim` (with the default `both` ABI mode) and provides:
- `my_timer_cbor.hpp`: High-level C++ class (`MyTimerCtx`) wrapping the **CBOR** FFI interface (inter-process)
- `my_timer.hpp` + `my_timer.h`: the **native** (zero-serialization, same-process) wrapper and the C ABI it builds on
- `main.cpp`: Example executable demonstrating how to use the CBOR bindings
- `CMakeLists.txt`: Build configuration that compiles the Nim library and links the C++ example
The native header is the bare `my_timer.hpp` and the CBOR header carries the `_cbor` suffix — the same convention as the C bindings (`my_timer.h` / `my_timer_cbor.h`) and the underlying symbols (`<name>` / `<name>_cbor`).
## How It's Generated
Generate or regenerate these bindings by running from the parent directory:
```sh
cd examples/timer
nimble genbindings_cpp
```
This command:
1. Invokes the Nim compiler with `-d:targetLang:cpp` flag
2. Triggers `genBindings("examples/timer/cpp_bindings", "../timer.nim")` in `timer.nim`
3. Creates/updates the generated binding files
## Building the Example
```sh
cd examples/timer/cpp_bindings
cmake -S . -B build
cmake --build build
./build/example
```
## Do Not Edit
The generated files in this folder are overwritten each time `nimble genbindings_cpp` runs. Any manual changes will be lost.