From 15ef85e161f84ae199ee773732b230ccafc665c7 Mon Sep 17 00:00:00 2001 From: Jared Popelar Date: Mon, 17 May 2021 14:56:42 -0600 Subject: Packaging of netlib-lapack for windows (#24993) MSVC's internal CMake and Ninja now detected by spack external find and added to packages.yaml Saving progress on packaging zlib for Windows Fixing the shared CMake flag * Loading Intel's ifx Fortran compiler into MSVC; if there are multiple versions of MSVC installed and detected, ifx will only be placed into the first block written in compilers.yaml. The version number of ifx can be detected using MSVC's version flag (instead of /QV) by using ignore_version_errors. This commit also provides support for detection of Intel compilers in their own compiler block by adding ifx.exe to the fc/f77_name blocks inside intel.py * Giving CMake a Fortran compiler argument * Adding patch file for removing duplicated mangling header for versions 3.9.1 and older; static and shared now successfully building on Windows * Have netlib-lapack depend on ninja@1.10 Co-authored-by: John R. Cary Co-authored-by: Jared Popelar Making a default config.yaml for Windows Small path length for build_stage Provide more prerequisite details, mention default config.yaml Killing an unnecessary setvars call Replacing some lost changes, proofreading, updating windows-supported package list Co-authored-by: John Parent --- .../builtin/packages/netlib-lapack/package.py | 6 +++ .../repos/builtin/packages/openssl/package.py | 59 ++++++++++++++++++---- var/spack/repos/builtin/packages/zlib/package.py | 57 +++++++++++++++++---- 3 files changed, 102 insertions(+), 20 deletions(-) (limited to 'var') diff --git a/var/spack/repos/builtin/packages/netlib-lapack/package.py b/var/spack/repos/builtin/packages/netlib-lapack/package.py index bd1baaddef..5d527fedec 100644 --- a/var/spack/repos/builtin/packages/netlib-lapack/package.py +++ b/var/spack/repos/builtin/packages/netlib-lapack/package.py @@ -71,6 +71,7 @@ class NetlibLapack(CMakePackage): depends_on('blas', when='+external-blas') depends_on('netlib-xblas+fortran+plain_blas', when='+xblas') depends_on('python@2.7:', type='test') + depends_on('ninja@1.10.0:', when='platform=windows') # We need to run every phase twice in order to get static and shared # versions of the libraries. When ~shared, we run the default @@ -92,6 +93,11 @@ class NetlibLapack(CMakePackage): '${CMAKE_CURRENT_SOURCE_DIR}/cmake/', 'CBLAS/CMakeLists.txt', string=True) + # Remove duplicate header file that gets generated during CMake shared + # builds: https://github.com/Reference-LAPACK/lapack/issues/583 + if self.spec.satisfies('platform=windows @0:3.9.1'): + force_remove('LAPACKE/include/lapacke_mangling.h') + @property def blas_libs(self): shared = True if '+shared' in self.spec else False diff --git a/var/spack/repos/builtin/packages/openssl/package.py b/var/spack/repos/builtin/packages/openssl/package.py index b4fe7ec425..f21b6b81a8 100644 --- a/var/spack/repos/builtin/packages/openssl/package.py +++ b/var/spack/repos/builtin/packages/openssl/package.py @@ -89,6 +89,8 @@ class Openssl(Package): # Uses Fake Autotools, should subclass Package description=('Use certificates from the ca-certificates-mozilla ' 'package, symlink system certificates, or none')) variant('docs', default=False, description='Install docs and manpages') + variant('shared', default=False, description="Build shared library version") + variant('dynamic', default=False, description="Link with MSVC's dynamic runtime library") depends_on('zlib') depends_on('perl@5.14.0:', type=('build', 'test')) @@ -134,26 +136,65 @@ class Openssl(Package): # Uses Fake Autotools, should subclass Package if self.spec.satisfies('%nvhpc os=centos7'): options.append('-D__STDC_NO_ATOMICS__') - config = Executable('./config') - config('--prefix=%s' % prefix, - '--openssldir=%s' % join_path(prefix, 'etc', 'openssl'), - '-I{0}'.format(self.spec['zlib'].prefix.include), - '-L{0}'.format(self.spec['zlib'].prefix.lib), - *options) + # Make a flag for shared library builds + shared_flag = '' + if spec.satisfies('~shared'): + shared_flag = 'no-shared' + + # On Windows, we use perl for configuration and build through MSVC + # nmake. + if spec.satisfies('platform=windows'): + config = Executable('perl') + config('Configure', + '--prefix=%s' % prefix, + '--openssldir=%s' % join_path(prefix, 'etc', 'openssl'), + 'CC=\"%s\"' % os.environ.get('SPACK_CC'), + 'CXX=\"%s\"' % os.environ.get('SPACK_CXX'), + '%s' % shared_flag, + 'VC-WIN64A') + else: + config = Executable('./config') + config('--prefix=%s' % prefix, + '--openssldir=%s' % join_path(prefix, 'etc', 'openssl'), + '-I{0}'.format(self.spec['zlib'].prefix.include), + '-L{0}'.format(self.spec['zlib'].prefix.lib), + *options) # Remove non-standard compiler options if present. These options are # present e.g. on Darwin. They are non-standard, i.e. most compilers # (e.g. gcc) will not accept them. filter_file(r'-arch x86_64', '', 'Makefile') - make() + if spec.satisfies('+dynamic'): + # This variant only makes sense for Windows + if spec.satisfies('platform=windows'): + filter_file(r'MT', 'MD', 'makefile') + else: + tty.warn("Dynamic runtime builds are only available for " + "Windows operating systems. Please disable " + "+dynamic to suppress this warning.") + + if spec.satisfies('platform=windows'): + nmake = Executable('nmake') + nmake() + else: + make() + if self.run_tests: - make('test', parallel=False) # 'VERBOSE=1' + if spec.satisfies('platform=windows'): + nmake = Executable('nmake') + nmake('test', parallel=False) + else: + make('test', parallel=False) # 'VERBOSE=1' install_tgt = 'install' if self.spec.satisfies('+docs') else 'install_sw' # See https://github.com/openssl/openssl/issues/7466#issuecomment-432148137 - make(install_tgt, parallel=False) + if spec.satisfies('platform=windows'): + nmake = Executable('nmake') + nmake(install_tgt, parallel=False) + else: + make(install_tgt, parallel=False) @run_after('install') def link_system_certs(self): diff --git a/var/spack/repos/builtin/packages/zlib/package.py b/var/spack/repos/builtin/packages/zlib/package.py index e7db85776b..41da1cadf3 100644 --- a/var/spack/repos/builtin/packages/zlib/package.py +++ b/var/spack/repos/builtin/packages/zlib/package.py @@ -6,7 +6,7 @@ # Although zlib comes with a configure script, it does not use Autotools # The AutotoolsPackage causes zlib to fail to build with PGI -class Zlib(Package): +class Zlib(CMakePackage): """A free, general-purpose, legally unencumbered lossless data-compression library. """ @@ -37,19 +37,54 @@ class Zlib(Package): ['libz'], root=self.prefix, recursive=True, shared=shared ) + def cmake_args(self): + args = ['-DBUILD_SHARED_LIBS:BOOL=' + + ('ON' if self._building_shared else 'OFF')] + return args + + @property + def build_directory(self): + return join_path(self.stage.source_path, + 'spack-build-shared' if self._building_shared + else 'spack-build-static') + def setup_build_environment(self, env): if '+pic' in self.spec: env.append_flags('CFLAGS', self.compiler.cc_pic_flag) if '+optimize' in self.spec: - env.append_flags('CFLAGS', '-O2') + env.append_flags('CFLAGS', '-O2') + + # Build, install, and check both static and shared versions of the + # libraries when +shared + @when('+shared platform=windows') + def cmake(self, spec, prefix): + for self._building_shared in (False, True): + super(Zlib, self).cmake(spec, prefix) + + @when('+shared platform=windows') + def build(self, spec, prefix): + for self._building_shared in (False, True): + super(Zlib, self).build(spec, prefix) + + @when('+shared platform=windows') + def check(self): + for self._building_shared in (False, True): + super(Zlib, self).check() def install(self, spec, prefix): - config_args = [] - if '~shared' in spec: - config_args.append('--static') - configure('--prefix={0}'.format(prefix), *config_args) - - make() - if self.run_tests: - make('check') - make('install') + if 'platform=windows' in self.spec and '+shared' in self.spec: + for self._building_shared in (False, True): + super(Zlib, self).install(spec, prefix) + else: + config_args = [] + if '~shared' in spec: + config_args.append('--static') + configure('--prefix={0}'.format(prefix), *config_args) + + make() + if self.run_tests: + make('check') + make('install') + + + -- cgit v1.2.3-70-g09d2