@@ -108,20 +108,24 @@ fn generate_from_string(source: &str, opt: &Opt) -> Result<GeneratedCode> {
108108}
109109
110110pub ( 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