X Tutup
Skip to content

Commit 3a99403

Browse files
johnwparentscheibelp
authored andcommitted
Spack on Windows package ports
CMake - Windows Bootstrap (spack#25825) Remove hardcoded cmake compiler (spack#26410) Revert breaking cmake changes Ensure no autotools on Windows Perl on Windows (spack#26612) Python source build windows (spack#26313) Reconfigure sysconf for Windows Python2.6 compatibility Fxixup new sbang tests for windows Ruby support (spack#28287) Add NASM support (spack#28319) Add mock Ninja package for testing
1 parent 90c7734 commit 3a99403

File tree

27 files changed

+648
-199
lines changed

27 files changed

+648
-199
lines changed

bin/spack_cmd.bat

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ popd
1515

1616
:: Check if Python is on the PATH
1717
if not defined python_pf_ver (
18-
(for /f "delims=" %%F in ('where python.exe') do (set python_pf_ver=%%F) ) 2> NUL
18+
(for /f "delims=" %%F in ('where python.exe') do (
19+
set python_pf_ver=%%F
20+
goto :found_python
21+
) ) 2> NUL
1922
)
23+
:found_python
2024
if not defined python_pf_ver (
2125
:: If not, look for Python from the Spack installer
2226
:get_builtin
@@ -35,7 +39,7 @@ if not defined python_pf_ver (
3539
:: Python is already on the path
3640
set py_exe=!python_pf_ver!
3741
(for /F "tokens=* USEBACKQ" %%F in (
38-
`!py_exe! --version`) do (set "output=%%F")) 2>NUL
42+
`"!py_exe!" --version`) do (set "output=%%F")) 2>NUL
3943
if not "!output:Microsoft Store=!"=="!output!" goto :get_builtin
4044
goto :exitpoint
4145
)

lib/spack/docs/getting_started.rst

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,14 +1587,6 @@ When given the option of adjusting your ``PATH``, choose the ``Git from the
15871587
command line and also from 3rd-party software`` option. This will automatically
15881588
update your ``PATH`` variable to include the ``git`` command.
15891589

1590-
""""
1591-
Perl
1592-
""""
1593-
1594-
Perl is a flexible and feature-rich programming language that comes built-in
1595-
on Unix boxes but needs to be installed externally for Windows users. Fortunately,
1596-
you can find the most recent release at https://www.perl.org/get.html.
1597-
15981590
""""
15991591
NASM
16001592
""""

lib/spack/llnl/util/tty/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def process_stacktrace(countback):
146146
file_list = []
147147
for frame in st:
148148
# Check that the file is a spack file
149-
if frame[0].find("/spack") >= 0:
149+
if frame[0].find(os.path.sep + "spack") >= 0:
150150
file_list.append(frame[0])
151151
# We use commonprefix to find what the spack 'root' directory is.
152152
root_dir = os.path.commonprefix(file_list)

lib/spack/spack/build_environment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,9 @@ def _set_variables_for_single_module(pkg, module):
528528
m.cmake = Executable('cmake')
529529
m.ctest = MakeExecutable('ctest', jobs)
530530

531-
# Standard build system arguments
531+
if os.name == 'nt':
532+
m.nmake = Executable('nmake')
533+
# Standard CMake arguments
532534
m.std_cmake_args = spack.build_systems.cmake.CMakePackage._std_args(pkg)
533535
m.std_meson_args = spack.build_systems.meson.MesonPackage._std_args(pkg)
534536
m.std_pip_args = spack.build_systems.python.PythonPackage._std_args(pkg)

lib/spack/spack/build_systems/autotools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from llnl.util.filesystem import force_remove, working_dir
1515

1616
from spack.build_environment import InstallError
17-
from spack.directives import depends_on
17+
from spack.directives import conflicts, depends_on
1818
from spack.operating_systems.mac_os import macos_version
1919
from spack.package import PackageBase, run_after, run_before
2020
from spack.util.executable import Executable
@@ -104,6 +104,7 @@ def patch_config_files(self):
104104
depends_on('gnuconfig', type='build', when='target=ppc64le:')
105105
depends_on('gnuconfig', type='build', when='target=aarch64:')
106106
depends_on('gnuconfig', type='build', when='target=riscv64:')
107+
conflicts('platform=windows')
107108

108109
@property
109110
def _removed_la_files_log(self):

lib/spack/spack/build_systems/cmake.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,11 @@ class CMakePackage(PackageBase):
9393
#: See https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html
9494
#: for more information.
9595

96-
variant('generator',
97-
default='Make' if sys.platform != 'win32' else 'Ninja',
98-
description='Build system to generate',
99-
values=('Make', 'Ninja'))
96+
generator = "Unix Makefiles"
10097

101-
depends_on('ninja', when='generator=Ninja')
102-
103-
generatorMap = {'Make': 'Unix Makefiles',
104-
'Ninja': 'Ninja'}
98+
if sys.platform == 'win32':
99+
generator = "Ninja"
100+
depends_on('ninja')
105101

106102
# https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
107103
variant('build_type', default='RelWithDebInfo',
@@ -150,10 +146,10 @@ def _std_args(pkg):
150146
"""Computes the standard cmake arguments for a generic package"""
151147

152148
try:
153-
pkg.generator = pkg.spec.variants['generator'].value
154-
except KeyError:
155-
pkg.generator = 'Make' if sys.platform != 'win32' else 'Ninja'
156-
primary_generator = CMakePackage.generatorMap[pkg.generator]
149+
if not pkg.generator:
150+
raise AttributeError
151+
except AttributeError:
152+
pkg.generator = CMakePackage.generator
157153

158154
try:
159155
build_type = pkg.spec.variants['build_type'].value
@@ -167,22 +163,16 @@ def _std_args(pkg):
167163

168164
define = CMakePackage.define
169165
args = [
170-
'-G', primary_generator,
166+
'-G', pkg.generator,
171167
define('CMAKE_INSTALL_PREFIX', pkg.prefix.replace('\\', '/')),
172168
define('CMAKE_BUILD_TYPE', build_type),
173-
define('CMAKE_C_COMPILER:FILEPATH', pkg.compiler.cc.replace('\\', '/')),
174-
define('CMAKE_CXX_COMPILER:FILEPATH', pkg.compiler.cxx.replace('\\', '/'))
175169
]
176170

177-
if pkg.compiler.fc is not None:
178-
args.append(define('CMAKE_Fortran_COMPILER:FILEPATH',
179-
pkg.compiler.fc.replace('\\', '/')))
180-
181171
# CMAKE_INTERPROCEDURAL_OPTIMIZATION only exists for CMake >= 3.9
182172
if pkg.spec.satisfies('^cmake@3.9:'):
183173
args.append(define('CMAKE_INTERPROCEDURAL_OPTIMIZATION', ipo))
184174

185-
if primary_generator == 'Unix Makefiles':
175+
if pkg.generator == 'Unix Makefiles':
186176
args.append(define('CMAKE_VERBOSE_MAKEFILE', True))
187177

188178
if platform.mac_ver()[0]:

lib/spack/spack/cmd/unit_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def colorize(c, prefix):
130130
# in the future - so this manipulation might be fragile
131131
if nodetype.lower() == 'function':
132132
name_parts.append(item)
133-
key_end = os.path.join(*[x[1] for x in key_parts])
133+
key_end = os.path.join(*key_parts[-1][1].split('/'))
134134
key = next(f for f in files if f.endswith(key_end))
135135
tests[key].add(tuple(x[1] for x in name_parts))
136136
elif nodetype.lower() == 'class':

lib/spack/spack/compilers/msvc.py

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,37 @@
44
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
55

66
import os
7+
import re
78
import subprocess
89
import sys
9-
from typing import List # novm
10+
from distutils.version import StrictVersion
11+
from typing import Dict, List, Set # novm
1012

1113
import spack.operating_systems.windows_os
1214
import spack.util.executable
1315
from spack.compiler import Compiler
16+
from spack.error import SpackError
17+
18+
avail_fc_version = set() # type: Set[str]
19+
fc_path = dict() # type: Dict[str, str]
20+
21+
fortran_mapping = {
22+
'2021.3.0': '19.29.30133',
23+
'2021.2.1': '19.28.29913',
24+
'2021.2.0': '19.28.29334',
25+
'2021.1.0': '19.28.29333',
26+
}
27+
28+
29+
def get_valid_fortran_pth(comp_ver):
30+
cl_ver = str(comp_ver).split('@')[1]
31+
sort_fn = lambda fc_ver: StrictVersion(fc_ver)
32+
sort_fc_ver = sorted(list(avail_fc_version), key=sort_fn)
33+
for ver in sort_fc_ver:
34+
if ver in fortran_mapping:
35+
if StrictVersion(cl_ver) <= StrictVersion(fortran_mapping[ver]):
36+
return fc_path[ver]
37+
return None
1438

1539

1640
class Msvc(Compiler):
@@ -46,6 +70,8 @@ class Msvc(Compiler):
4670
# file based on compiler executable path.
4771

4872
def __init__(self, *args, **kwargs):
73+
new_pth = [pth if pth else get_valid_fortran_pth(args[0]) for pth in args[3]]
74+
args[3][:] = new_pth
4975
super(Msvc, self).__init__(*args, **kwargs)
5076
if os.getenv("ONEAPI_ROOT"):
5177
# If this found, it sets all the vars
@@ -65,6 +91,12 @@ def verbose_flag(self):
6591
def pic_flag(self):
6692
return ""
6793

94+
@property
95+
def msvc_version(self):
96+
ver = re.search(Msvc.version_regex, self.cc).group(1)
97+
ver = "".join(ver.split('.')[:2])[:-1]
98+
return "MSVC" + ver
99+
68100
def setup_custom_environment(self, pkg, env):
69101
"""Set environment variables for MSVC using the
70102
Microsoft-provided script."""
@@ -81,44 +113,40 @@ def setup_custom_environment(self, pkg, env):
81113
if sys.version_info[0] >= 3:
82114
out = out.decode('utf-16le', errors='replace') # novermin
83115

84-
int_env = { # novermin
85-
key.lower(): value
86-
for key, _, value in
87-
(line.partition('=') for line in out.splitlines())
88-
if key and value
89-
}
116+
int_env = dict((key.lower(), value) for key, _, value in
117+
(line.partition('=') for line in out.splitlines())
118+
if key and value)
90119

91120
if 'path' in int_env:
92121
env.set_path('PATH', int_env['path'].split(';'))
93122
env.set_path('INCLUDE', int_env.get('include', '').split(';'))
94123
env.set_path('LIB', int_env.get('lib', '').split(';'))
124+
125+
env.set('CC', self.cc)
126+
env.set('CXX', self.cxx)
127+
env.set('FC', self.fc)
128+
env.set('F77', self.f77)
95129
else:
96130
# Should not this be an exception?
97131
print("Cannot pull msvc compiler information in Python 2.6 or below")
98132

99-
# fc_version only loads the ifx compiler into the first MSVC stanza;
100-
# if there are other versions of Microsoft VS installed and detected, they
101-
# will only have cl.exe as the C/C++ compiler
102-
103133
@classmethod
104134
def fc_version(cls, fc):
105135
# We're using intel for the Fortran compilers, which exist if
106136
# ONEAPI_ROOT is a meaningful variable
137+
fc_ver = cls.default_version(fc)
138+
avail_fc_version.add(fc_ver)
139+
fc_path[fc_ver] = fc
107140
if os.getenv("ONEAPI_ROOT"):
108141
try:
109142
sps = spack.operating_systems.windows_os.WindowsOs.compiler_search_paths
110-
except Exception:
111-
print("sps not found.")
112-
raise
113-
try:
114-
clp = spack.util.executable.which_string("cl", path=sps)
115-
except Exception:
116-
print("cl not found.")
117-
raise
143+
except AttributeError:
144+
raise SpackError("Windows compiler search paths not established")
145+
clp = spack.util.executable.which_string("cl", path=sps)
118146
ver = cls.default_version(clp)
119-
return ver
120147
else:
121-
return cls.default_version(fc)
148+
ver = fc_ver
149+
return ver
122150

123151
@classmethod
124152
def f77_version(cls, f77):

lib/spack/spack/detection/path.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import sys
1313
import warnings
1414

15-
1615
import llnl.util.filesystem
1716
import llnl.util.tty
1817

lib/spack/spack/fetch_strategy.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,9 @@ def _existing_url(self, url):
353353
# Telling urllib to check if url is accessible
354354
try:
355355
url, headers, response = spack.util.web.read_from_url(url)
356-
except spack.util.web.SpackWebError:
357-
msg = "Urllib fetch failed to verify url {0}".format(url)
356+
except spack.util.web.SpackWebError as werr:
357+
msg = "Urllib fetch failed to verify url\
358+
{0}\n with error {1}".format(url, werr)
358359
raise FailedDownloadError(url, msg)
359360
return (response.getcode() is None or response.getcode() == 200)
360361

0 commit comments

Comments
 (0)
X Tutup