ocl-include

Crates.io Docs.rs Travis CI Appveyor Codecov.io License

Simple preprocessor that implements #include mechanism for OpenCL source files.

About

OpenCL API doesn't provide mechanism for including header files into the main one, like in C and C++. This crate is a simple preprocessor that handles #include ... and #pragma once directives in source files, collects them over filesystem or memory, and gives a single string to the output that could be passed to OpenCL kernel builder.

Documentation

Examples

Let you have main.c and header.h files in ./kernels/ folder:

main.c: ```c

include

int main() { return RET_CODE; } ```

header.h: ```c

pragma once

static const int RET_CODE = 0; ```

Filesystem only

The follwong code takes main.c from the filesystem and includes header.h into it.

```rust use std::path::Path; use ocl_include::*;

fn main() { let hook = FsHook::new() .include_dir(&Path::new("./examples")).unwrap();

let node = collect(&hook, Path::new("main.c")).unwrap();

println!("{}", node.collect());

} ```

Filesystem and memory

The follwong code takes main.c source from the memory and includes header.h into it from the filesystem.

```rust use std::path::Path; use ocl_include::*;

fn main() { let main = r" #include int main() { return ~RET_CODE; } ";

let hook = ListHook::new()
.add_hook(
    MemHook::new()
    .add_file(&Path::new("main.c"), main.to_string()).unwrap()
)
.add_hook(
    FsHook::new()
    .include_dir(&Path::new("./examples")).unwrap()
);

let node = collect(&hook, Path::new("main.c")).unwrap();

println!("{}", node.collect());

} ```

Hooks

Hook is a handler that retrieve files by their names.

The crate contains the following hooks now:

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.