Skip to content

Improve vswhere use to avoid boiling the ocean while looking for cl.exe #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install project & dependencies
shell: bash
run: pip install .[dev]

- name: Test
shell: bash
run: |
set -uexo pipefail
python -m venv venv
source venv/bin/activate
pip install .[dev]
pytest ./test
run: pytest ./test

test-windows:
name: Test Windows
Expand All @@ -57,8 +56,10 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install project & dependencies
shell: powershell
run: pip install '.[dev]'

- name: Test
shell: powershell
run: |
pip install '.[dev]'
pytest ./test
run: pytest ./test
27 changes: 20 additions & 7 deletions autopxd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
import os
import platform
import re
Expand Down Expand Up @@ -52,23 +51,37 @@ def _find_cl():
"ARM64": "arm64",
}.get(platform.machine(), "x86")
program_files = os.getenv("ProgramFiles(x86)") or os.getenv("ProgramFiles")

if build_platform in ("x86", "x64"):
# Note the `x86.x64` here not related to cross compilation, but just
# poor naming of something which should have been called `x86_or_x64`.
require = "Microsoft.VisualStudio.Component.VC.Tools.x86.x64"
else:
assert build_platform == "arm64"
require = "Microsoft.VisualStudio.Component.VC.Tools.ARM64"

cmd = [
os.path.join(program_files, r"Microsoft Visual Studio\Installer\vswhere.exe"),
"-prerelease",
"-latest",
"-products",
"*",
"-format",
"json",
"-requires",
require,
"-property",
"installationPath",
"-utf8",
"-find",
rf"**\bin\Host{host_platform}\{build_platform}\cl.exe",
]
try:
return json.loads(subprocess.check_output(cmd, encoding="utf-8"))[-1]
except (OSError, subprocess.CalledProcessError, IndexError) as ex:
install_dir = subprocess.check_output(cmd, encoding="utf-8").strip()
except subprocess.CalledProcessError as ex:
raise RuntimeError("No suitable compiler available") from ex

with open(rf"{install_dir}\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt", encoding="ascii") as fd:
default_version = fd.read().strip()

return rf"{install_dir}\VC\Tools\MSVC\{default_version}\bin\Host{host_platform}\{build_platform}\cl.exe"


def _preprocess_msvc(code, extra_cpp_args, debug):
fd, source_file = tempfile.mkstemp(suffix=".c")
Expand Down