@@ -2305,6 +2305,15 @@ fn default_lib_name_for_target(abi: PythonAbi, target: &Triple) -> String {
23052305}
23062306
23072307fn default_lib_name_windows ( abi : PythonAbi , mingw : bool , debug : bool ) -> Result < String > {
2308+ // mingw formats lib names like unix, and uses a "lib" prefix. We could let the linker
2309+ // handle "lib" prefix, but that means the `raw-dylib` name is incorrect (where the
2310+ // "lib" prefix is not automatically added).)
2311+ if mingw {
2312+ let mut lib_name = default_lib_name_unix ( abi, true , None ) ?;
2313+ lib_name. insert_str ( 0 , "lib" ) ;
2314+ return Ok ( lib_name) ;
2315+ }
2316+
23082317 if abi. implementation . is_pypy ( ) {
23092318 // PyPy on Windows ships `libpypy3.X-c.dll` (e.g. `libpypy3.11-c.dll`),
23102319 // not CPython's `pythonXY.dll`. With raw-dylib linking we need the real
@@ -2332,13 +2341,6 @@ fn default_lib_name_windows(abi: PythonAbi, mingw: bool, debug: bool) -> Result<
23322341 lib_name = lib_name. replace ( "python3" , "python3t" ) ;
23332342 }
23342343 Ok ( lib_name)
2335- } else if mingw {
2336- ensure ! (
2337- !abi. kind. is_free_threaded( ) ,
2338- "MinGW free-threaded builds are not currently tested or supported"
2339- ) ;
2340- // https://packages.msys2.org/base/mingw-w64-python
2341- Ok ( format ! ( "python{}.{}" , abi. version. major, abi. version. minor) )
23422344 } else if abi. kind ( ) . is_free_threaded ( ) {
23432345 #[ expect( deprecated, reason = "using constant internally" ) ]
23442346 {
@@ -2362,28 +2364,36 @@ fn default_lib_name_windows(abi: PythonAbi, mingw: bool, debug: bool) -> Result<
23622364 }
23632365}
23642366
2365- fn default_lib_name_unix ( abi : PythonAbi , cygwin : bool , ld_version : Option < & str > ) -> Result < String > {
2367+ fn default_lib_name_unix (
2368+ abi : PythonAbi ,
2369+ use_stable_abi_lib : bool ,
2370+ ld_version : Option < & str > ,
2371+ ) -> Result < String > {
23662372 match abi. implementation {
23672373 PythonImplementation :: CPython => match ld_version {
23682374 Some ( ld_version) => Ok ( format ! ( "python{ld_version}" ) ) ,
2369- None => {
2370- if cygwin && matches ! ( abi . kind , PythonAbiKind :: Stable ( StableAbi :: Abi3 ) ) {
2375+ None => match abi . kind {
2376+ PythonAbiKind :: Stable ( StableAbi :: Abi3 ) if use_stable_abi_lib => {
23712377 Ok ( "python3" . to_string ( ) )
2372- } else if cygwin && matches ! ( abi. kind, PythonAbiKind :: Stable ( StableAbi :: Abi3t ) ) {
2378+ }
2379+ PythonAbiKind :: Stable ( StableAbi :: Abi3t ) if use_stable_abi_lib => {
23732380 Ok ( "python3t" . to_string ( ) )
2374- } else if abi. kind . is_free_threaded ( ) {
2375- #[ expect( deprecated, reason = "using constant internally" ) ]
2376- {
2377- 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) ;
2381+ }
2382+ _ => {
2383+ if abi. kind . is_free_threaded ( ) {
2384+ #[ expect( deprecated, reason = "using constant internally" ) ]
2385+ {
2386+ 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) ;
2387+ }
2388+ Ok ( format ! (
2389+ "python{}.{}t" ,
2390+ abi. version. major, abi. version. minor
2391+ ) )
2392+ } else {
2393+ Ok ( format ! ( "python{}.{}" , abi. version. major, abi. version. minor) )
23782394 }
2379- Ok ( format ! (
2380- "python{}.{}t" ,
2381- abi. version. major, abi. version. minor
2382- ) )
2383- } else {
2384- Ok ( format ! ( "python{}.{}" , abi. version. major, abi. version. minor) )
23852395 }
2386- }
2396+ } ,
23872397 } ,
23882398 PythonImplementation :: PyPy => match ld_version {
23892399 Some ( ld_version) => Ok ( format ! ( "pypy{ld_version}-c" ) ) ,
0 commit comments