@@ -2302,7 +2302,12 @@ const WINDOWS_STABLE_ABI_DEBUG_LIB_NAME: &str = "python3_d";
23022302#[ allow( dead_code) ]
23032303fn default_lib_name_for_target ( abi : PythonAbi , target : & Triple ) -> String {
23042304 if target. operating_system == OperatingSystem :: Windows {
2305- default_lib_name_windows ( abi, false , false ) . unwrap ( )
2305+ default_lib_name_windows (
2306+ abi,
2307+ matches ! ( target. environment, Environment :: Gnu | Environment :: GnuLlvm ) ,
2308+ false ,
2309+ )
2310+ . unwrap ( )
23062311 } else {
23072312 default_lib_name_unix (
23082313 abi,
@@ -2314,6 +2319,10 @@ fn default_lib_name_for_target(abi: PythonAbi, target: &Triple) -> String {
23142319}
23152320
23162321fn default_lib_name_windows ( abi : PythonAbi , mingw : bool , debug : bool ) -> Result < String > {
2322+ // set `lib` prefix for mingw, as its python abi library is shipped prefixed. also mingw
2323+ // library has the version separated by dot
2324+ let ( lib_prefix, separator) = if mingw { ( "lib" , "." ) } else { ( "" , "" ) } ;
2325+
23172326 if abi. implementation . is_pypy ( ) {
23182327 // PyPy on Windows ships `libpypy3.X-c.dll` (e.g. `libpypy3.11-c.dll`),
23192328 // not CPython's `pythonXY.dll`. With raw-dylib linking we need the real
@@ -2326,7 +2335,7 @@ fn default_lib_name_windows(abi: PythonAbi, mingw: bool, debug: bool) -> Result<
23262335 // CPython bug: linking against python3_d.dll raises error
23272336 // https://github.com/python/cpython/issues/101614
23282337 Ok ( format ! (
2329- "python{}{}_d" ,
2338+ "{lib_prefix} python{}{separator }{}_d" ,
23302339 abi. version. major, abi. version. minor
23312340 ) )
23322341 } else if abi. kind == PythonAbiKind :: Stable ( StableAbi :: Abi3 )
@@ -2340,34 +2349,43 @@ fn default_lib_name_windows(abi: PythonAbi, mingw: bool, debug: bool) -> Result<
23402349 if abi. kind == PythonAbiKind :: Stable ( StableAbi :: Abi3t ) {
23412350 lib_name = lib_name. replace ( "python3" , "python3t" ) ;
23422351 }
2343- Ok ( lib_name)
2352+ Ok ( format ! ( "{lib_prefix}{ lib_name}" ) )
23442353 } else if mingw {
23452354 ensure ! (
23462355 !abi. kind. is_free_threaded( ) ,
23472356 "MinGW free-threaded builds are not currently tested or supported"
23482357 ) ;
23492358 // https://packages.msys2.org/base/mingw-w64-python
2350- Ok ( format ! ( "python{}.{}" , abi. version. major, abi. version. minor) )
2359+ Ok ( format ! (
2360+ "{lib_prefix}python{}.{}" ,
2361+ abi. version. major, abi. version. minor
2362+ ) )
23512363 } else if abi. kind ( ) . is_free_threaded ( ) {
23522364 #[ expect( deprecated, reason = "using constant internally" ) ]
23532365 {
23542366 ensure ! ( abi. version( ) >= PythonVersion :: PY313 , "Cannot compile extensions for the free-threaded build on Python versions earlier than 3.13, found {}.{}" , abi. version. major, abi. version. minor) ;
23552367 }
23562368 if debug {
23572369 Ok ( format ! (
2358- "python{}{}t_d" ,
2370+ "{lib_prefix} python{}{separator }{}t_d" ,
23592371 abi. version. major, abi. version. minor
23602372 ) )
23612373 } else {
2362- Ok ( format ! ( "python{}{}t" , abi. version. major, abi. version. minor) )
2374+ Ok ( format ! (
2375+ "{lib_prefix}python{}{separator}{}t" ,
2376+ abi. version. major, abi. version. minor
2377+ ) )
23632378 }
23642379 } else if debug {
23652380 Ok ( format ! (
2366- "python{}{}_d" ,
2381+ "{lib_prefix} python{}{separator }{}_d" ,
23672382 abi. version. major, abi. version. minor
23682383 ) )
23692384 } else {
2370- Ok ( format ! ( "python{}{}" , abi. version. major, abi. version. minor) )
2385+ Ok ( format ! (
2386+ "{lib_prefix}python{}{separator}{}" ,
2387+ abi. version. major, abi. version. minor
2388+ ) )
23712389 }
23722390}
23732391
@@ -3091,7 +3109,7 @@ mod tests {
30913109 let implementation = PythonImplementation :: CPython ;
30923110 let version = PythonVersion :: PY39 ;
30933111 let config = InterpreterConfigBuilder :: new ( implementation, version)
3094- . lib_name ( "python39 " . to_string ( ) )
3112+ . lib_name ( "libpython3.9 " . to_string ( ) )
30953113 . lib_dir ( "/usr/lib/mingw" . to_string ( ) )
30963114 . finalize ( )
30973115 . unwrap ( ) ;
@@ -3290,7 +3308,7 @@ mod tests {
32903308 false ,
32913309 )
32923310 . unwrap( ) ,
3293- "python3 .9" ,
3311+ "libpython3 .9" ,
32943312 ) ;
32953313 assert_eq ! (
32963314 super :: default_lib_name_windows(
@@ -3302,7 +3320,7 @@ mod tests {
33023320 false ,
33033321 )
33043322 . unwrap( ) ,
3305- "python3 " ,
3323+ "libpython3 " ,
33063324 ) ;
33073325 assert_eq ! (
33083326 super :: default_lib_name_windows(
0 commit comments