Skip to content

Commit bb4fda6

Browse files
authored
chore(agents): Update the backend creation instructions to include Rust and extra tests (#9490)
Signed-off-by: Richard Palethorpe <io@richiejp.com>
1 parent f0c9261 commit bb4fda6

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

.agents/adding-backends.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Create the backend directory under the appropriate location:
88
- **Python backends**: `backend/python/<backend-name>/`
99
- **Go backends**: `backend/go/<backend-name>/`
1010
- **C++ backends**: `backend/cpp/<backend-name>/`
11+
- **Rust backends**: `backend/rust/<backend-name>/`
1112

1213
For Python backends, you'll typically need:
1314
- `backend.py` - Main gRPC server implementation
@@ -18,9 +19,22 @@ For Python backends, you'll typically need:
1819
- `run.sh` - Runtime script
1920
- `test.py` / `test.sh` - Test files
2021

22+
For Rust backends, you'll typically need (see `backend/rust/kokoros/` as a reference):
23+
- `Cargo.toml` - Crate manifest; depend on the upstream project as a submodule under `sources/`
24+
- `build.rs` - Invokes `tonic_build` to generate gRPC stubs from `backend/backend.proto` (use the `BACKEND_PROTO_PATH` env var so the Makefile can inject the canonical copy)
25+
- `src/` - The gRPC server implementation (implement `Backend` via `tonic`)
26+
- `Makefile` - Copies `backend.proto` into the crate, runs `cargo build --release`, then `package.sh`
27+
- `package.sh` - Uses `ldd` to bundle the binary's dynamic deps and `ld.so` into `package/lib/`
28+
- `run.sh` - Sets `LD_LIBRARY_PATH`/`SSL_CERT_DIR` and execs the binary via the bundled `lib/ld.so`
29+
- `sources/<UpstreamProject>/` - Git submodule with the upstream Rust crate
30+
2131
## 2. Add Build Configurations to `.github/workflows/backend.yml`
2232

23-
Add build matrix entries for each platform/GPU type you want to support. Look at similar backends (e.g., `chatterbox`, `faster-whisper`) for reference.
33+
Add build matrix entries for each platform/GPU type you want to support. Look at similar backends for reference — `chatterbox`/`faster-whisper` for Python, `piper`/`silero-vad` for Go, `kokoros` for Rust.
34+
35+
**Without an entry here no image is ever built or pushed, and the gallery entry in `backend/index.yaml` will point at a tag that does not exist.** The `dockerfile:` field must point at `./backend/Dockerfile.<lang>` matching the language bucket from step 1 (e.g. `Dockerfile.python`, `Dockerfile.golang`, `Dockerfile.rust`). The `tag-suffix` must match the `uri:` in the corresponding `backend/index.yaml` image entry exactly.
36+
37+
If you add a new language bucket, `scripts/changed-backends.js` also needs a branch in `inferBackendPath` so PR change-detection routes file edits correctly.
2438

2539
**Placement in file:**
2640
- CPU builds: Add after other CPU builds (e.g., after `cpu-chatterbox`)
@@ -56,24 +70,28 @@ Add `backends/<backend-name>` to the `.NOTPARALLEL` line (around line 2) to prev
5670

5771
**Step 4b: Add to `prepare-test-extra`**
5872

59-
Add the backend to the `prepare-test-extra` target (around line 312) to prepare it for testing:
73+
Add the backend to the `prepare-test-extra` target to prepare it for testing. Use the path matching your language bucket (`backend/python/`, `backend/go/`, `backend/rust/`, …):
6074

6175
```makefile
6276
prepare-test-extra: protogen-python
6377
...
64-
$(MAKE) -C backend/python/<backend-name>
78+
$(MAKE) -C backend/<lang>/<backend-name>
6579
```
6680

81+
For Rust backends the target is usually the crate build target itself (e.g. `$(MAKE) -C backend/rust/<backend-name> <backend-name>-grpc`) so the binary is in place before `test` runs.
82+
6783
**Step 4c: Add to `test-extra`**
6884

69-
Add the backend to the `test-extra` target (around line 319) to run its tests:
85+
Add the backend to the `test-extra` target to run its tests applies to Go and Rust backends too, not only Python:
7086

7187
```makefile
7288
test-extra: prepare-test-extra
7389
...
74-
$(MAKE) -C backend/python/<backend-name> test
90+
$(MAKE) -C backend/<lang>/<backend-name> test
7591
```
7692

93+
Each backend's own `Makefile` should define a `test` target so this line works regardless of language. Integration tests that need large model downloads should be gated behind an env var (see `backend/rust/kokoros/`'s `KOKOROS_MODEL_PATH` pattern) so CI only runs unit tests.
94+
7795
**Step 4d: Add Backend Definition**
7896

7997
Add a backend definition variable in the backend definitions section (around line 428-457). The format depends on the backend type:
@@ -93,6 +111,13 @@ BACKEND_<BACKEND_NAME> = <backend-name>|python|./backend|false|true
93111
BACKEND_<BACKEND_NAME> = <backend-name>|golang|.|false|true
94112
```
95113

114+
**For Rust backends**:
115+
```makefile
116+
BACKEND_<BACKEND_NAME> = <backend-name>|rust|.|false|true
117+
```
118+
119+
The language field (`python`/`golang`/`rust`/…) must match a `backend/Dockerfile.<lang>` file.
120+
96121
**Step 4e: Generate Docker Build Target**
97122

98123
Add an eval call to generate the docker-build target (around line 480-501):

.agents/coding-style.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ trim_trailing_whitespace = false
4242

4343
Use `github.com/mudler/xlog` for logging which has the same API as slog.
4444

45+
## Go tests
46+
47+
All Go tests — including backend tests — must use [Ginkgo](https://onsi.github.io/ginkgo/) (v2) with Gomega matchers, not the stdlib `testing` package with `t.Run` / `t.Errorf`. A test file should register a suite with `RegisterFailHandler(Fail)` in a `TestXxx(t *testing.T)` bootstrap and use `Describe`/`Context`/`It` blocks for the actual cases. Look at any existing `*_test.go` under `core/` or `pkg/` for a template.
48+
49+
Do not mix styles within a package. If you are extending tests in a package that already uses Ginkgo, keep using Ginkgo. If you find stdlib-style Go tests in the tree, treat them as tech debt to be migrated rather than as a pattern to follow.
50+
4551
## Documentation
4652

4753
The project documentation is located in `docs/content`. When adding new features or changing existing functionality, it is crucial to update the documentation to reflect these changes. This helps users understand how to use the new capabilities and ensures the documentation stays relevant.

0 commit comments

Comments
 (0)