From 9e2558bd563af31355d83471f628a5d02656cdac Mon Sep 17 00:00:00 2001 From: "John W. Parent" <45471568+johnwparent@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:20:04 -0400 Subject: [PATCH] Windows: add win-sdk/wgl externals during bootstrapping (#43459) On Windows, bootstrapping logic now searches for and adds the win-sdk and wgl packages to the user's top scope as externals if they are not present. These packages are generally required to install most packages with Spack on Windows, and are only available as externals, so it is assumed that doing this automatically would be useful and avoid a mandatory manual step for each new Spack instance. Note this is the first case of bootstrapping logic modifying configuration other than the bootstrap configuration. --- lib/spack/docs/getting_started.rst | 3 +++ lib/spack/spack/bootstrap/core.py | 37 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/spack/docs/getting_started.rst b/lib/spack/docs/getting_started.rst index ab9c274e01..25dfc95ee5 100644 --- a/lib/spack/docs/getting_started.rst +++ b/lib/spack/docs/getting_started.rst @@ -1572,6 +1572,8 @@ Microsoft Visual Studio """"""""""""""""""""""" Microsoft Visual Studio provides the only Windows C/C++ compiler that is currently supported by Spack. +Spack additionally requires that the Windows SDK (including WGL) to be installed as part of your +visual studio installation as it is required to build many packages from source. We require several specific components to be included in the Visual Studio installation. One is the C/C++ toolset, which can be selected as "Desktop development with C++" or "C++ build tools," @@ -1579,6 +1581,7 @@ depending on installation type (Professional, Build Tools, etc.) The other requ "C++ CMake tools for Windows," which can be selected from among the optional packages. This provides CMake and Ninja for use during Spack configuration. + If you already have Visual Studio installed, you can make sure these components are installed by rerunning the installer. Next to your installation, select "Modify" and look at the "Installation details" pane on the right. diff --git a/lib/spack/spack/bootstrap/core.py b/lib/spack/spack/bootstrap/core.py index 34aff29b55..62b82f8e27 100644 --- a/lib/spack/spack/bootstrap/core.py +++ b/lib/spack/spack/bootstrap/core.py @@ -559,12 +559,49 @@ def ensure_patchelf_in_path_or_raise() -> spack.util.executable.Executable: ) +def ensure_winsdk_external_or_raise() -> None: + """Ensure the Windows SDK + WGL are available on system + If both of these package are found, the Spack user or bootstrap + configuration (depending on where Spack is running) + will be updated to include all versions and variants detected. + If either the WDK or WSDK are not found, this method will raise + a RuntimeError. + + **NOTE:** This modifies the Spack config in the current scope, + either user or environment depending on the calling context. + This is different from all other current bootstrap dependency + checks. + """ + if set(["win-sdk", "wgl"]).issubset(spack.config.get("packages").keys()): + return + externals = spack.detection.by_path(["win-sdk", "wgl"]) + if not set(["win-sdk", "wgl"]) == externals.keys(): + missing_packages_lst = [] + if "wgl" not in externals: + missing_packages_lst.append("wgl") + if "win-sdk" not in externals: + missing_packages_lst.append("win-sdk") + missing_packages = " & ".join(missing_packages_lst) + raise RuntimeError( + f"Unable to find the {missing_packages}, please install these packages\ +via the Visual Studio installer\ +before proceeding with Spack or provide the path to a non standard install via\ +'spack external find --path'" + ) + # wgl/sdk are not required for bootstrapping Spack, but + # are required for building anything non trivial + # add to user config so they can be used by subsequent Spack ops + spack.detection.update_configuration(externals, buildable=False) + + def ensure_core_dependencies() -> None: """Ensure the presence of all the core dependencies.""" if sys.platform.lower() == "linux": ensure_patchelf_in_path_or_raise() if not IS_WINDOWS: ensure_gpg_in_path_or_raise() + else: + ensure_winsdk_external_or_raise() ensure_clingo_importable_or_raise()