Skip to content

Commit 2997313

Browse files
authored
Merge pull request #397 from dtolnay/multiple
Collect apis from multiple cxx::bridge in the same file
2 parents 9ca2ff2 + 42e0d6f commit 2997313

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

gen/src/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,24 @@ fn generate_from_string(source: &str, opt: &Opt) -> Result<GeneratedCode> {
108108
}
109109

110110
pub(super) fn generate(syntax: File, opt: &Opt) -> Result<GeneratedCode> {
111+
if syntax.modules.is_empty() {
112+
return Err(Error::NoBridgeMod);
113+
}
114+
115+
let ref mut apis = Vec::new();
111116
let ref mut errors = Errors::new();
112-
let bridge = syntax
113-
.modules
114-
.into_iter()
115-
.next()
116-
.ok_or(Error::NoBridgeMod)?;
117-
let ref namespace = bridge.namespace;
118-
let trusted = bridge.unsafety.is_some();
119-
let ref apis = syntax::parse_items(errors, bridge.content, trusted, namespace);
117+
for bridge in syntax.modules {
118+
let ref namespace = bridge.namespace;
119+
let trusted = bridge.unsafety.is_some();
120+
apis.extend(syntax::parse_items(errors, bridge.content, trusted, namespace));
121+
}
122+
120123
let ref types = Types::collect(errors, apis);
121124
check::precheck(errors, apis, opt);
122125
errors.propagate()?;
123126
check::typecheck(errors, apis, types);
124127
errors.propagate()?;
128+
125129
// Some callers may wish to generate both header and implementation from the
126130
// same token stream to avoid parsing twice. Others only need to generate
127131
// one or the other.

0 commit comments

Comments
 (0)