@@ -868,49 +868,50 @@ impl BuildContext {
868868 Ok ( ( ) )
869869 }
870870
871- fn write_cffi_wheel (
872- & self ,
873- artifact : BuildArtifact ,
874- platform_tags : & [ PlatformTag ] ,
875- ext_libs : Vec < Library > ,
871+ /// Shared build pipeline for cdylib-based bindings (CFFI, UniFfi).
872+ ///
873+ /// Compiles the cdylib, runs auditwheel, resolves platform tags, writes
874+ /// the wheel via `write_wheel`, and returns the built wheel metadata.
875+ #[ allow( clippy:: needless_lifetimes) ] // false positive
876+ fn build_cdylib_wheel < ' a , F > (
877+ & ' a self ,
878+ make_generator : F ,
876879 sbom_data : & Option < SbomData > ,
877- out_dirs : & HashMap < String , PathBuf > ,
878- ) -> Result < PathBuf > {
879- let tag = self . get_universal_tag ( platform_tags) ?;
880-
881- let interpreter = self . interpreter . first ( ) . ok_or_else ( || {
882- anyhow ! ( "A python interpreter is required for cffi builds but one was not provided" )
883- } ) ?;
884- self . write_wheel (
880+ ) -> Result < ( PathBuf , HashMap < String , PathBuf > ) >
881+ where
882+ F : FnOnce ( Rc < tempfile:: TempDir > ) -> Result < Box < dyn BindingGenerator + ' a > > ,
883+ {
884+ let ( artifact, out_dirs) = self . compile_cdylib ( None , None ) ?;
885+ let ( policy, external_libs) = self . auditwheel ( & artifact, & self . platform_tag , None ) ?;
886+ let platform_tags = self . resolve_platform_tags ( & policy) ;
887+ let tag = self . get_universal_tag ( & platform_tags) ?;
888+ let wheel_path = self . write_wheel (
885889 & tag,
886890 & [ & artifact] ,
887- & [ ext_libs] ,
888- |temp_dir| {
889- Ok ( Box :: new (
890- CffiBindingGenerator :: new ( interpreter, temp_dir)
891- . context ( "Failed to initialize Cffi binding generator" ) ?,
892- ) )
893- } ,
891+ & [ external_libs] ,
892+ make_generator,
894893 sbom_data,
895- out_dirs,
896- )
894+ & out_dirs,
895+ ) ?;
896+ Ok ( ( wheel_path, out_dirs) )
897897 }
898898
899899 /// Builds a wheel with cffi bindings
900900 pub fn build_cffi_wheel (
901901 & self ,
902902 sbom_data : & Option < SbomData > ,
903903 ) -> Result < Vec < BuiltWheelMetadata > > {
904- let mut wheels = Vec :: new ( ) ;
905- let ( artifact, out_dirs) = self . compile_cdylib ( None , None ) ?;
906- let ( policy, external_libs) = self . auditwheel ( & artifact, & self . platform_tag , None ) ?;
907- let platform_tags = self . resolve_platform_tags ( & policy) ;
908- let wheel_path = self . write_cffi_wheel (
909- artifact,
910- & platform_tags,
911- external_libs,
904+ let interpreter = self . interpreter . first ( ) . ok_or_else ( || {
905+ anyhow ! ( "A python interpreter is required for cffi builds but one was not provided" )
906+ } ) ?;
907+ let ( wheel_path, _) = self . build_cdylib_wheel (
908+ |temp_dir| {
909+ Ok ( Box :: new (
910+ CffiBindingGenerator :: new ( interpreter, temp_dir)
911+ . context ( "Failed to initialize Cffi binding generator" ) ?,
912+ ) )
913+ } ,
912914 sbom_data,
913- & out_dirs,
914915 ) ?;
915916
916917 // Warn if cffi isn't specified in the requirements
@@ -927,52 +928,21 @@ impl BuildContext {
927928 }
928929
929930 eprintln ! ( "📦 Built wheel to {}" , wheel_path. display( ) ) ;
930- wheels. push ( ( wheel_path, "py3" . to_string ( ) ) ) ;
931-
932- Ok ( wheels)
933- }
934-
935- fn write_uniffi_wheel (
936- & self ,
937- artifact : BuildArtifact ,
938- platform_tags : & [ PlatformTag ] ,
939- ext_libs : Vec < Library > ,
940- sbom_data : & Option < SbomData > ,
941- out_dirs : & HashMap < String , PathBuf > ,
942- ) -> Result < PathBuf > {
943- let tag = self . get_universal_tag ( platform_tags) ?;
944-
945- self . write_wheel (
946- & tag,
947- & [ & artifact] ,
948- & [ ext_libs] ,
949- |_temp_dir| Ok ( Box :: new ( UniFfiBindingGenerator :: default ( ) ) ) ,
950- sbom_data,
951- out_dirs,
952- )
931+ Ok ( vec ! [ ( wheel_path, "py3" . to_string( ) ) ] )
953932 }
954933
955934 /// Builds a wheel with uniffi bindings
956935 pub fn build_uniffi_wheel (
957936 & self ,
958937 sbom_data : & Option < SbomData > ,
959938 ) -> Result < Vec < BuiltWheelMetadata > > {
960- let mut wheels = Vec :: new ( ) ;
961- let ( artifact, out_dirs) = self . compile_cdylib ( None , None ) ?;
962- let ( policy, external_libs) = self . auditwheel ( & artifact, & self . platform_tag , None ) ?;
963- let platform_tags = self . resolve_platform_tags ( & policy) ;
964- let wheel_path = self . write_uniffi_wheel (
965- artifact,
966- & platform_tags,
967- external_libs,
939+ let ( wheel_path, _) = self . build_cdylib_wheel (
940+ |_temp_dir| Ok ( Box :: new ( UniFfiBindingGenerator :: default ( ) ) ) ,
968941 sbom_data,
969- & out_dirs,
970942 ) ?;
971943
972944 eprintln ! ( "📦 Built wheel to {}" , wheel_path. display( ) ) ;
973- wheels. push ( ( wheel_path, "py3" . to_string ( ) ) ) ;
974-
975- Ok ( wheels)
945+ Ok ( vec ! [ ( wheel_path, "py3" . to_string( ) ) ] )
976946 }
977947
978948 fn write_bin_wheel (
0 commit comments