Skip to content

Commit f895c1f

Browse files
committed
Add SDK CodeGen
Initially C (Largely vibecoded, lol) Changelog(feat)
1 parent a9ebad8 commit f895c1f

50 files changed

Lines changed: 4117 additions & 78 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ dist/
3232
logs/
3333
log/
3434
!*/internal/log
35-
*.log
35+
*.log

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
[![Build Status](https://github.com/alia5/VIIPER/actions/workflows/snapshots.yml/badge.svg)](https://github.com/alia5/VIIPER/actions/workflows/snapshots.yml)
66
[![License: GPL-3.0](https://img.shields.io/github/license/alia5/VIIPER)](https://github.com/alia5/VIIPER/blob/main/LICENSE)
7+
[![Client SDKs: MIT](https://img.shields.io/badge/Client_SDKs-MIT-green)](https://github.com/alia5/VIIPER/blob/main/viiper/internal/codegen/common/license.go)
78
[![Release](https://img.shields.io/github/v/release/alia5/VIIPER?include_prereleases&sort=semver)](https://github.com/alia5/VIIPER/releases)
89
[![Issues](https://img.shields.io/github/issues/alia5/VIIPER)](https://github.com/alia5/VIIPER/issues)
910
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/alia5/VIIPER/pulls)
@@ -37,6 +38,8 @@ All devices _can and must be_ controlled programmatically via an API.
3738
- ✅ Cross-platform: works on Linux and Windows
3839
- ✅ Flexible logging (including raw USB packet logs)
3940
- ✅ API server for device/bus management and controlling virtual devices programmatically
41+
- ✅ Multiple client SDKs for easy integration; see [Client SDKs](docs/api/overview.md)
42+
MIT Licensed
4043

4144
## 🔌 Requirements
4245

clients/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
*/
3+
!.gitignore

docs/api/overview.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# API Reference
22

3-
VIIPER ships a lightweight TCP API for managing virtual buses/devices and for device-specific streaming. It’s designed to be trivial to drive from any language that can open a TCP socket and send newline-terminated commands.
3+
VIIPER ships a lightweight TCP API for managing virtual buses/devices and for device-specific streaming. It's designed to be trivial to drive from any language that can open a TCP socket and send newline-terminated commands.
4+
5+
!!! tip "Client SDKs Available"
6+
Generated client libraries are available that abstract away the protocol details described below. For most use cases, you should use one of the provided SDKs rather than implementing the raw protocol yourself:
7+
8+
- [C SDK](../clients/c.md): Generated C library with type-safe device streams
9+
- [Go Client](../clients/go.md): Reference implementation included in the repository
10+
- [Generator Documentation](../clients/generator.md): Information about code generation for additional languages
11+
12+
The documentation below is provided for reference and for implementing clients in languages not yet supported by the generator.
413

514
## Protocol overview
615

docs/cli/codegen.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Code Generation Command
2+
3+
The `codegen` command generates type-safe client SDKs from Go source code annotations.
4+
5+
## Usage
6+
7+
```bash
8+
viiper codegen [flags]
9+
```
10+
11+
## Description
12+
13+
Scans the VIIPER server codebase to extract:
14+
- API routes and response DTOs
15+
- Device wire formats from `viiper:wire` comment tags
16+
- Device constants (keycodes, modifiers, button masks)
17+
18+
Then generates client SDKs for C, C#, and TypeScript with:
19+
- Management API clients
20+
- Device-agnostic stream wrappers
21+
- Per-device encode/decode functions
22+
- Typed constants and enums
23+
24+
## Flags
25+
26+
### `--output`
27+
28+
Output directory for generated SDKs (relative to repository root).
29+
30+
**Default:** `../clients`
31+
**Environment Variable:** `VIIPER_CODEGEN_OUTPUT`
32+
33+
**Example:**
34+
35+
```bash
36+
viiper codegen --output=../sdk-output
37+
```
38+
39+
### `--lang`
40+
41+
Target language to generate.
42+
43+
**Values:** `c`, `csharp`, `typescript`, `all`
44+
**Default:** `all`
45+
**Environment Variable:** `VIIPER_CODEGEN_LANG`
46+
47+
**Examples:**
48+
49+
```bash
50+
# Generate all SDKs
51+
viiper codegen --lang=all
52+
53+
# Generate C SDK only
54+
viiper codegen --lang=c
55+
56+
# Generate C# SDK only
57+
viiper codegen --lang=csharp
58+
59+
# Generate TypeScript SDK only
60+
viiper codegen --lang=typescript
61+
```
62+
63+
## Output Structure
64+
65+
Generated files are organized by language:
66+
67+
```
68+
clients/
69+
├── c/
70+
│ ├── include/viiper/
71+
│ │ ├── viiper.h
72+
│ │ ├── viiper_keyboard.h
73+
│ │ ├── viiper_mouse.h
74+
│ │ └── viiper_xbox360.h
75+
│ ├── src/
76+
│ │ ├── viiper.c
77+
│ │ ├── viiper_keyboard.c
78+
│ │ ├── viiper_mouse.c
79+
│ │ └── viiper_xbox360.c
80+
│ └── CMakeLists.txt
81+
├── csharp/
82+
│ └── Viiper.Client/
83+
│ └── (generated C# files)
84+
└── ts/
85+
└── viiperclient/
86+
└── (generated TypeScript files)
87+
```
88+
89+
## Examples
90+
91+
### Generate All SDKs
92+
93+
```bash
94+
cd viiper
95+
go run ./cmd/viiper codegen
96+
```
97+
98+
### Generate C SDK and Rebuild Examples
99+
100+
```bash
101+
cd viiper
102+
go run ./cmd/viiper codegen --lang=c
103+
cd ../examples/c
104+
cmake --build build --config Release
105+
```
106+
107+
### CI/CD Integration
108+
109+
```yaml
110+
- name: Generate Client SDKs
111+
run: |
112+
cd viiper
113+
go run ./cmd/viiper codegen --lang=all
114+
```
115+
116+
## When to Regenerate
117+
118+
Run codegen when any of these change:
119+
120+
- `pkg/apitypes/*.go`: API response structures
121+
- `pkg/device/*/inputstate.go`: Wire format annotations
122+
- `pkg/device/*/const.go`: Exported constants
123+
- `internal/server/api/*.go`: Route registrations
124+
- Generator templates in `internal/codegen/generator/`
125+
126+
## See Also
127+
128+
- [Generator Documentation](../clients/generator.md): Detailed explanation of tagging system and code generation flow
129+
- [C SDK Documentation](../clients/c.md): C-specific usage and build instructions
130+
- [Configuration](configuration.md): Global configuration options

docs/cli/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ VIIPER provides a command-line interface for running the USBIP server and proxy.
66

77
- [`server`](server.md) - Start the VIIPER USBIP server
88
- [`proxy`](proxy.md) - Start the VIIPER USBIP proxy
9+
- [`codegen`](codegen.md) - Generate client SDKs from source code annotations
910

1011
## Global Options
1112

0 commit comments

Comments
 (0)