1 unstable release
0.1.0 | Oct 11, 2020 |
---|
#849 in Programming languages
9KB
147 lines
cpp-rs
Put this in your build.rs
to use the C pre-processor with Rust.
Example Use
fn main() {
walk_dir(CCompiler::GCC, "src")
}
This will pre-process any .cpprs
source files in src/
using
GCC.
See the lzo-macros example.
Known Defects
The C pre-processor will discard any lines beginning with #
, so that e.g.
#[macro_use]
would be thrown away.
lib.rs
:
Example
Build
You probably want the following in your build.rs
:
use cpprs::{walk_src_preprocess, CCompiler};
fn main() {
walk_src_preprocess(CCompiler::GCC, vec![])
}
This will pre-process any .cpprs
source files in src/
using
GCC.
Code
Suppose you have the following in src/lib.cpprs
:
#include <minilzo.h>
pub enum LzoError {
LzoOk = LZO_E_OK,
LzoError = LZO_E_ERROR,
LzoOutOfMemory = LZO_E_OUT_OF_MEMORY,
LzoNotCompressible = LZO_E_NOT_COMPRESSIBLE,
LzoInputOverrun = LZO_E_INPUT_OVERRUN,
LzoOutputOverrun = LZO_E_OUTPUT_OVERRUN,
LzoLookbehindOverrun = LZO_E_LOOKBEHIND_OVERRUN,
LzoEofNotFound = LZO_E_EOF_NOT_FOUND,
LzoInputNotConsumed = LZO_E_INPUT_NOT_CONSUMED,
LzoNotYetImplemented = LZO_E_NOT_YET_IMPLEMENTED,
LzoInvalidArgument = LZO_E_INVALID_ARGUMENT,
LzoInvalidAlignment = LZO_E_INVALID_ALIGNMENT,
LzoOutputNotConsumed = LZO_E_OUTPUT_NOT_CONSUMED,
LzoInternalError = LZO_E_INTERNAL_ERROR,
}
Then this will be placed in src/lib.rs
:
pub enum LzoError {
LzoOk = 0,
LzoError = (-1),
LzoOutOfMemory = (-2),
LzoNotCompressible = (-3),
LzoInputOverrun = (-4),
LzoOutputOverrun = (-5),
LzoLookbehindOverrun = (-6),
LzoEofNotFound = (-7),
LzoInputNotConsumed = (-8),
LzoNotYetImplemented = (-9),
LzoInvalidArgument = (-10),
LzoInvalidAlignment = (-11),
LzoOutputNotConsumed = (-12),
LzoInternalError = (-99),
}
i.e. the macros will be filled in.
Dependencies
~2.2–10MB
~92K SLoC