Crate includium

Crate includium 

Source
Expand description

§C Preprocessor Library

This library provides a complete C preprocessor implementation that can process C/C++ source code with macros, conditional compilation, and includes. It supports target-specific preprocessing for different operating systems and compilers.

§Features

  • Macro expansion (object-like and function-like macros)
  • Conditional compilation (#ifdef, #ifndef, #if, #else, #elif, #endif)
  • Include processing with custom resolvers
  • Target-specific macro definitions (Linux, Windows, macOS)
  • Compiler-specific macro definitions (GCC, Clang, MSVC)
  • C FFI for integration with other languages

§Example

use includium::{preprocess_c_code, PreprocessorConfig};

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).unwrap();
println!("{}", result);

Structs§

Macro
A preprocessor macro definition
Preprocessor
The main C preprocessor struct
PreprocessorConfig
Configuration for the C preprocessor

Enums§

Compiler
Compiler dialect for preprocessing
PreprocessError
Errors that can occur during preprocessing
Target
Target operating system for preprocessing

Functions§

preprocess_c_code
Preprocess C code with the given configuration. This automatically defines target and compiler-specific macros.
preprocess_c_file
Preprocess a C file and write the result to another file
preprocess_c_file_to_string
Preprocess a C file and return the result as a string

Type Aliases§

IncludeResolver
Type alias for include resolver function