includium 0.1.0

A complete C preprocessor implementation in Rust.
Documentation
  • Coverage
  • 100%
    54 out of 54 items documented1 out of 4 items with examples
  • Size
  • Source code size: 145.17 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.18 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 16s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • walker84837/includium
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • walker84837

Includium

Crates.io Documentation License: MPL-2.0

A complete C preprocessor implementation in Rust.

API Documentation | CLI Documentation | Changelog

includium is a robust, well-tested C preprocessor that can process C/C++ source code with macros, conditional compilation, and includes. It supports target-specific preprocessing for different operating systems and compilers.

This repository contains both the core library and a command-line interface (includium-cli).

Features

Feature Description
Macro Expansion Supports both object-like and function-like macros
Conditional Compilation Full support for #ifdef, #ifndef, #if, #else, #elif, #endif
Include Processing Handles file inclusion with custom resolvers
Target-Specific Definitions Pre-configured macros for Linux, Windows, and macOS
Compiler Support Mock definitions for GCC, Clang, and MSVC
C FFI Integration capabilities for use with other languages and ecosystems

Supported Platforms

OS Compilers Status
Linux GCC, Clang ✅ Fully supported
Windows MSVC ✅ Fully supported
macOS Clang ✅ Fully supported

Table of Contents

Installation

Add includium to your Cargo.toml using

cargo add includium

or manually by editing Cargo.toml:

[dependencies]
includium = "0.1.0"

Usage

As a Library

[!WARNING] Compiler-specific macro definitions are approximations. While they match common behavior for GCC, Clang, and MSVC, edge cases may differ from real toolchains.

use includium::{preprocess_c_code, PreprocessorConfig};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let code = r#"
#define PI 3.14
#ifdef __linux__
const char* platform = "Linux";
#endif
    "#;

    let config = PreprocessorConfig::for_linux();
    let result = preprocess_c_code(code, &config)?;
    println!("{}", result);
    Ok(())
}

As a CLI

The includium-cli package provides a command-line interface for the C preprocessor. See the CLI documentation for detailed usage instructions.

Basic installation:

cargo install includium-cli

Basic usage:

# Preprocess a file
includium input.c -o output.i

# Cross-compile for Windows
includium input.c --target windows --compiler msvc -o win_output.i

Development

Just Tasks

This project uses Just for task automation. Available tasks:

Task Description Arguments
build Build the workspace (library + CLI) None
build-release Build in release mode None
test Run all tests None
check Run all checks (format, lint, test) None
run Run the CLI with arguments --help
run-release Run the CLI in release mode input.c -o output.i
install Install the CLI locally None
clean Clean build artifacts None
docs Generate documentation None

Building from Source

  1. Clone the repository:

    git clone https://github.com/walker84837/includium.git
    cd includium
    
  2. Build the workspace:

    cargo build # or just build
    
  3. Run tests:

    cargo test # or just test
    

Advanced Usage

[!NOTE] This section is intended for advanced users who need custom include resolution or fine-grained control over diagnostics and preprocessing behavior.

Custom Include Resolvers

use includium::Preprocessor;

let mut preprocessor = Preprocessor::new()
    .with_include_resolver(|path| {
        match path {
            "config.h" => Some("#define CONFIG_ENABLED 1".to_string()),
            "version.h" => Some("#define VERSION \"1.0.0\"".to_string()),
            _ => None,
        }
    });

#warning Handling

use includium::PreprocessorConfig;
use std::rc::Rc;

let warning_handler = Rc::new(|msg: &str| {
    eprintln!("Warning: {}", msg);
});

let config = PreprocessorConfig::for_linux()
    .with_warning_handler(warning_handler);

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Roadmap

  • CLI (includium-cli)
  • Integration tests
  • Benchmarks with cargo bench
  • CI with cross-platform tests for multiple compilers

Reporting Issues

If you find a bug or have a feature request, please open an issue with:

  1. A clear description of the problem
  2. Steps to reproduce
  3. Expected vs actual behavior
  4. Platform and compiler information

License

This project is licensed under the Mozilla Public License Version 2.0. See the LICENSE file for details.