File tree Expand file tree Collapse file tree 6 files changed +39
-15
lines changed Expand file tree Collapse file tree 6 files changed +39
-15
lines changed Original file line number Diff line number Diff line change 3
3
mod test;
4
4
5
5
use super :: { Opt , Output } ;
6
+ use crate :: gen:: include:: Include ;
7
+ use crate :: syntax:: IncludeKind ;
6
8
use clap:: AppSettings ;
7
9
use std:: ffi:: { OsStr , OsString } ;
8
10
use std:: path:: PathBuf ;
@@ -63,7 +65,19 @@ pub(super) fn from_args() -> Opt {
63
65
let include = matches
64
66
. values_of ( INCLUDE )
65
67
. unwrap_or_default ( )
66
- . map ( str:: to_owned)
68
+ . map ( |include| {
69
+ if include. starts_with ( '<' ) && include. ends_with ( '>' ) {
70
+ Include {
71
+ path : include[ 1 ..include. len ( ) - 1 ] . to_owned ( ) ,
72
+ kind : IncludeKind :: Bracketed ,
73
+ }
74
+ } else {
75
+ Include {
76
+ path : include. to_owned ( ) ,
77
+ kind : IncludeKind :: Quoted ,
78
+ }
79
+ }
80
+ } )
67
81
. collect ( ) ;
68
82
69
83
let mut outputs = Vec :: new ( ) ;
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ mod output;
13
13
mod syntax;
14
14
15
15
use crate :: gen:: error:: { report, Result } ;
16
- use crate :: gen:: { fs, include} ;
16
+ use crate :: gen:: fs;
17
+ use crate :: gen:: include:: { self , Include } ;
17
18
use crate :: output:: Output ;
18
19
use std:: io:: { self , Write } ;
19
20
use std:: path:: PathBuf ;
@@ -24,7 +25,7 @@ struct Opt {
24
25
input : Option < PathBuf > ,
25
26
header : bool ,
26
27
cxx_impl_annotations : Option < String > ,
27
- include : Vec < String > ,
28
+ include : Vec < Include > ,
28
29
outputs : Vec < Output > ,
29
30
}
30
31
Original file line number Diff line number Diff line change @@ -20,8 +20,9 @@ mod gen;
20
20
mod syntax;
21
21
22
22
pub use crate :: error:: Error ;
23
- pub use crate :: gen:: include:: HEADER ;
23
+ pub use crate :: gen:: include:: { Include , HEADER } ;
24
24
pub use crate :: gen:: { GeneratedCode , Opt } ;
25
+ pub use crate :: syntax:: IncludeKind ;
25
26
use proc_macro2:: TokenStream ;
26
27
27
28
/// Generate C++ bindings code from a Rust token stream. This should be a Rust
Original file line number Diff line number Diff line change @@ -49,9 +49,16 @@ fn find_line(mut offset: usize, line: &str) -> Option<usize> {
49
49
}
50
50
}
51
51
52
- #[ derive( PartialEq ) ]
52
+ /// A header to #include.
53
+ ///
54
+ /// The cxxbridge tool does not parse or even require the given paths to exist;
55
+ /// they simply go into the generated C++ code as #include lines.
56
+ #[ derive( Clone , PartialEq , Debug ) ]
53
57
pub struct Include {
58
+ /// The header's path, not including the enclosing quotation marks or angle
59
+ /// brackets.
54
60
pub path : String ,
61
+ /// Whether to emit `#include "path"` or `#include <path>`.
55
62
pub kind : IncludeKind ,
56
63
}
57
64
@@ -82,12 +89,9 @@ impl Includes {
82
89
}
83
90
}
84
91
85
- impl < ' a > Extend < & ' a String > for Includes {
86
- fn extend < I : IntoIterator < Item = & ' a String > > ( & mut self , iter : I ) {
87
- self . custom . extend ( iter. into_iter ( ) . map ( |path| Include {
88
- path : path. clone ( ) ,
89
- kind : IncludeKind :: Quoted ,
90
- } ) ) ;
92
+ impl < ' a > Extend < & ' a Include > for Includes {
93
+ fn extend < I : IntoIterator < Item = & ' a Include > > ( & mut self , iter : I ) {
94
+ self . custom . extend ( iter. into_iter ( ) . cloned ( ) ) ;
91
95
}
92
96
}
93
97
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ mod write;
11
11
pub ( super ) use self :: error:: Error ;
12
12
use self :: error:: { format_err, Result } ;
13
13
use self :: file:: File ;
14
+ use self :: include:: Include ;
14
15
use crate :: syntax:: report:: Errors ;
15
16
use crate :: syntax:: { self , check, Types } ;
16
17
use std:: path:: Path ;
@@ -34,7 +35,7 @@ pub struct Opt {
34
35
/// Any additional headers to #include. The cxxbridge tool does not parse or
35
36
/// even require the given paths to exist; they simply go into the generated
36
37
/// C++ code as #include lines.
37
- pub include : Vec < String > ,
38
+ pub include : Vec < Include > ,
38
39
/// Optional annotation for implementations of C++ function wrappers that
39
40
/// may be exposed to Rust. You may for example need to provide
40
41
/// `__declspec(dllexport)` or `__attribute__((visibility("default")))` if
Original file line number Diff line number Diff line change @@ -52,10 +52,13 @@ pub struct Include {
52
52
pub end_span : Span ,
53
53
}
54
54
55
- #[ derive( Copy , Clone , PartialEq ) ]
55
+ /// Whether to emit `#include "path"` or `#include <path>`.
56
+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
56
57
pub enum IncludeKind {
57
- Quoted , // #include "quoted/path/to"
58
- Bracketed , // #include <bracketed/path/to>
58
+ /// `#include "quoted/path/to"`
59
+ Quoted ,
60
+ /// `#include <bracketed/path/to>`
61
+ Bracketed ,
59
62
}
60
63
61
64
pub struct ExternType {
You can’t perform that action at this time.
0 commit comments