Skip to content

Commit 36e84e2

Browse files
authored
Merge pull request #142 from python-project-templates/test-on-macos-and-windows
Run tests on macOS and Windows and fix the Windows failures
2 parents c442d47 + 47cf71c commit 36e84e2

6 files changed

Lines changed: 38 additions & 11 deletions

File tree

‎.github/workflows/build.yaml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ jobs:
2828
runs-on: ${{ matrix.os }}
2929

3030
strategy:
31+
fail-fast: false
3132
matrix:
3233
os: [ubuntu-24.04]
3334
python-version: ["3.11", "3.12", "3.13"]
35+
include:
36+
- os: macos-26
37+
python-version: "3.11"
38+
- os: windows-2025
39+
python-version: "3.11"
3440

3541
steps:
3642
- name: Checkout
@@ -43,14 +49,22 @@ jobs:
4349
with:
4450
version: ${{ matrix.python-version }}
4551

52+
- name: Setup C++
53+
uses: actions-ext/cpp/setup@7de57593fbcba72d513072bfb4b30b5a344aa547
54+
with:
55+
cache: 'false'
56+
clang_format: 'false'
57+
4658
- name: Install dependencies
4759
run: make develop
4860

4961
- name: Lint
5062
run: make lint
63+
if: runner.os == 'Linux'
5164

5265
- name: Checks
5366
run: make checks
67+
if: runner.os == 'Linux'
5468

5569
- name: Build
5670
run: make build
@@ -69,6 +83,7 @@ jobs:
6983
uses: EnricoMi/publish-unit-test-result-action@7622c5bf3d112a72ab4fa3951c2aa5723d8ab92d # v2.25.0
7084
with:
7185
files: '**/junit.xml'
86+
if: runner.os == 'Linux'
7287

7388
- name: Upload coverage
7489
uses: codecov/codecov-action@303a32d7a59b442fa8d48b6a1cc6825c09c847a5 # v7.1.1

‎hatch_cpp/config.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def generate(self):
197197
if self.platform.platform == "emscripten":
198198
objects = []
199199
for source_index, source in enumerate(library.sources):
200-
obj = Path("build/hatch-cpp") / f"{library_index}-{source_index}-{Path(source).stem}.o"
201-
objects.append(str(obj))
200+
obj = f"build/hatch-cpp/{library_index}-{source_index}-{Path(source).stem}.o"
201+
objects.append(obj)
202202
self.commands.append(f"{compiler} -c {source} {compile_flags} -o {obj}")
203203
self.commands.append(f"{compiler} {' '.join(objects)} {link_flags}")
204204
else:

‎hatch_cpp/tests/test_projects.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ class TestProject:
1515
[
1616
"test_project_basic",
1717
"test_project_override_classes",
18-
"test_project_override_toolchain",
18+
pytest.param(
19+
"test_project_override_toolchain",
20+
marks=pytest.mark.skipif(
21+
platform == "win32", reason="the fixture selects the gcc toolchain, whose flags clang rejects for MSVC targets"
22+
),
23+
),
1924
"test_project_pybind",
2025
"test_project_pybind_vcpkg",
2126
"test_project_nanobind",

‎hatch_cpp/tests/test_vcpkg_ref.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ def _make_vcpkg_env(self, tmp_path):
125125
"""Create a minimal vcpkg.json so generate() produces commands."""
126126
(tmp_path / "vcpkg.json").write_text("{}")
127127

128+
def _pin_linux_host(self, monkeypatch):
129+
"""Make generate() behave as on an x86_64 Linux host, whatever host runs the test."""
130+
monkeypatch.setattr("hatch_cpp.toolchains.vcpkg.sys_platform", "linux")
131+
monkeypatch.setattr("hatch_cpp.toolchains.vcpkg.platform_machine", lambda: "x86_64")
132+
128133
def test_generate_with_explicit_ref(self, tmp_path, monkeypatch):
129134
monkeypatch.chdir(tmp_path)
130135
self._make_vcpkg_env(tmp_path)
@@ -164,6 +169,7 @@ def test_generate_without_ref(self, tmp_path, monkeypatch):
164169

165170
def test_generate_uses_posix_command_paths(self, tmp_path, monkeypatch):
166171
monkeypatch.chdir(tmp_path)
172+
self._pin_linux_host(monkeypatch)
167173
self._make_vcpkg_env(tmp_path)
168174

169175
cfg = HatchCppVcpkgConfiguration(vcpkg_triplet="x64-linux")
@@ -185,6 +191,7 @@ def test_generate_detects_linux_arm64_triplet(self, tmp_path, monkeypatch):
185191

186192
def test_generate_detects_emscripten_triplet(self, tmp_path, monkeypatch):
187193
monkeypatch.chdir(tmp_path)
194+
self._pin_linux_host(monkeypatch)
188195
self._make_vcpkg_env(tmp_path)
189196
build_plan = SimpleNamespace(platform=SimpleNamespace(platform="emscripten"))
190197

@@ -206,6 +213,7 @@ def test_generate_uses_windows_command_paths(self, tmp_path, monkeypatch):
206213

207214
def test_generate_skips_clone_when_vcpkg_root_exists(self, tmp_path, monkeypatch):
208215
monkeypatch.chdir(tmp_path)
216+
self._pin_linux_host(monkeypatch)
209217
self._make_vcpkg_env(tmp_path)
210218
vcpkg_root = tmp_path / "vcpkg"
211219
vcpkg_root.mkdir()
@@ -225,6 +233,7 @@ def test_generate_skips_clone_when_vcpkg_root_exists(self, tmp_path, monkeypatch
225233

226234
def test_generate_reclones_when_vcpkg_root_exists_but_empty(self, tmp_path, monkeypatch):
227235
monkeypatch.chdir(tmp_path)
236+
self._pin_linux_host(monkeypatch)
228237
self._make_vcpkg_env(tmp_path)
229238
(tmp_path / "vcpkg").mkdir()
230239

@@ -253,6 +262,7 @@ def test_generate_bootstraps_when_vcpkg_executable_missing(self, tmp_path, monke
253262

254263
def test_generate_reclones_when_vcpkg_exists_but_not_working(self, tmp_path, monkeypatch):
255264
monkeypatch.chdir(tmp_path)
265+
self._pin_linux_host(monkeypatch)
256266
self._make_vcpkg_env(tmp_path)
257267
vcpkg_root = tmp_path / "vcpkg"
258268
vcpkg_root.mkdir()

‎hatch_cpp/toolchains/cmake.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,10 @@ def generate(self, config) -> list[str]:
5454
commands[-1] += f" -DCMAKE_INSTALL_PREFIX={Path(self.root).parent}"
5555

5656
# TODO: CMAKE_CXX_COMPILER
57-
# Respect CMAKE_GENERATOR environment variable
57+
# Respect CMAKE_GENERATOR environment variable. Without it CMake picks its default,
58+
# which on Windows is the newest installed Visual Studio.
5859
cmake_generator = environ.get("CMAKE_GENERATOR", "")
59-
if config.platform.platform == "win32":
60-
if not cmake_generator:
61-
cmake_generator = "Visual Studio 17 2022"
62-
commands[-1] += f' -G "{cmake_generator}"'
63-
elif cmake_generator:
60+
if cmake_generator:
6461
commands[-1] += f' -G "{cmake_generator}"'
6562

6663
# Put in CMake flags

‎hatch_cpp/toolchains/vcpkg.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _read_vcpkg_ref_from_gitmodules(vcpkg_root: Path) -> str | None:
5757
parser.read(str(gitmodules_path))
5858

5959
for section in parser.sections():
60-
if parser.get(section, "path", fallback=None) == str(vcpkg_root):
60+
if parser.get(section, "path", fallback=None) == vcpkg_root.as_posix():
6161
return parser.get(section, "branch", fallback=None)
6262

6363
return None
@@ -93,7 +93,7 @@ def _vcpkg_executable_path(self) -> Path:
9393
def _command_path(self, path: Path) -> str:
9494
if sys_platform == "win32":
9595
return str(path).replace("/", "\\")
96-
return f"./{path}"
96+
return f"./{path.as_posix()}"
9797

9898
def _delete_dir_command(self, path: Path) -> str:
9999
if sys_platform == "win32":

0 commit comments

Comments
 (0)