Skip to content

Commit a430b55

Browse files
committed
gen: allow for cfg_evaluator to be set in cxx_gen
This allows for users of cxx_gen to choose a cfg_evaluator, otherwise they cannot have cfg attributes in bridges.
1 parent 2193add commit a430b55

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

gen/lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod syntax;
4747

4848
pub use crate::error::Error;
4949
pub use crate::gen::include::{Include, HEADER};
50-
pub use crate::gen::{GeneratedCode, Opt};
50+
pub use crate::gen::{CfgEvaluator, CfgResult, GeneratedCode, Opt};
5151
pub use crate::syntax::IncludeKind;
5252
use proc_macro2::TokenStream;
5353

gen/src/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,32 @@ pub struct Opt {
5454
/// Rust code from one shared object or executable depends on these C++
5555
/// functions in another.
5656
pub cxx_impl_annotations: Option<String>,
57+
/// Optional [`CfgEvaluator`] for handling cfg attributes
58+
pub cfg_evaluator: Box<dyn CfgEvaluator>,
5759

5860
pub(super) gen_header: bool,
5961
pub(super) gen_implementation: bool,
6062
pub(super) allow_dot_includes: bool,
61-
pub(super) cfg_evaluator: Box<dyn CfgEvaluator>,
6263
pub(super) doxygen: bool,
6364
}
6465

65-
pub(super) trait CfgEvaluator {
66+
/// An evaluator which parses cfg attributes
67+
pub trait CfgEvaluator {
68+
/// For a given cfg name and value return a [`CfgResult`] indicating if it's enabled
6669
fn eval(&self, name: &str, value: Option<&str>) -> CfgResult;
6770
}
6871

69-
pub(super) enum CfgResult {
72+
/// Results of a [`CfgEvaluator`]
73+
pub enum CfgResult {
74+
/// cfg option is enabled
7075
True,
76+
/// cfg option is disabled
7177
False,
72-
Undetermined { msg: String },
78+
/// cfg option is not enabled or disabled
79+
Undetermined {
80+
/// Custom message explaining why the cfg option is undetermined
81+
msg: String,
82+
},
7383
}
7484

7585
/// Results of code generation.

0 commit comments

Comments
 (0)