• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #![allow(dead_code)]
11 #![allow(
12     clippy::cast_sign_loss,
13     clippy::default_trait_access,
14     clippy::enum_glob_use,
15     clippy::if_same_then_else,
16     clippy::inherent_to_string,
17     clippy::items_after_statements,
18     clippy::match_bool,
19     clippy::match_on_vec_items,
20     clippy::match_same_arms,
21     clippy::missing_errors_doc,
22     clippy::module_name_repetitions,
23     clippy::needless_pass_by_value,
24     clippy::new_without_default,
25     clippy::nonminimal_bool,
26     clippy::option_if_let_else,
27     clippy::or_fun_call,
28     clippy::redundant_else,
29     clippy::shadow_unrelated,
30     clippy::similar_names,
31     clippy::single_match_else,
32     clippy::struct_excessive_bools,
33     clippy::too_many_arguments,
34     clippy::too_many_lines,
35     clippy::toplevel_ref_arg,
36     // clippy bug: https://github.com/rust-lang/rust-clippy/issues/6983
37     clippy::wrong_self_convention
38 )]
39 
40 mod error;
41 mod gen;
42 mod syntax;
43 
44 pub use crate::error::Error;
45 pub use crate::gen::include::{Include, HEADER};
46 pub use crate::gen::{GeneratedCode, Opt};
47 pub use crate::syntax::IncludeKind;
48 use proc_macro2::TokenStream;
49 
50 /// Generate C++ bindings code from a Rust token stream. This should be a Rust
51 /// token stream which somewhere contains a `#[cxx::bridge] mod {}`.
generate_header_and_cc(rust_source: TokenStream, opt: &Opt) -> Result<GeneratedCode, Error>52 pub fn generate_header_and_cc(rust_source: TokenStream, opt: &Opt) -> Result<GeneratedCode, Error> {
53     let syntax = syn::parse2(rust_source)
54         .map_err(crate::gen::Error::from)
55         .map_err(Error::from)?;
56     gen::generate(syntax, opt).map_err(Error::from)
57 }
58