Building from Source¶
Advanced guide for building Neun-py from source with custom configurations.
Build System¶
Neun-py uses a multi-stage build process:
- Code Generation -
generate_pybinds.pycreates C++ bindings frommodels.json - Compilation - C++ code is compiled into a Python extension module
- Installation - Module installed in development or production mode
Makefile Targets¶
make # Default: codegen + install editable
make codegen # Force regenerate src/pybinds.cpp
make develop # Install in editable mode (pip install -e .)
make test # Import module and list available types
make sdist # Build source distribution
make wheel # Build binary wheel
make dist # Build both sdist and wheel
make clean # Remove build artifacts
Smart Regeneration¶
The build system automatically regenerates C++ bindings when:
models.jsonis modifiedgenerate_pybinds.pyis updated- Manual regeneration via
make codegen
This saves compilation time during development.
Build Configuration¶
Compiler Flags¶
The Makefile enforces C++20 via the CXXFLAGS environment variable:
Custom Compiler¶
Custom Python¶
Development Workflow¶
1. Setup Development Environment¶
git clone https://github.com/GNB-UAM/neun_py
cd neun_py
python3 -m venv venv
source venv/bin/activate
2. Initial Build¶
3. Iterative Development¶
After modifying models.json or generator:
4. Testing Changes¶
5. Clean Rebuild¶
Building Distributions¶
Source Distribution¶
Includes:
- All source files
- Headers from include/neun/
- models.json and generator
- LICENSE, README, etc.
Binary Wheel¶
Platform-specific compiled extension.
Both¶
Advanced Configuration¶
Custom Include Directories¶
If Neun headers are in a non-standard location:
Build Options in setup.py¶
Edit setup.py to customize:
- Compiler flags in
get_compile_args() - Include directories in
get_neun_include_dirs() - Extension configuration in
ext_modules
Modifying Code Generation¶
Edit generate_pybinds.py to:
- Add new model types
- Customize binding generation
- Add utility functions
- Modify enum registration
Then regenerate:
Troubleshooting Build Issues¶
Missing pybind11¶
Compiler Errors¶
Check compiler version:
Verify C++20 support:
Header Not Found¶
Ensure headers are in the expected location:
Build Cache Issues¶
Clear all build artifacts:
Next Steps¶
- Adding New Models - Extend the library
- Architecture - Understand the design
- Contributing - Submit improvements