indygreg / python-build-standalone

Produce redistributable builds of Python
BSD 3-Clause "New" or "Revised" License
1.71k stars 107 forks source link

Fails to build on Win 11 with Preview visual studio #268

Open kfsone opened 3 weeks ago

kfsone commented 3 weeks ago

Command line:

py.exe build-windows.py --profile noopt --vs 2022 --python cpython-3.12 --sh c:\cygwin64\bin\bash.exe

downloads strawberry perl, process libffi, and then fails with the obtuse: VC\Auxiliary\Build\vcvarsall.bat not found.

This appears to be two fold:

1- the result of the subcommand in find_vs_path is not checked for emptiness, 2- the command is not passing the "-prerelease" option to vswhere,

An easy fix would be:

diff --git a/cpython-windows/build.py b/cpython-windows/build.py
index bc97cd5..66ff6a1 100644
--- a/cpython-windows/build.py
+++ b/cpython-windows/build.py
@@ -233,18 +233,22 @@ def find_vs_path(path, msvc_version):
     else:
         raise ValueError(f"unsupported Visual Studio version: {msvc_version}")

-    p = subprocess.check_output(
-        [
-            str(vswhere),
-            # Visual Studio 2019.
-            "-version",
-            version,
-            "-property",
-            "installationPath",
-            "-products",
-            "*",
-        ]
-    )
+    cmdline = [
+        str(vswhere),
+        # Visual Studio 2019.
+        "-version",
+        version,
+        "-property",
+        "installationPath",
+        "-prerelease",
+        "-products",
+        "*",
+    ]
+    p = subprocess.check_output(cmdline)
+    if not p:
+        cmd = ' '.join('"%s"' % i for i in cmdline)
+        print("could not find visual studio (using '%s')" % cmd)
+        sys.exit(1)

But I suspect this would kick the can down the road to an additional problem if you had vs2022 and vs2022 preview installed.