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.119")]
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::into_iter_without_iter,
21 clippy::items_after_statements,
22 clippy::match_bool,
23 clippy::match_on_vec_items,
24 clippy::match_same_arms,
25 clippy::missing_errors_doc,
26 clippy::module_name_repetitions,
27 clippy::must_use_candidate,
28 clippy::needless_pass_by_value,
29 clippy::new_without_default,
30 clippy::nonminimal_bool,
31 clippy::or_fun_call,
32 clippy::redundant_else,
33 clippy::shadow_unrelated,
34 clippy::similar_names,
35 clippy::single_match_else,
36 clippy::struct_excessive_bools,
37 clippy::struct_field_names,
38 clippy::too_many_arguments,
39 clippy::too_many_lines,
40 clippy::toplevel_ref_arg,
41 clippy::uninlined_format_args
42 )]
43
44 mod error;
45 mod gen;
46 mod syntax;
47
48 pub use crate::error::Error;
49 pub use crate::gen::include::{Include, HEADER};
50 pub use crate::gen::{GeneratedCode, Opt};
51 pub use crate::syntax::IncludeKind;
52 use proc_macro2::TokenStream;
53
54 /// Generate C++ bindings code from a Rust token stream. This should be a Rust
55 /// token stream which somewhere contains a `#[cxx::bridge] mod {}`.
generate_header_and_cc(rust_source: TokenStream, opt: &Opt) -> Result<GeneratedCode, Error>56 pub fn generate_header_and_cc(rust_source: TokenStream, opt: &Opt) -> Result<GeneratedCode, Error> {
57 let syntax = syn::parse2(rust_source)
58 .map_err(crate::gen::Error::from)
59 .map_err(Error::from)?;
60 gen::generate(syntax, opt).map_err(Error::from)
61 }
62