@@ -141,112 +141,8 @@ fn main() -> Result<()> {
141141 out_dir. join( "initializer.js" ) . display( )
142142 )
143143 } ) ?;
144-
145- // Write exports and imports as JSON (manual serialization)
146- let exports_json = serialize_exports ( & result. exports ) ;
147- fs:: write ( out_dir. join ( "exports.json" ) , exports_json) . with_context ( || {
148- format ! (
149- "Failed to write exports file: {}" ,
150- out_dir. join( "exports.json" ) . display( )
151- )
152- } ) ?;
153-
154- let imports_json = serialize_imports ( & result. imports ) ;
155- fs:: write ( out_dir. join ( "imports.json" ) , imports_json) . with_context ( || {
156- format ! (
157- "Failed to write imports file: {}" ,
158- out_dir. join( "imports.json" ) . display( )
159- )
160- } ) ?;
161-
162- println ! (
163- "Successfully generated bindings and saved to {}" ,
164- out_dir. display( )
165- ) ;
166144 }
167145 }
168146
169147 Ok ( ( ) )
170148}
171-
172- /// Manually serialize exports to JSON
173- fn serialize_exports ( exports : & [ ( String , CoreFn ) ] ) -> String {
174- let mut result = String :: from ( "[\n " ) ;
175- for ( i, ( name, core_fn) ) in exports. iter ( ) . enumerate ( ) {
176- if i > 0 {
177- result. push_str ( ",\n " ) ;
178- }
179- result. push_str ( " [\" " ) ;
180- result. push_str ( & name. replace ( '\\' , "\\ \\ " ) . replace ( '"' , "\\ \" " ) ) ;
181- result. push_str ( "\" , " ) ;
182- result. push_str ( & serialize_core_fn ( core_fn) ) ;
183- result. push ( ']' ) ;
184- }
185- result. push_str ( "\n ]" ) ;
186- result
187- }
188-
189- /// Manually serialize imports to JSON
190- fn serialize_imports ( imports : & [ ( String , String , u32 ) ] ) -> String {
191- let mut result = String :: from ( "[\n " ) ;
192- for ( i, ( specifier, name, arg_count) ) in imports. iter ( ) . enumerate ( ) {
193- if i > 0 {
194- result. push_str ( ",\n " ) ;
195- }
196- result. push_str ( " [\" " ) ;
197- result. push_str ( & specifier. replace ( '\\' , "\\ \\ " ) . replace ( '"' , "\\ \" " ) ) ;
198- result. push_str ( "\" , \" " ) ;
199- result. push_str ( & name. replace ( '\\' , "\\ \\ " ) . replace ( '"' , "\\ \" " ) ) ;
200- result. push_str ( "\" , " ) ;
201- result. push_str ( & arg_count. to_string ( ) ) ;
202- result. push ( ']' ) ;
203- }
204- result. push_str ( "\n ]" ) ;
205- result
206- }
207-
208- /// Manually serialize CoreFn to JSON
209- fn serialize_core_fn ( core_fn : & CoreFn ) -> String {
210- let mut result = String :: from ( "{" ) ;
211-
212- // params
213- result. push_str ( "\" params\" : [" ) ;
214- for ( i, param) in core_fn. params . iter ( ) . enumerate ( ) {
215- if i > 0 {
216- result. push_str ( ", " ) ;
217- }
218- result. push_str ( & serialize_core_ty ( param) ) ;
219- }
220- result. push_str ( "], " ) ;
221-
222- // ret
223- result. push_str ( "\" ret\" : " ) ;
224- if let Some ( ref ret) = core_fn. ret {
225- result. push_str ( & serialize_core_ty ( ret) ) ;
226- } else {
227- result. push_str ( "null" ) ;
228- }
229- result. push_str ( ", " ) ;
230-
231- // retptr
232- result. push_str ( & format ! ( "\" retptr\" : {}, " , core_fn. retptr) ) ;
233-
234- // retsize
235- result. push_str ( & format ! ( "\" retsize\" : {}, " , core_fn. retsize) ) ;
236-
237- // paramptr
238- result. push_str ( & format ! ( "\" paramptr\" : {}" , core_fn. paramptr) ) ;
239-
240- result. push ( '}' ) ;
241- result
242- }
243-
244- /// Manually serialize CoreTy to JSON
245- fn serialize_core_ty ( core_ty : & CoreTy ) -> String {
246- match core_ty {
247- CoreTy :: I32 => "\" i32\" " . to_string ( ) ,
248- CoreTy :: I64 => "\" i64\" " . to_string ( ) ,
249- CoreTy :: F32 => "\" f32\" " . to_string ( ) ,
250- CoreTy :: F64 => "\" f64\" " . to_string ( ) ,
251- }
252- }
0 commit comments