Skip to content

Commit 8bd3a4e

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
tools: move CLI entry points to tools/cmd/ for consistent layout
1 parent 02b59e1 commit 8bd3a4e

8 files changed

Lines changed: 43 additions & 11 deletions

File tree

CLAUDE.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Project Instructions
2+
3+
## Code Generation Pipeline
4+
5+
This project uses a three-stage code generation pipeline (see README.md for details):
6+
7+
1. **Stage 1 (`make specs`)**: `tools/cmd/specgen` + `c2ffi` extracts structured YAML specs from C headers into `spec/generated/`.
8+
2. **Stage 2 (`make capi`)**: `tools/cmd/capigen` generates raw CGo bindings in `capi/{module}/` from specs + manifests.
9+
3. **Stage 3 (`make idiomatic`)**: `tools/cmd/idiomgen` generates idiomatic Go packages from specs + overlays + templates.
10+
11+
## Rules
12+
13+
### Never edit generated bindings directly
14+
15+
All files under `capi/{module}/` and `{module}/` (top-level idiomatic packages like `looper/`, `camera/`, `sensor/`, etc.) are generated. They contain `// Code generated by ... DO NOT EDIT.` headers.
16+
17+
**Never edit these files.** Instead, modify the appropriate source:
18+
19+
- To change **raw CGo bindings** (`capi/`): edit `capi/manifests/{module}.yaml` or `tools/pkg/capigen/`. Nobody else writes to
20+
`capi/` but `capigen`!
21+
- To change **idiomatic Go API shape** (type names, method receivers, error handling): edit `spec/overlays/{module}.yaml`.
22+
- To change **generated code patterns** (struct layout, constructor/destructor shape, bridge code): edit `templates/*.tmpl`.
23+
- To change **spec extraction logic**: edit `tools/pkg/specgen/`.
24+
- To change **idiomatic generation logic**: edit `tools/pkg/idiomgen/` or `tools/pkg/overlaymodel/`.
25+
26+
After modifying sources, regenerate with `make idiomatic` (or `make regen` for a full rebuild).
27+
28+
### Examples must use only idiomatic bindings
29+
30+
Code in `examples/` must import only the idiomatic top-level packages (e.g., `github.com/xaionaro-go/ndk/looper`, `github.com/xaionaro-go/ndk/camera`). Never import `capi/` packages or use `import "C"` / CGo directly in examples. If the idiomatic package is missing a needed function or type, add it via the overlay and regenerate rather than falling back to capi.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ specs:
2727
manifest="capi/manifests/$$m.yaml"; \
2828
[ -f "$$manifest" ] || continue; \
2929
echo "specgen $$m (c2ffi)"; \
30-
go run ./tools/specgen \
30+
go run ./tools/cmd/specgen \
3131
-manifest "$$manifest" \
3232
-ndk-include "$(NDK_SYSROOT)" \
3333
-c2ffi-bin "$(C2FFI_BIN)" \
@@ -42,7 +42,7 @@ capi:
4242
[ -f "$$manifest" ] || continue; \
4343
[ -f "$$spec" ] || continue; \
4444
echo "capigen $$m"; \
45-
go run ./tools/capigen \
45+
go run ./tools/cmd/capigen \
4646
-spec "$$spec" \
4747
-manifest "$$manifest" \
4848
-out "capi/$$m/"; \
@@ -53,7 +53,7 @@ specs-fixtures:
5353
@for m in $(FIXTURE_MODULES); do \
5454
case $$m in simple|edgecases) continue;; esac; \
5555
echo "specgen $$m (fixture)"; \
56-
go run ./tools/specgen \
56+
go run ./tools/cmd/specgen \
5757
-module $$m \
5858
-pkg tools/pkg/specgen/testdata/$$m \
5959
-out spec/generated/$$m.yaml; \
@@ -68,7 +68,7 @@ idiomatic:
6868
goname=$$(grep 'go_name:' "$$overlay" | head -1 | awk '{print $$2}'); \
6969
[ -z "$$goname" ] && goname="$$m"; \
7070
echo "idiomgen $$m -> $$goname/"; \
71-
go run ./tools/idiomgen \
71+
go run ./tools/cmd/idiomgen \
7272
-spec "$$spec" \
7373
-overlay "$$overlay" \
7474
-templates templates/ \

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ flowchart TD
295295

296296
### Stage 1: Spec Extraction (`make specs`)
297297

298-
**Tool**: `tools/specgen` + `c2ffi` (external)
298+
**Tool**: `tools/cmd/specgen` + `c2ffi` (external)
299299

300300
Parses NDK C headers via c2ffi and extracts a structured YAML specification containing types, enums, functions, callbacks, and structs.
301301

@@ -344,7 +344,7 @@ functions:
344344

345345
### Stage 2: Raw CGo Bindings (`make capi`)
346346

347-
**Tool**: `tools/capigen` (in-repo)
347+
**Tool**: `tools/cmd/capigen` (in-repo)
348348

349349
Reads the generated spec YAML and manifest YAML, then produces raw CGo wrapper packages with type aliases, function wrappers, callback proxies, and enum constants.
350350

@@ -360,7 +360,7 @@ Reads the generated spec YAML and manifest YAML, then produces raw CGo wrapper p
360360

361361
### Stage 3: Idiomatic Go Generation (`make idiomatic`)
362362

363-
**Tool**: `tools/idiomgen` (in-repo)
363+
**Tool**: `tools/cmd/idiomgen` (in-repo)
364364

365365
Merges the generated spec with a hand-written overlay and renders Go templates to produce the final user-facing packages.
366366

@@ -513,10 +513,12 @@ flowchart TD
513513
.
514514
├── Makefile # Build orchestration
515515
├── tools/
516-
│ ├── specgen/ # Stage 1: spec extraction via c2ffi
517-
│ ├── capigen/ # Stage 2: CGo wrapper generator
518-
│ ├── idiomgen/ # Stage 3: idiomatic Go generator
519-
│ ├── headerspec/ # Standalone header spec extraction tool
516+
│ ├── cmd/
517+
│ │ ├── specgen/ # Stage 1: spec extraction via c2ffi
518+
│ │ ├── capigen/ # Stage 2: CGo wrapper generator
519+
│ │ ├── idiomgen/ # Stage 3: idiomatic Go generator
520+
│ │ ├── headerspec/ # Standalone header spec extraction tool
521+
│ │ └── ndk-build/ # APK packaging tool
520522
│ └── pkg/
521523
│ ├── c2ffi/ # c2ffi invocation and JSON→spec conversion
522524
│ ├── capigen/ # CGo code generation from spec + manifest

0 commit comments

Comments
 (0)