Skip to content

Commit

Permalink
Windows: Port icu4c; define cxx std flags for MSVC (spack#45547)
Browse files Browse the repository at this point in the history
* Adds an MSBuild system + Builder to the icu4c package
* Adds custom install method as MSBuild system does not vendor an
  install target
* The cxxstd variant is not supported on Windows (there are no config
  options you use to tell the build system what cxx standard to
  build against), so the variant definition was updated to occur
  everywhere except Windows

Also, this commit defines the c/cxx..._flag properties of the MSVC
compiler (although they are not used by `icu4c` and not strictly
necessary to bundle with this PR).
  • Loading branch information
johnwparent authored Aug 21, 2024
1 parent f93595b commit 182bc87
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 10 deletions.
24 changes: 24 additions & 0 deletions lib/spack/spack/compilers/msvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,30 @@ def get_oneapi_root(pth: str):
)
self.msvc_compiler_environment = CmdCall(*env_cmds)

@property
def cxx11_flag(self):
return "/std:c++11"

@property
def cxx14_flag(self):
return "/std:c++14"

@property
def cxx17_flag(self):
return "/std:c++17"

@property
def cxx20_flag(self):
return "/std:c++20"

@property
def c11_flag(self):
return "/std:c11"

@property
def c17_flag(self):
return "/std:c17"

@property
def msvc_version(self):
"""This is the VCToolset version *NOT* the actual version of the cl compiler
Expand Down
64 changes: 54 additions & 10 deletions var/spack/repos/builtin/packages/icu4c/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import pathlib

from spack.package import *


class Icu4c(AutotoolsPackage):
class Icu4c(AutotoolsPackage, MSBuildPackage):
"""ICU is a mature, widely used set of C/C++ and Java libraries providing
Unicode and Globalization support for software applications. ICU4C is the
C/C++ interface."""
Expand All @@ -31,15 +33,22 @@ class Icu4c(AutotoolsPackage):
depends_on("c", type="build") # generated
depends_on("cxx", type="build") # generated

variant(
"cxxstd",
default="11",
values=("11", "14", "17"),
multi=False,
description="Use the specified C++ standard when building",
)
build_system("autotools", "msbuild", default="autotools")
for plat in ["linux", "darwin", "freebsd"]:
with when(f"platform={plat}"):
variant(
"cxxstd",
default="11",
values=("11", "14", "17"),
multi=False,
description="Use the specified C++ standard when building",
)

depends_on("python", type="build", when="@64.1:")
with when("build_system=autotools"):
depends_on("autoconf", type="build")
depends_on("automake", type="build")
depends_on("libtool", type="build")

conflicts(
"%intel@:16",
Expand All @@ -55,8 +64,6 @@ class Icu4c(AutotoolsPackage):
when="@58.0:59",
)

configure_directory = "source"

def url_for_version(self, version):
url = "https://github.com/unicode-org/icu/releases/download/release-{0}/icu4c-{1}-src.tgz"
return url.format(version.dashed, version.underscored)
Expand All @@ -68,12 +75,19 @@ def flag_handler(self, name, flags):
flags.append(getattr(self.compiler, f"cxx{self.spec.variants['cxxstd'].value}_flag"))
return (None, flags, None)


class BuildEnvironment:
# Need to make sure that locale is UTF-8 in order to process source
# files in UTF-8.
@when("@59:")
def setup_build_environment(self, env):
env.set("LC_ALL", "en_US.UTF-8")


class AutotoolsBuilder(spack.build_systems.autotools.AutotoolsBuilder, BuildEnvironment):

configure_directory = "source"

def configure_args(self):
args = []

Expand All @@ -88,3 +102,33 @@ def configure_args(self):
args.append("--enable-rpath")

return args


class MSBuildBuilder(spack.build_systems.msbuild.MSBuildBuilder, BuildEnvironment):
def msbuild_args(self):
return [
"allinone.sln",
self.define("OutputPath", self.spec.prefix),
self.define("Configuration", "Release"),
self.define("SkipUWP", "true"),
]

@property
def build_directory(self):
solution_path = pathlib.Path(self.pkg.stage.source_path)
if self.spec.satsifies("@:67"):
solution_path = solution_path / "icu"
solution_path = solution_path / "source" / "allinone"
return str(solution_path)

def install(self, pkg, spec, prefix):
mkdirp(prefix.lib)
mkdirp(prefix.bin)
mkdirp(prefix.include)
with working_dir(self.pkg.stage.source_path):
# install bin
install_tree("bin64", prefix.bin)
# install lib
install_tree("lib64", prefix.lib)
# intstall headers
install_tree("include", prefix.include)

0 comments on commit 182bc87

Please sign in to comment.