Skip to content

Development

Setting Up Development Environment

Clone the repository and install dependencies:

Terminal window
git clone https://github.com/mylonics/struct-frame.git
cd struct-frame
# Install Python dependencies
pip install proto-schema-parser
# Install Node.js dependencies (for TypeScript tests)
npm install

Running from Source

Terminal window
# Using PYTHONPATH
PYTHONPATH=src python src/main.py examples/basic/hello.sf --build_py
# Or install in editable mode
pip install -e .
python -m struct_frame examples/basic/hello.sf --build_py

Project Structure

struct-frame/
src/
main.py # CLI entry point
struct_frame/
generate.py # Proto parsing and validation
language_facts.py # Primitive types, option names, limits (shared with the VS Code extension)
c_gen.py # C code generator
cpp_gen.py # C++ code generator
ts_gen.py # TypeScript code generator
py_gen.py # Python code generator
js_gen.py # JavaScript code generator
gql_gen.py # GraphQL code generator
csharp_gen.py # C# code generator
rust_gen.py # Rust code generator
naming.py # Generated-name rules, reserved words, --name_overrides
schema_diff.py # `struct_frame diff` wire-compatibility check
boilerplate/ # Runtime library templates
c/
cpp/
ts/
py/
js/ # compiled from ts/ (do not hand-edit; see below)
csharp/
rust/
tests/
run_tests.py # Cross-language test runner (see `python test_all.py`)
proto/ # Test schemas (.sf)
c/, cpp/, py/, ts/, js/, csharp/, rust/ # Language-specific tests
test_*.py # pytest suites for the generator itself
examples/ # Example schemas and tested programs
wireshark/ # Lua dissector (see wireshark/README.md)
editors/vscode/ # VS Code extension + language server for .sf files
docs/ # Documentation site sources

Adding or changing a schema option

The compiler and the VS Code extension read the language’s primitive types, option names, accepted values and numeric limits from one place, src/struct_frame/language_facts.py:

  1. Change the table in language_facts.py and the compiler code that uses it in generate.py.
  2. Regenerate the extension’s copy: python src/struct_frame/language_facts.py --write. CI runs --check and fails if it is stale.
  3. Add hover text for any new name in editors/vscode/server/src/docs.ts, plus any new validation in server.ts. npm test in editors/vscode fails until every name is documented.
  4. The extension’s corpus test requires zero language-server errors on every schema the compiler accepts (tests/proto, examples, tests/benchmarks/schema, tests/docs/schemas).

Changes under editors/vscode are published as a new extension version with the next PyPI release (see docs/dev/RELEASE.md).

Code Generation Pipeline

  1. Parsing: Read proto file using proto-schema-parser
  2. Validation: Check schema (unique IDs, field numbers, required options)
  3. Generation: Language-specific generators produce output files
  4. Boilerplate: Runtime libraries are copied to output directories

Making Changes

Editing the JavaScript runtime

boilerplate/js/ is compiled from boilerplate/ts/. Edit the TypeScript and rebuild; never edit the JavaScript by hand:

Terminal window
npm ci
./node_modules/.bin/tsc -p src/struct_frame/boilerplate/ts/tsconfig.cjs.json

(A type error about the optional serialport module is benign; the output is still emitted.) tests/test_generator_regressions.py fails if the compiled SDK lacks members the TypeScript SDK has.

Modifying Generators

Each language has a generator in src/struct_frame/<lang>_gen.py. Generators must implement:

  • Type mapping from proto types to target language types
  • Message struct/class generation
  • Enum generation
  • Array handling (fixed and bounded)
  • String handling
  • Serialization/deserialization code

Adding a New Target Language

  1. Create <lang>_gen.py in src/struct_frame/
  2. Implement the generator class
  3. Add boilerplate files to src/struct_frame/boilerplate/<lang>/
  4. Add CLI flag in src/main.py
  5. Add tests in tests/<lang>/
  6. Register the language in tests/run_tests.py (_init_languages) and add it to the CI lanes in .github/workflows/test.yml

Building for Release

Terminal window
# Update version in pyproject.toml
pip install --upgrade build twine
python -m build
python -m twine upload dist/*

Common Development Tasks

Regenerate All Examples

Terminal window
PYTHONPATH=src python src/main.py examples/generic_robot.sf \
--build_c --build_cpp --build_ts --build_py --build_gql

Run Quick Validation

Terminal window
# Generate and check for errors
PYTHONPATH=src python src/main.py examples/array_test.sf --build_py --py_path generated/py
# Import generated code
python -c "import sys; sys.path.insert(0, 'generated/py'); from structframe.array_test import get_message_info"

Running the Tests

Terminal window
python test_all.py # every language available on this machine
python test_all.py --require-langs c,cpp,py,ts,js,csharp,rust # fail instead of skipping a missing toolchain
python -m pytest tests # generator-level pytest suites only

New schema-validation behaviour should get a test in tests/test_generator_regressions.py (or tests/test_generator_validation.py); documentation samples that compile belong in examples/ so tests/test_examples.py builds and runs them.

Code Style

  • Python: Follow existing style in codebase
  • C: See .clang-format
  • Generated code should be readable and debuggable