@@ -250,6 +250,7 @@ fn build_xcframework(
250250 consolidate_modulemap_files ( & generated_dir, & headers_module_dir) ?;
251251
252252 move_files ( "swift" , & generated_dir, & swift_dir) ?;
253+ apply_uniffi_mocks_workaround ( & swift_dir) ?;
253254
254255 println ! ( "-- Generating MatrixSDKFFI.xcframework framework" ) ;
255256 let xcframework_path = generated_dir. join ( "MatrixSDKFFI.xcframework" ) ;
@@ -431,3 +432,26 @@ fn consolidate_modulemap_files(source: &Utf8Path, destination: &Utf8Path) -> Res
431432 std:: fs:: write ( destination. join ( "module.modulemap" ) , modulemap) ?;
432433 Ok ( ( ) )
433434}
435+
436+ // Temporary workaround for https://github.com/mozilla/uniffi-rs/issues/2717
437+ fn apply_uniffi_mocks_workaround ( swift_dir : & Utf8Path ) -> Result < ( ) > {
438+ let regex = regex:: Regex :: new ( r#"(deinit\s*\{\n)(\s*try!\s*rustCall)"# ) ?;
439+
440+ for entry in swift_dir. read_dir_utf8 ( ) ? {
441+ let entry = entry?;
442+ if entry. file_type ( ) ?. is_file ( ) {
443+ let path = entry. path ( ) ;
444+ if path. extension ( ) == Some ( "swift" ) {
445+ let mut contents = std:: fs:: read_to_string ( path) ?;
446+ let new_contents =
447+ regex. replace_all ( & contents, "$1 guard handle != 0 else { return }\n $2" ) ;
448+ if new_contents != contents {
449+ contents = new_contents. to_string ( ) ;
450+ std:: fs:: write ( path, contents) ?;
451+ }
452+ }
453+ }
454+ }
455+
456+ Ok ( ( ) )
457+ }
0 commit comments