1 //! The CXX code generator for constructing and compiling C++ code.
2 //!
3 //! This is intended as a mechanism for embedding the `cxx` crate into
4 //! higher-level code generators. See [dtolnay/cxx#235] and
5 //! [https://github.com/google/autocxx].
6 //!
7 //! [dtolnay/cxx#235]: https://github.com/dtolnay/cxx/issues/235
8 //! [https://github.com/google/autocxx]: https://github.com/google/autocxx
9
10 #![doc(html_root_url = "https://docs.rs/cxx-gen/0.7.97")]
11 #![deny(missing_docs)]
12 #![allow(dead_code)]
13 #![allow(
14 clippy::cast_sign_loss,
15 clippy::default_trait_access,
16 clippy::derive_partial_eq_without_eq,
17 clippy::enum_glob_use,
18 clippy::if_same_then_else,
19 clippy::inherent_to_string,
20 clippy::items_after_statements,
21 clippy::match_bool,
22 clippy::match_on_vec_items,
23 clippy::match_same_arms,
24 clippy::missing_errors_doc,
25 clippy::module_name_repetitions,
26 clippy::needless_pass_by_value,
27 clippy::new_without_default,
28 clippy::nonminimal_bool,
29 clippy::option_if_let_else,
30 clippy::or_fun_call,
31 clippy::redundant_else,
32 clippy::shadow_unrelated,
33 clippy::similar_names,
34 clippy::single_match_else,
35 clippy::struct_excessive_bools,
36 clippy::too_many_arguments,
37 clippy::too_many_lines,
38 clippy::toplevel_ref_arg,
39 // clippy bug: https://github.com/rust-lang/rust-clippy/issues/6983
40 clippy::wrong_self_convention
41 )]
42
43 mod error;
44 mod gen;
45 mod syntax;
46
47 pub use crate::error::Error;
48 pub use crate::gen::include::{Include, HEADER};
49 pub use crate::gen::{GeneratedCode, Opt};
50 pub use crate::syntax::IncludeKind;
51 use proc_macro2::TokenStream;
52
53 /// Generate C++ bindings code from a Rust token stream. This should be a Rust
54 /// token stream which somewhere contains a `#[cxx::bridge] mod {}`.
generate_header_and_cc(rust_source: TokenStream, opt: &Opt) -> Result<GeneratedCode, Error>55 pub fn generate_header_and_cc(rust_source: TokenStream, opt: &Opt) -> Result<GeneratedCode, Error> {
56 let syntax = syn::parse2(rust_source)
57 .map_err(crate::gen::Error::from)
58 .map_err(Error::from)?;
59 gen::generate(syntax, opt).map_err(Error::from)
60 }
61