Support generate from path in cxx-gen

This commit is contained in:
topjohnwu 2023-05-19 15:10:38 -07:00
parent 8b34a83f11
commit 7535230afb

View File

@ -51,6 +51,7 @@ pub use crate::gen::include::{Include, HEADER};
pub use crate::gen::{CfgEvaluator, CfgResult, GeneratedCode, Opt};
pub use crate::syntax::IncludeKind;
use proc_macro2::TokenStream;
use std::path::Path;
/// Generate C++ bindings code from a Rust token stream. This should be a Rust
/// token stream which somewhere contains a `#[cxx::bridge] mod {}`.
@ -60,3 +61,9 @@ pub fn generate_header_and_cc(rust_source: TokenStream, opt: &Opt) -> Result<Gen
.map_err(Error::from)?;
gen::generate(syntax, opt).map_err(Error::from)
}
/// Generate C++ bindings code from a file.
/// This should be a Rust file containing a `#[cxx::bridge] mod {}`.
pub fn generate_header_and_cc_with_path<P: AsRef<Path>>(path: P, opt: &Opt) -> GeneratedCode {
gen::generate_from_path(path.as_ref(), opt)
}