@@ -1119,21 +1119,6 @@ fn generate_uniffi_bindings(
11191119 . into_path_buf ( ) ;
11201120 fs:: create_dir_all ( & binding_dir) ?;
11211121
1122- let pattern = crate_dir. join ( "src" ) . join ( "*.udl" ) ;
1123- let udls = glob:: glob ( pattern. to_str ( ) . unwrap ( ) ) ?
1124- . map ( |p| p. unwrap ( ) )
1125- . collect :: < Vec < _ > > ( ) ;
1126- let is_library = if udls. is_empty ( ) {
1127- true
1128- } else if udls. len ( ) > 1 {
1129- bail ! (
1130- "Multiple UDL files found in {}" ,
1131- crate_dir. join( "src" ) . display( )
1132- ) ;
1133- } else {
1134- false
1135- } ;
1136-
11371122 let mut cmd = uniffi_bindgen_command ( crate_dir) ?;
11381123 cmd. args ( [
11391124 "generate" ,
@@ -1152,25 +1137,17 @@ fn generate_uniffi_bindings(
11521137 . bindings
11531138 . get ( "python" )
11541139 . and_then ( |py| py. cdylib_name . clone ( ) ) ;
1155- if !is_library {
1156- cmd. arg ( "--config" ) ;
1157- cmd. arg ( config_file) ;
1158- }
1140+
1141+ // TODO: is this needed? `uniffi-bindgen` uses `uniffi.toml` by default,
1142+ // `uniffi_bindgen_command` sets cwd to the crate (workspace) root, so maybe
1143+ // we don't need to pass the config file explicitly?
1144+ cmd. arg ( "--config" ) ;
1145+ cmd. arg ( config_file) ;
11591146 }
11601147
1161- let py_binding_name = if is_library {
1162- cmd. arg ( "--library" ) ;
1163- cmd. arg ( artifact) ;
1164- let file_stem = artifact. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ;
1165- file_stem
1166- . strip_prefix ( "lib" )
1167- . unwrap_or ( file_stem)
1168- . to_string ( )
1169- } else {
1170- let udl = & udls[ 0 ] ;
1171- cmd. arg ( udl) ;
1172- udl. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( )
1173- } ;
1148+ cmd. arg ( "--library" ) ;
1149+ cmd. arg ( artifact) ;
1150+
11741151 debug ! ( "Running {:?}" , cmd) ;
11751152 let mut child = cmd. spawn ( ) . context (
11761153 "Failed to run uniffi-bindgen, did you install it? Try `pip install uniffi-bindgen`" ,
@@ -1180,15 +1157,16 @@ fn generate_uniffi_bindings(
11801157 bail ! ( "Command {:?} failed" , cmd) ;
11811158 }
11821159
1183- // uniffi bindings hardcoded the extension filenames
1184- let cdylib_name = match cdylib_name {
1185- Some ( name) => name,
1186- None => format ! ( "uniffi_{py_binding_name}" ) ,
1187- } ;
1188- let cdylib = match target_os {
1189- Os :: Macos => format ! ( "lib{cdylib_name}.dylib" ) ,
1190- Os :: Windows => format ! ( "{cdylib_name}.dll" ) ,
1191- _ => format ! ( "lib{cdylib_name}.so" ) ,
1160+ // Name of the cdylib is either from uniffi.toml or derived from the library
1161+ let cdylib = match cdylib_name {
1162+ // this logic should match with uniffi's expected names, e.g.
1163+ // https://github.com/mozilla/uniffi-rs/blob/86a34083dd18bdd33f420c602b4fad624cc1e404/uniffi_bindgen/src/bindings/python/templates/NamespaceLibraryTemplate.py#L14-L37
1164+ Some ( cdylib_name) => match target_os {
1165+ Os :: Macos => format ! ( "lib{cdylib_name}.dylib" ) ,
1166+ Os :: Windows => format ! ( "{cdylib_name}.dll" ) ,
1167+ _ => format ! ( "lib{cdylib_name}.so" ) ,
1168+ } ,
1169+ None => artifact. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
11921170 } ;
11931171
11941172 let py_bindings = fs:: read_dir ( & binding_dir) ?
0 commit comments