@@ -2314,6 +2314,9 @@ fn default_lib_name_for_target(abi: PythonAbi, target: &Triple) -> String {
23142314}
23152315
23162316fn default_lib_name_windows ( abi : PythonAbi , mingw : bool , debug : bool ) -> Result < String > {
2317+ // set `lib` prefix for mingw, as its python abi library is shipped prefixed
2318+ let lib_prefix = if mingw { "lib" } else { "" } ;
2319+
23172320 if abi. implementation . is_pypy ( ) {
23182321 // PyPy on Windows ships `libpypy3.X-c.dll` (e.g. `libpypy3.11-c.dll`),
23192322 // not CPython's `pythonXY.dll`. With raw-dylib linking we need the real
@@ -2326,8 +2329,8 @@ fn default_lib_name_windows(abi: PythonAbi, mingw: bool, debug: bool) -> Result<
23262329 // CPython bug: linking against python3_d.dll raises error
23272330 // https://github.com/python/cpython/issues/101614
23282331 Ok ( format ! (
2329- "python{}{}_d" ,
2330- abi. version. major, abi. version. minor
2332+ "{} python{}{}_d" ,
2333+ lib_prefix , abi. version. major, abi. version. minor
23312334 ) )
23322335 } else if abi. kind == PythonAbiKind :: Stable ( StableAbi :: Abi3 )
23332336 || abi. kind == PythonAbiKind :: Stable ( StableAbi :: Abi3t )
@@ -2340,34 +2343,43 @@ fn default_lib_name_windows(abi: PythonAbi, mingw: bool, debug: bool) -> Result<
23402343 if abi. kind == PythonAbiKind :: Stable ( StableAbi :: Abi3t ) {
23412344 lib_name = lib_name. replace ( "python3" , "python3t" ) ;
23422345 }
2343- Ok ( lib_name)
2346+ Ok ( format ! ( "{}{}" , lib_prefix , lib_name) )
23442347 } else if mingw {
23452348 ensure ! (
23462349 !abi. kind. is_free_threaded( ) ,
23472350 "MinGW free-threaded builds are not currently tested or supported"
23482351 ) ;
23492352 // https://packages.msys2.org/base/mingw-w64-python
2350- Ok ( format ! ( "python{}.{}" , abi. version. major, abi. version. minor) )
2353+ Ok ( format ! (
2354+ "{}python{}.{}" ,
2355+ lib_prefix, abi. version. major, abi. version. minor
2356+ ) )
23512357 } else if abi. kind ( ) . is_free_threaded ( ) {
23522358 #[ expect( deprecated, reason = "using constant internally" ) ]
23532359 {
23542360 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) ;
23552361 }
23562362 if debug {
23572363 Ok ( format ! (
2358- "python{}{}t_d" ,
2359- abi. version. major, abi. version. minor
2364+ "{} python{}{}t_d" ,
2365+ lib_prefix , abi. version. major, abi. version. minor
23602366 ) )
23612367 } else {
2362- Ok ( format ! ( "python{}{}t" , abi. version. major, abi. version. minor) )
2368+ Ok ( format ! (
2369+ "{}python{}{}t" ,
2370+ lib_prefix, abi. version. major, abi. version. minor
2371+ ) )
23632372 }
23642373 } else if debug {
23652374 Ok ( format ! (
2366- "python{}{}_d" ,
2367- abi. version. major, abi. version. minor
2375+ "{} python{}{}_d" ,
2376+ lib_prefix , abi. version. major, abi. version. minor
23682377 ) )
23692378 } else {
2370- Ok ( format ! ( "python{}{}" , abi. version. major, abi. version. minor) )
2379+ Ok ( format ! (
2380+ "{}python{}{}" ,
2381+ lib_prefix, abi. version. major, abi. version. minor
2382+ ) )
23712383 }
23722384}
23732385
@@ -3290,7 +3302,7 @@ mod tests {
32903302 false ,
32913303 )
32923304 . unwrap( ) ,
3293- "python3 .9" ,
3305+ "libpython3 .9" ,
32943306 ) ;
32953307 assert_eq ! (
32963308 super :: default_lib_name_windows(
@@ -3302,7 +3314,7 @@ mod tests {
33023314 false ,
33033315 )
33043316 . unwrap( ) ,
3305- "python3 " ,
3317+ "libpython3 " ,
33063318 ) ;
33073319 assert_eq ! (
33083320 super :: default_lib_name_windows(
0 commit comments