@@ -454,3 +454,82 @@ def test_base_list_not_mutated(self):
454454 # Base list should not be modified
455455 assert library .include_dirs == ["common" ]
456456 assert library .include_dirs_linux == ["linux" ]
457+
458+
459+ class TestMSVCPythonLibsPath :
460+ """Tests for MSVC Python libs path discovery."""
461+
462+ def test_msvc_link_flags_include_libpath (self ):
463+ """Test that MSVC link flags include /LIBPATH for Python libs."""
464+ library = HatchCppLibrary (
465+ name = "test" ,
466+ sources = ["test.cpp" ],
467+ binding = "generic" , # Skip Python.h include
468+ )
469+
470+ platform = HatchCppPlatform (
471+ cc = "cl" ,
472+ cxx = "cl" ,
473+ ld = "link" ,
474+ platform = "win32" ,
475+ toolchain = "msvc" ,
476+ disable_ccache = True ,
477+ )
478+
479+ flags = platform .get_link_flags (library )
480+ # Should have /link /DLL flags
481+ assert "/link" in flags
482+ assert "/DLL" in flags
483+ # Should have output file
484+ assert "/Fe:" in flags
485+
486+ def test_msvc_link_flags_with_libraries (self ):
487+ """Test that MSVC link flags properly format library names."""
488+ library = HatchCppLibrary (
489+ name = "test" ,
490+ sources = ["test.cpp" ],
491+ binding = "generic" ,
492+ libraries = ["mylib" ],
493+ library_dirs = ["path/to/libs" ],
494+ )
495+
496+ platform = HatchCppPlatform (
497+ cc = "cl" ,
498+ cxx = "cl" ,
499+ ld = "link" ,
500+ platform = "win32" ,
501+ toolchain = "msvc" ,
502+ disable_ccache = True ,
503+ )
504+
505+ flags = platform .get_link_flags (library )
506+ # Libraries should have .lib suffix on Windows
507+ assert "mylib.lib" in flags
508+ # Library dirs should use /LIBPATH:
509+ assert "/LIBPATH:path/to/libs" in flags
510+
511+ def test_msvc_link_flags_with_platform_specific_libraries (self ):
512+ """Test that MSVC uses win32-specific libraries."""
513+ library = HatchCppLibrary (
514+ name = "test" ,
515+ sources = ["test.cpp" ],
516+ binding = "generic" ,
517+ libraries = ["common" ],
518+ libraries_win32 = ["kernel32" , "user32" ],
519+ library_dirs_win32 = ["C:/Windows/System32" ],
520+ )
521+
522+ platform = HatchCppPlatform (
523+ cc = "cl" ,
524+ cxx = "cl" ,
525+ ld = "link" ,
526+ platform = "win32" ,
527+ toolchain = "msvc" ,
528+ disable_ccache = True ,
529+ )
530+
531+ flags = platform .get_link_flags (library )
532+ assert "common.lib" in flags
533+ assert "kernel32.lib" in flags
534+ assert "user32.lib" in flags
535+ assert "/LIBPATH:C:/Windows/System32" in flags
0 commit comments