hatch-cpp 0.3.1__py3-none-any.whl → 0.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hatch_cpp/__init__.py CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "0.3.1"
1
+ __version__ = "0.3.2"
2
2
 
3
3
  from .config import *
4
4
  from .hooks import *
@@ -454,3 +454,82 @@ class TestPlatformFieldOrdering:
454
454
  # Base list should not be modified
455
455
  assert library.include_dirs == ["common"]
456
456
  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
@@ -5,7 +5,7 @@ from pathlib import Path
5
5
  from re import match
6
6
  from shutil import which
7
7
  from sys import executable, platform as sys_platform
8
- from sysconfig import get_path
8
+ from sysconfig import get_config_var, get_path
9
9
  from typing import Any, List, Literal, Optional
10
10
 
11
11
  from pydantic import AliasChoices, BaseModel, Field, field_validator, model_validator
@@ -368,8 +368,16 @@ class HatchCppPlatform(BaseModel):
368
368
  flags += " /LD"
369
369
  flags += f" /Fe:{library.get_qualified_name(self.platform)}"
370
370
  flags += " /link /DLL"
371
- if (Path(executable).parent / "libs").exists():
372
- flags += f" /LIBPATH:{str(Path(executable).parent / 'libs')}"
371
+ # Add Python libs directory - check multiple possible locations
372
+ python_libs_paths = [
373
+ Path(executable).parent / "libs", # Standard Python install
374
+ Path(executable).parent.parent / "libs", # Some virtualenv layouts
375
+ Path(get_config_var("installed_base") or "") / "libs", # sysconfig approach
376
+ ]
377
+ for libs_path in python_libs_paths:
378
+ if libs_path.exists():
379
+ flags += f" /LIBPATH:{str(libs_path)}"
380
+ break
373
381
  flags += " " + " ".join(f"{lib}.lib" for lib in effective_libraries)
374
382
  flags += " " + " ".join(f"/LIBPATH:{lib}" for lib in effective_library_dirs)
375
383
  # clean
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hatch-cpp
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
4
  Summary: Hatch plugin for C++ builds
5
5
  Project-URL: Repository, https://github.com/python-project-templates/hatch-cpp
6
6
  Project-URL: Homepage, https://github.com/python-project-templates/hatch-cpp
@@ -1,10 +1,10 @@
1
- hatch_cpp/__init__.py,sha256=NiHzyZHO9thWWlAsLinBL03KdZwgTXAKh3yDMnAIKRs,114
1
+ hatch_cpp/__init__.py,sha256=80s2OK7mGLMGyDOX66_Zwq0K3j37suMBwllbXaq_crU,114
2
2
  hatch_cpp/config.py,sha256=LlwDBmD1nir08Y5GOl4wa29h2iJBtNRSzYMGHRVFJUo,3698
3
3
  hatch_cpp/hooks.py,sha256=SQkF5WJIgzw-8rvlTzuQvBqdP6K3fHgnh6CZOZFag50,203
4
4
  hatch_cpp/plugin.py,sha256=NcIDi7c9KH-_RkPeeCgWKoH5InIjw2eECswazwvGl_c,4304
5
5
  hatch_cpp/utils.py,sha256=lxd3U3aMYsTS6DYMc1y17MR16LzgRzv92f_xh87LSg8,297
6
6
  hatch_cpp/tests/test_hatch_build.py,sha256=q2IKTFi3Pq99UsOyL84V-C9VtFUs3ZcA9UlA8lpRW54,1553
7
- hatch_cpp/tests/test_platform_specific.py,sha256=UaqYFoKfdxNG5p4ZlPsCJE50LB8HzzgVDRlYG03YHQM,17722
7
+ hatch_cpp/tests/test_platform_specific.py,sha256=8EFHEv86e0CD1bIruHgLb28yf2pSRF1VgvcX2tK5bRo,20124
8
8
  hatch_cpp/tests/test_projects.py,sha256=vs-kHdiHM7pCqM3oGQsSryq5blRi0HyK5QFfHxlJDi8,1773
9
9
  hatch_cpp/tests/test_structs.py,sha256=cpzbPLneEbEONzXmPS1S9PL9mbhya4udc4eqTpU9w6w,2576
10
10
  hatch_cpp/tests/test_project_basic/pyproject.toml,sha256=eqM1UVpNmJWDfsuO18ZG_VOV9I4tAWgsM5Dhf49X8Nc,694
@@ -57,10 +57,10 @@ hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.hpp,sha256=LZSfCfhLY
57
57
  hatch_cpp/tests/test_project_pybind_vcpkg/project/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
58
  hatch_cpp/toolchains/__init__.py,sha256=anza4tXKxauobWMOUrxX3sEO0qs7sp6VdLXhLae3vkY,64
59
59
  hatch_cpp/toolchains/cmake.py,sha256=VQYYqiOu0ZEF0IBuep35Xad7jryWy04-dHYYf7c0XgY,3331
60
- hatch_cpp/toolchains/common.py,sha256=a8Pp6K5ykR04ZGXirQGx-xDw9xFm65O2sqrZpUlUqws,18165
60
+ hatch_cpp/toolchains/common.py,sha256=fSb6rTCmDbu9mrmB01qo6KnqTV42IPYbuF2betGjBvI,18593
61
61
  hatch_cpp/toolchains/vcpkg.py,sha256=Gwv3YNXBngpdebvRuYuUcWCzPyDbmDvy8c0K7uV4k38,2146
62
- hatch_cpp-0.3.1.dist-info/METADATA,sha256=elXaQLudW-BbNb0B0ZL1YCbMCr39d7GpZUaSQRB_I40,9896
63
- hatch_cpp-0.3.1.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
64
- hatch_cpp-0.3.1.dist-info/entry_points.txt,sha256=RgXfjpD4iwomJQK5n7FnPkXzb5fOnF5v3DI5hbkgVcw,30
65
- hatch_cpp-0.3.1.dist-info/licenses/LICENSE,sha256=FWyFTpd5xXEz50QpGDtsyIv6dgR2z_dHdoab_Nq_KMw,11452
66
- hatch_cpp-0.3.1.dist-info/RECORD,,
62
+ hatch_cpp-0.3.2.dist-info/METADATA,sha256=r1F7u1r__2y464NTdBPPsTxvVQlFRnijdRTbvxrxx50,9896
63
+ hatch_cpp-0.3.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
64
+ hatch_cpp-0.3.2.dist-info/entry_points.txt,sha256=RgXfjpD4iwomJQK5n7FnPkXzb5fOnF5v3DI5hbkgVcw,30
65
+ hatch_cpp-0.3.2.dist-info/licenses/LICENSE,sha256=FWyFTpd5xXEz50QpGDtsyIv6dgR2z_dHdoab_Nq_KMw,11452
66
+ hatch_cpp-0.3.2.dist-info/RECORD,,