Skip to main content

A powerful source file amalgamator for C/C++ projects

Project description

๐Ÿ”— Singleston

A powerful source file amalgamator that converts multi-file projects into a single, self-contained source file. Currently supports C and C++ projects, using compiler-generated dependency files to intelligently resolve includes and create properly ordered, unified source code.

Perfect for creating single-header libraries, distributing code, simplifying builds, or reducing compilation complexity.

โœจ Features

  • ๐Ÿ” Smart Dependency Resolution: Uses compiler-generated .d files for accurate dependency tracking
  • ๐Ÿ“ C/C++ Support: Handles both C and C++ files with any header extension (.h, .hh, .hpp, etc.)
  • ๐Ÿ”„ Intelligent Include Processing:
    • Preserves system includes (#include <system>)
    • Removes local includes for files being amalgamated
    • Deduplicates includes while preserving order of first appearance
  • ๐Ÿ›ก๏ธ Include Guard Removal: Automatically detects and removes both #pragma once and traditional include guards
  • ๐Ÿ“Š Topological Sorting: Ensures proper file processing order based on dependency relationships
  • ๐ŸŽฏ First Appearance Priority: Processes files in order of first appearance across dependency files

๐ŸŽ Advanced Features

  • ๐Ÿ”ง Flexible Output Options: Write to file (-o) or stdout by default
  • ๐Ÿ“ File Boundary Markers: Optional separators (--add-separators) for debugging
  • ๐Ÿ” Verbose Mode: Detailed processing information (-v, --verbose) for troubleshooting
  • ๐Ÿ”— Symlink Support: Optional symlink following (--follow-symlinks) for complex project structures
  • ๐Ÿšจ Comprehensive Error Handling: Colored error messages with detailed diagnostics
  • โšก High Performance: Efficient processing even for large codebases

๐Ÿ› ๏ธ Build Integration

  • ๐Ÿ”Œ Makefile Integration: Works seamlessly with existing build systems
  • ๐Ÿ“ฆ Batch Processing: Handle multiple dependency files in a single command
  • ๐Ÿ”„ Automated Workflow: Integrate into CI/CD pipelines for automated amalgamation
  • ๐ŸŽฏ Zero Configuration: Works out of the box with standard gcc/clang -MMD output

๐Ÿ“ฆ Prerequisites

  • Python 3.8+: Required for running the amalgamator
  • C/C++ Compiler: clang or gcc with -MMD flag support for dependency generation
  • Make: For using the provided build system (optional)

๐Ÿš€ Quick Start

1. Generate Dependency Files

First, compile your project with dependency generation enabled:

# Using the example project
cd examples/simple_plugins
make

# Or manually with clang/gcc
clang++ -MMD -c src/main.cpp -o src/main.o
clang++ -MMD -c src/utils.cpp -o src/utils.o

2. Run Singleston

# Using the installed console command
singleston examples/simple_plugins/srcs/*.d -o amalgamated.cpp

# Or using the script directly
./scripts/singleston.py examples/simple_plugins/srcs/*.d -o amalgamated.cpp

# With verbose output and file separators
singleston examples/simple_plugins/srcs/*.d -o amalgamated.cpp --verbose --add-separators

3. Compile the Result

# Compile the amalgamated file
clang++ -O2 amalgamated.cpp -o final_executable

๐Ÿš€ Installation

From PyPI

pip install singleston

From Source

git clone https://github.com/ChuOkupai/singleston
cd singleston
pip install -e .

๐Ÿ”ง Development

Setup Development Environment

# Clone the repository
git clone https://github.com/ChuOkupai/singleston
cd singleston

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install development dependencies
pip install -r requirements-dev.txt

Building and Publishing

# Build distribution packages
make build
# or
python -m build

# Upload to TestPyPI (for testing)
make upload-test

# Upload to PyPI (for release)
make upload

๐Ÿ› ๏ธ Usage

Synopsis

singleston [-o OUTPUT_FILE] [-v|--verbose] [--add-separators] [--follow-symlinks] DEPS_FILE [DEPS_FILE...]

Options

  • -o OUTPUT_FILE: Output file path (default: stdout)
  • -v, --verbose: Enable verbose output for debugging
  • -h, --help: Show help message and exit
  • --add-separators: Add file boundary markers in output
  • --follow-symlinks: Follow symbolic links in include paths

Arguments

  • DEPS_FILE: One or more compiler-generated dependency files (.d format from gcc/clang -MMD)

Examples

# Basic usage with the console command
singleston examples/simple_plugins/srcs/*.d -o export.cpp

# Using the script directly
./scripts/singleston.py examples/simple_plugins/srcs/*.d -o export.cpp

# Complex project with verbose output
singleston src/*.d lib/*.d -o amalgamated.cpp --verbose

# Debug mode with file separators
singleston examples/simple_plugins/srcs/*.d --add-separators --verbose

# Handle symlinked includes
singleston examples/simple_plugins/srcs/*.d -o output.cpp --follow-symlinks

๐ŸŽฏ Example Project

The repository includes a complete example project in examples/simple_plugins/:

# Build the example project
cd examples/simple_plugins
make

# Amalgamate the project (using console command)
cd ../..
singleston examples/simple_plugins/srcs/*.d -o example_export.cpp --verbose

# Or from within the project directory
cd examples/simple_plugins
singleston srcs/*.d -o example_export.cpp --verbose

# Verify the amalgamated file compiles
clang++ -O2 example_export.cpp -o example_executable
./example_executable

๐ŸŽฏ Use Cases

๐Ÿ“š Single-Header Libraries

Convert multi-file C++ libraries into single-header distributions

๐Ÿš€ Performance Optimization

Reduce compilation times by eliminating include overhead

๐Ÿ“ฆ Code Distribution

Package entire projects into single files for easy sharing

๐Ÿ› ๏ธ Build System Integration

Integrate into existing build systems and CI/CD pipelines

๐Ÿงช Testing

The project includes a comprehensive test suite:

# Run all tests
python -m unittest discover tests/

# Run with coverage
make coverage

๐Ÿ› Troubleshooting

Common Issues

Issue: error: dependency file not found

# Solution: Ensure you've compiled with -MMD first
cd examples/simple_plugins && make

Issue: error: cannot read dependency file (permission denied)

# Solution: Check file permissions
chmod 644 examples/simple_plugins/srcs/*.d

Issue: Missing system includes in output

# Solution: Use verbose mode to debug include processing
./scripts/singleston.py examples/simple_plugins/srcs/*.d --verbose

๐Ÿค Contributing

Contributions are welcome! We're especially interested in:

  • Language support: Help add support for Python, Java, Rust, Go, and other languages
  • Feature improvements: Better dependency analysis, optimization features
  • Bug fixes: Help improve reliability and edge case handling

Development Notes

  • Code Style: This project uses .editorconfig for consistent formatting
  • AI Generated: Much of the codebase contains AI-generated code - feel free to improve and refactor
  • Testing: Please include tests for new features

Development Setup

# Clone the repository
git clone https://github.com/ChuOkupai/singleston
cd singleston

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
make test

# Check code quality
make lint

๐ŸŒ Community & Contributing

More languages needed! While singleston currently supports C and C++ projects, we encourage the community to contribute support for additional programming languages. Whether it's Python, Java, Rust, or any other language - your contributions are welcome!

โš–๏ธ License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

singleston-1.0.1.tar.gz (34.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

singleston-1.0.1-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file singleston-1.0.1.tar.gz.

File metadata

  • Download URL: singleston-1.0.1.tar.gz
  • Upload date:
  • Size: 34.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for singleston-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cde5ee0641ff6324f483a854298cb0cba577049087a52f7f98161ee75d608343
MD5 5d3ada7194eae65ea1a1ee7babb4c3d4
BLAKE2b-256 2d1e6d1085abe36f3d5e8ff72b68f270a1af2249264bb5e3639ea462a82201a9

See more details on using hashes here.

File details

Details for the file singleston-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: singleston-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for singleston-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 335d4c9cd725f416cf04dd4369a47549d24da36cc523da175e3aa5a2c9807c15
MD5 8b12a7ce9971a04eb1c9cc0630c1d5fe
BLAKE2b-256 c796edff0a40d9de5d4b98f9442278628fc98e7ba52ac0c00e5f84e85123aadf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page