From 4ff8a6a9b703002db9f1c5a949a4b00c4978363d Mon Sep 17 00:00:00 2001 From: 百地 希留耶 <65301509+KiruyaMomochi@users.noreply.github.com> Date: Thu, 27 Oct 2022 04:45:35 +0800 Subject: Windows: fix bootstrap and package install failure (#32942) * Add patches for building clingo with MSVC * Help python find clingo DLL * If an executable is located in "C:\Program Files", Executable was running into issues with the extra space. This quotes the exe to ensure that it is treated as a single value. Signed-off-by: Kiruya Momochi <65301509+KiruyaMomochi@users.noreply.github.com> --- lib/spack/spack/bootstrap.py | 8 ++++++++ lib/spack/spack/util/executable.py | 3 ++- var/spack/repos/builtin/packages/clingo/package.py | 2 ++ .../repos/builtin/packages/clingo/size-t.patch | 22 ++++++++++++++++++++++ .../repos/builtin/packages/clingo/vs2022.patch | 18 ++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 var/spack/repos/builtin/packages/clingo/size-t.patch create mode 100644 var/spack/repos/builtin/packages/clingo/vs2022.patch diff --git a/lib/spack/spack/bootstrap.py b/lib/spack/spack/bootstrap.py index 2e0f2614e7..d92609fdcd 100644 --- a/lib/spack/spack/bootstrap.py +++ b/lib/spack/spack/bootstrap.py @@ -91,6 +91,14 @@ def _try_import_from_store(module, query_spec, query_info=None): os.path.join(candidate_spec.prefix, pkg.platlib), ] # type: list[str] path_before = list(sys.path) + + # Python 3.8+ on Windows does not search dependent DLLs in PATH, + # so we need to manually add it using os.add_dll_directory + # https://docs.python.org/3/whatsnew/3.8.html#bpo-36085-whatsnew + if sys.version_info[:2] >= (3, 8) and sys.platform == "win32": + if os.path.isdir(candidate_spec.prefix.bin): + os.add_dll_directory(candidate_spec.prefix.bin) # novermin + # NOTE: try module_paths first and last, last allows an existing version in path # to be picked up and used, possibly depending on something in the store, first # allows the bootstrap version to work when an incompatible version is in diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py index cd8ddef6de..6160b95266 100644 --- a/lib/spack/spack/util/executable.py +++ b/lib/spack/spack/util/executable.py @@ -10,6 +10,7 @@ import subprocess import sys from six import string_types, text_type +from six.moves import shlex_quote import llnl.util.tty as tty @@ -333,7 +334,7 @@ def which(*args, **kwargs): Executable: The first executable that is found in the path """ exe = which_string(*args, **kwargs) - return Executable(exe) if exe else None + return Executable(shlex_quote(exe)) if exe else None class ProcessError(spack.error.SpackError): diff --git a/var/spack/repos/builtin/packages/clingo/package.py b/var/spack/repos/builtin/packages/clingo/package.py index be477fdf5b..a3d39d8e62 100644 --- a/var/spack/repos/builtin/packages/clingo/package.py +++ b/var/spack/repos/builtin/packages/clingo/package.py @@ -64,6 +64,8 @@ class Clingo(CMakePackage): depends_on("py-cffi", type=("build", "run"), when="@5.5.0: platform=cray") patch("python38.patch", when="@5.3:5.4.0") + patch("size-t.patch", when="%msvc") + patch("vs2022.patch", when="%msvc@19.30:") def patch(self): # Doxygen is optional but can't be disabled with a -D, so patch diff --git a/var/spack/repos/builtin/packages/clingo/size-t.patch b/var/spack/repos/builtin/packages/clingo/size-t.patch new file mode 100644 index 0000000000..52f7db2062 --- /dev/null +++ b/var/spack/repos/builtin/packages/clingo/size-t.patch @@ -0,0 +1,22 @@ +diff --git a/libpyclingo/pyclingo.cc b/libpyclingo/pyclingo.cc +index ec4a33c..88b6669 100644 +--- a/libpyclingo/pyclingo.cc ++++ b/libpyclingo/pyclingo.cc +@@ -116,7 +116,7 @@ struct ObjectProtocoll { + Object call(char const *name, Args &&... args); + template + Object operator()(Args &&... args); +- ssize_t size(); ++ Py_ssize_t size(); + bool empty() { return size() == 0; } + Object getItem(Reference o); + Object getItem(char const *key); +@@ -232,7 +232,7 @@ Object ObjectProtocoll::operator()(Args &&... args) { + return PyObject_CallFunctionObjArgs(toPy_(), Reference(args).toPy()..., nullptr); + } + template +-ssize_t ObjectProtocoll::size() { ++Py_ssize_t ObjectProtocoll::size() { + auto ret = PyObject_Size(toPy_()); + if (PyErr_Occurred()) { throw PyException(); } + return ret; diff --git a/var/spack/repos/builtin/packages/clingo/vs2022.patch b/var/spack/repos/builtin/packages/clingo/vs2022.patch new file mode 100644 index 0000000000..8a27fc8679 --- /dev/null +++ b/var/spack/repos/builtin/packages/clingo/vs2022.patch @@ -0,0 +1,18 @@ +diff --git a/libpyclingo/pyclingo.cc b/libpyclingo/pyclingo.cc +index 88b6669..58e73bd 100644 +--- a/libpyclingo/pyclingo.cc ++++ b/libpyclingo/pyclingo.cc +@@ -25,6 +25,13 @@ + // NOTE: the python header has a linker pragma to link with python_d.lib + // when _DEBUG is set which is not part of official python releases + #if defined(_MSC_VER) && defined(_DEBUG) && !defined(CLINGO_UNDEF__DEBUG) ++// Workaround for a VS 2022 issue. ++// NOTE: This workaround knowingly violates the Python.h include order requirement: ++// https://docs.python.org/3/c-api/intro.html#include-files ++# include ++# if _MSVC_STL_VERSION >= 143 ++# include ++# endif + #undef _DEBUG + #include + #define _DEBUG -- cgit v1.2.3-70-g09d2