|
| 1 | +--- |
| 2 | +description: How to add a new feature to go wrappers |
| 3 | +globs: |
| 4 | +alwaysApply: false |
| 5 | +--- |
| 6 | +# Add New Feature to Go Wrappers |
| 7 | + |
| 8 | +This checklist outlines the steps required to add support for a new ICICLE feature (e.g., Sumcheck, Pairing) to the Go wrappers generator. Replace `<FeatureName>` with the PascalCase name of the feature (e.g., `Sumcheck`) and `<featurename>` with the lowercase version (e.g., `sumcheck`). |
| 9 | + |
| 10 | +**Context Files:** |
| 11 | + |
| 12 | +* `@wrappers/golang/internal/generator/config/config.go` |
| 13 | +* `@wrappers/golang/internal/generator/config/fields.go` (or similar config initialization file) |
| 14 | +* `@wrappers/golang/internal/generator/config/curves.go` (or similar config initialization file) |
| 15 | +* `@wrappers/golang/internal/generator/main.go` |
| 16 | +* `@icicle/cmake/features.cmake` |
| 17 | +* (New) `@wrappers/golang/internal/generator/<featurename>/generate.go` |
| 18 | +* (New) `@wrappers/golang/internal/generator/<featurename>/templates/<featurename>.go.tmpl` |
| 19 | +* (New) `@wrappers/golang/internal/generator/<featurename>/templates/<featurename>_test.go.tmpl` |
| 20 | +* (New) `@wrappers/golang/internal/generator/<featurename>/templates/<featurename>.h.tmpl` |
| 21 | + |
| 22 | +**Checklist:** |
| 23 | + |
| 24 | +* [ ] **Update Config Structs:** |
| 25 | + * In `wrappers/golang/internal/generator/config/config.go`: |
| 26 | + * Add `Supports<FeatureName> bool` field to `FieldData` struct. |
| 27 | + * Add `Supports<FeatureName> bool` field to `CurveData` struct. |
| 28 | + |
| 29 | +* [ ] **Update Config Initialization:** |
| 30 | + * In the files under `wrappers/golang/internal/generator/config/` where `FieldData` and `CurveData` instances are created (e.g., `fields.go`, `curves.go`): |
| 31 | + * Initialize the `Supports<FeatureName>` field for each field/curve based on its capabilities, typically by checking `icicle/cmake/features.cmake`. |
| 32 | + |
| 33 | +* [ ] **Update Main Generator (`main.go`):** |
| 34 | + * In `wrappers/golang/internal/generator/main.go`: |
| 35 | + * Update the feature parsing logic (likely reading from `features.cmake`) to recognize the new `<FeatureName>` feature string. |
| 36 | + * Set the `Supports<FeatureName>` flag accordingly in the `CurveData` or `FieldData` instances being processed. |
| 37 | + * Add the import statement for the new generator package: `_ "github.com/ingonyama-zk/icicle/v3/wrappers/golang/internal/generator/<featurename>"`. |
| 38 | + * Within the loops processing curves and fields, add a conditional call to the new feature's generator: |
| 39 | + ```go |
| 40 | + if curve.Supports<FeatureName> { // or field.Supports<FeatureName> |
| 41 | + <featurename>.Generate(outputDir, curve.Curve, ...) // Pass necessary arguments |
| 42 | + } |
| 43 | + ``` |
| 44 | + |
| 45 | +* [ ] **Create Feature Generator Directory:** |
| 46 | + * Create the directory: `wrappers/golang/internal/generator/<featurename>/` |
| 47 | + |
| 48 | +* [ ] **Create Generator Logic File:** |
| 49 | + * Create the file: `wrappers/golang/internal/generator/<featurename>/generate.go`. |
| 50 | + * Define a `Generate` function responsible for executing templates. |
| 51 | + * Define a data struct (e.g., `<FeatureName>Data`) to pass information to the templates. |
| 52 | + * Define constants for the template file paths (pointing into the `templates` subdirectory). |
| 53 | + * Implement the `Generate` function to parse templates and call `generator_utils.GenerateFile` for each template (`.go`, `_test.go`, `.h`). |
| 54 | + |
| 55 | +* [ ] **Create Templates Directory:** |
| 56 | + * Create the subdirectory: `wrappers/golang/internal/generator/<featurename>/templates/` |
| 57 | + |
| 58 | +* [ ] **Create Go Template File:** |
| 59 | + * Create the Go code template: `wrappers/golang/internal/generator/<featurename>/templates/<featurename>.go.tmpl`. |
| 60 | + * Implement the Go bindings using CGO, referencing functions defined in the corresponding `.h.tmpl`. Use template variables (e.g., `{{.Field}}`, `{{.PackageName}}`) passed from `generate.go`. |
| 61 | + |
| 62 | +* [ ] **Create Test Template File:** |
| 63 | + * Create the Go test template: `wrappers/golang/internal/generator/<featurename>/templates/<featurename>_test.go.tmpl`. |
| 64 | + * Add placeholder test functions (e.g., `Test<FeatureName>Functionality`, `Test<FeatureName>Serialization`) using the `testing` package and ideally `stretchr/testify`. Mark tests as skipped initially. |
| 65 | + |
| 66 | +* [ ] **Create Header Template File:** |
| 67 | + * Create the C header template: `wrappers/golang/internal/generator/<featurename>/templates/<featurename>.h.tmpl`. |
| 68 | + * Define the necessary C function signatures, structs (like FFI-safe configs), typedefs, and includes required for the CGO calls in the `.go.tmpl` file. Use template variables as needed. |
| 69 | + |
| 70 | +* [ ] **Run Generator:** |
| 71 | + * Execute `go generate` within the `wrappers/golang/internal/generator/` directory to test the changes and generate the new wrapper files. |
| 72 | + |
| 73 | +* [ ] **Implement TODOs:** |
| 74 | + * Fill in any `// TODO:` comments left in the generated Go code or templates, especially around complex CGO conversions, memory management, and test logic. |
0 commit comments