Skip to content

feat: allow custom arguments for clang #615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ The following variables affect the building the of the `opencv` crate, but belon
`*.dll`s next to your binary. Be sure to specify paths in UNIX style (/C/Program Files/Dir) because colon
in `PATH` might be interpreted as the entry separator. Summary [here](https://stackoverflow.com/a/6546427).

* `OPENCV_CLANG_ARGS`
Allow custom arguments for generating and parsing code with clang, see the [documentation for clang arguments](https://docs.rs/clang/latest/clang/struct.Parser.html#method.arguments).

* clang crate environment variables
See crate's [README](https://github.com/KyleMayes/clang-sys/blob/master/README.md#environment-variables)

Expand Down
6 changes: 6 additions & 0 deletions binding-generator/src/generator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Cow;
use std::env;
use std::fs::File;
use std::io::BufReader;
use std::ops::ControlFlow;
Expand Down Expand Up @@ -433,6 +434,11 @@ impl Generator {
args.push("-includeocvrs_common.hpp".into());
// need to have c++14 here because VS headers contain features that require it
args.push("-std=c++14".into());
// allow us to use some custom clang args
let clang_args = env::var_os("OPENCV_CLANG_ARGS").unwrap_or_default();
clang_args.to_string_lossy().split_whitespace().map(String::from).for_each(|i| {
args.push(i.into());
});
args
}

Expand Down