Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapel update for Arkouda #1

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions var/spack/repos/builtin/packages/chapel/fix_chpl_line_length.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/compiler/util/files.cpp b/compiler/util/files.cpp
index 4183614988..9746baf935 100644
--- a/compiler/util/files.cpp
+++ b/compiler/util/files.cpp
@@ -211,7 +211,7 @@ void restoreDriverTmp(const char* tmpFilePath,

fileinfo* tmpFile = openTmpFile(tmpFilePath, "r");

- char strBuf[4096];
+ char strBuf[8192];
while (fgets(strBuf, sizeof(strBuf), tmpFile->fptr)) {
// Note: Using strlen here (instead of strnlen) is safe because fgets
// guarantees null termination.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
diff --git a/tools/chapel-py/setup.py b/tools/chapel-py/setup.py
index bee452790c..58ec46d7e6 100644
--- a/tools/chapel-py/setup.py
+++ b/tools/chapel-py/setup.py
@@ -46,7 +46,37 @@ host_cc = str(chpl_variables.get("CHPL_HOST_CC"))
host_cxx = str(chpl_variables.get("CHPL_HOST_CXX"))

host_bin_subdir = str(chpl_variables.get("CHPL_HOST_BIN_SUBDIR"))
+
+# construct the chpl_lib_path from chpl_home, or use the configured-prefix if it exists
+
chpl_lib_path = os.path.join(chpl_home, "lib", "compiler", host_bin_subdir)
+chpl_install_lib_path = None
+if os.path.exists(os.path.join(chpl_home, "configured-prefix")):
+ with open(os.path.join(chpl_home, "CMakeLists.txt"), "r") as f:
+ # read CMakeLists.txt to get the CHPL_MAJOR_VERSION and CHPL_MINOR_VERSION
+ # and then construct the path from that
+ chpl_major_version = None
+ chpl_minor_version = None
+ for line in f:
+ if "set(CHPL_MAJOR_VERSION" in line:
+ chpl_major_version = line.split()[1].strip(')')
+ if "set(CHPL_MINOR_VERSION" in line:
+ chpl_minor_version = line.split()[1].strip(')')
+ if chpl_major_version is not None and chpl_minor_version is not None:
+ break
+ assert(chpl_major_version is not None and chpl_minor_version is not None)
+ chpl_version_string = "{}.{}".format(chpl_major_version, chpl_minor_version)
+ chpl_prefix = None
+ with open(os.path.join(chpl_home, "configured-prefix"), "r") as f:
+ chpl_prefix = f.read().strip()
+ assert(chpl_prefix is not None)
+ chpl_install_lib_path = os.path.join(
+ chpl_prefix,
+ "lib",
+ "chapel",
+ chpl_version_string,
+ "compiler"
+ )
arezaii marked this conversation as resolved.
Show resolved Hide resolved

CXXFLAGS = []
if have_llvm and have_llvm != "none":
@@ -64,10 +94,14 @@ CXXFLAGS += ["-std=c++17", "-I{}/frontend/include".format(chpl_home)]
LDFLAGS = []
LDFLAGS += [
"-L{}".format(chpl_lib_path),
+ "-Wl,-rpath,{}".format(chpl_lib_path),
"-lChplFrontendShared",
- "-Wl,-rpath",
- chpl_lib_path,
]
+if chpl_install_lib_path is not None:
+ LDFLAGS += [
+ "-L{}".format(chpl_install_lib_path),
+ "-Wl,-rpath,{}".format(chpl_install_lib_path),
+ ]

if str(chpl_variables.get("CHPL_SANITIZE")) == "address":
if str(chpl_variables.get("CHPL_HOST_PLATFORM")) == "darwin":
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/tools/chapel-py/setup.py b/tools/chapel-py/setup.py
index 30c2708724..3921143def 100644
--- a/tools/chapel-py/setup.py
+++ b/tools/chapel-py/setup.py
@@ -47,6 +47,36 @@ host_cxx = str(chpl_variables.get("CHPL_HOST_CXX"))

host_bin_subdir = str(chpl_variables.get("CHPL_HOST_BIN_SUBDIR"))
chpl_lib_path = os.path.join(chpl_home, "lib", "compiler", host_bin_subdir)
+# For installations using --prefix, the lib final lib path is going to be different
+# figure it out now and write it to the rpath
+chpl_install_lib_path = None
+if os.path.exists(os.path.join(chpl_home, "configured-prefix")):
+ with open(os.path.join(chpl_home, "CMakeLists.txt"), "r") as f:
+ # read CMakeLists.txt to get the CHPL_MAJOR_VERSION and CHPL_MINOR_VERSION
+ # and then construct the path from that
+ chpl_major_version = None
+ chpl_minor_version = None
+ for line in f:
+ if "set(CHPL_MAJOR_VERSION" in line:
+ chpl_major_version = line.split()[1].strip(')')
+ if "set(CHPL_MINOR_VERSION" in line:
+ chpl_minor_version = line.split()[1].strip(')')
+ if chpl_major_version is not None and chpl_minor_version is not None:
+ break
+ assert(chpl_major_version is not None and chpl_minor_version is not None)
+ chpl_version_string = "{}.{}".format(chpl_major_version, chpl_minor_version)
+ chpl_prefix = None
+ with open(os.path.join(chpl_home, "configured-prefix"), "r") as f:
+ chpl_prefix = f.read().strip()
+ assert(chpl_prefix is not None)
+ chpl_install_lib_path = os.path.join(
+ chpl_prefix,
+ "lib",
+ "chapel",
+ chpl_version_string,
+ "compiler"
+ )
+

CXXFLAGS = []
if have_llvm and have_llvm != "none":
@@ -68,6 +98,12 @@ LDFLAGS += [
"-lChplFrontendShared",
]

+if chpl_install_lib_path is not None:
+ LDFLAGS += [
+ "-L{}".format(chpl_install_lib_path),
+ "-Wl,-rpath,{}".format(chpl_install_lib_path),
+ ]
+
if str(chpl_variables.get("CHPL_SANITIZE")) == "address":
if str(chpl_variables.get("CHPL_HOST_PLATFORM")) == "darwin":
sys.exit(
100 changes: 89 additions & 11 deletions var/spack/repos/builtin/packages/chapel/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os
import re
import subprocess

import llnl.util.lang
Expand Down Expand Up @@ -63,10 +64,16 @@ class Chapel(AutotoolsPackage, CudaPackage, ROCmPackage):
version("2.0.1", sha256="47e1f3789478ea870bd4ecdf52acbe469d171b89b663309325431f3da7c75008")
version("2.0.0", sha256="a8cab99fd034c7b7229be8d4626ec95cf02072646fb148c74b4f48c460c6059c")

sanity_check_is_dir = ["bin", join_path("lib", "chapel"), join_path("share", "chapel")]
sanity_check_is_file = [join_path("bin", "chpl")]

depends_on("c", type="build") # generated
depends_on("cxx", type="build") # generated

patch("fix_spack_cc_wrapper_in_cray_prgenv.patch", when="@2.0.0:")
patch("fix_chpl_shared_lib_path.patch", when="@2.1:2.2 +python-bindings")
patch("fix_chpl_shared_lib_path_2.3.patch", when="@2.2.1: +python-bindings")
patch("fix_chpl_line_length.patch")

launcher_names = (
"amudprun",
Expand Down Expand Up @@ -326,6 +333,12 @@ class Chapel(AutotoolsPackage, CudaPackage, ROCmPackage):
values=("bundled", "none", "spack"),
)

variant(
"python-bindings",
description="Also build the Python bindings for Chapel frontend (requires LLVM)",
default=False,
)

variant(
"re2",
description="Build with re2 support",
Expand Down Expand Up @@ -407,6 +420,7 @@ class Chapel(AutotoolsPackage, CudaPackage, ROCmPackage):
"CHPL_GPU",
"CHPL_GPU_ARCH",
"CHPL_GPU_MEM_STRATEGY",
"CHPL_HOME",
"CHPL_HOST_ARCH",
# "CHPL_HOST_CC",
"CHPL_HOST_COMPILER",
Expand Down Expand Up @@ -495,6 +509,11 @@ class Chapel(AutotoolsPackage, CudaPackage, ROCmPackage):
with when("llvm=none"):
conflicts("+cuda", msg="Cuda support requires building with LLVM")
conflicts("+rocm", msg="ROCm support requires building with LLVM")
conflicts(
"+python-bindings",
msg="Python bindings require building with LLVM, see "
"https://chapel-lang.org/docs/tools/chapel-py/chapel-py.html#installation",
)

# Add dependencies

Expand Down Expand Up @@ -536,6 +555,9 @@ class Chapel(AutotoolsPackage, CudaPackage, ROCmPackage):
depends_on("gasnet conduits=none", when="gasnet=spack")
depends_on("[email protected]: conduits=none", when="@2.1.0: gasnet=spack")

with when("+python-bindings"):
extends("python")

depends_on("[email protected]:")
depends_on("[email protected]:")

Expand Down Expand Up @@ -565,9 +587,20 @@ def unset_chpl_env_vars(self, env):
env.unset(var)

def build(self, spec, prefix):
make()
if spec.variants["chpldoc"].value:
make("chpldoc")
with set_env(CHPL_MAKE_THIRD_PARTY=join_path(self.build_directory, "third-party")):
make()
with set_env(CHPL_HOME=self.build_directory):
if spec.satisfies("+chpldoc"):
make("chpldoc")
if spec.satisfies("+python-bindings"):
make("chapel-py-venv")
python("-m", "ensurepip", "--default-pip")
python("-m", "pip", "install", "tools/chapel-py")

def install(self, spec, prefix):
make("install")
if str(spec.version).lower() == "main":
install("CMakeLists.txt", join_path(prefix.share, "chapel"))

def setup_chpl_platform(self, env):
if self.spec.variants["host_platform"].value == "unset":
Expand Down Expand Up @@ -726,23 +759,68 @@ def setup_build_environment(self, env):

def setup_run_environment(self, env):
self.setup_env_vars(env)
env.prepend_path(
"PATH", join_path(self.prefix.share, "chapel", self._output_version_short, "util")
chpl_home = join_path(self.prefix.share, "chapel", self._output_version_short)
env.prepend_path("PATH", join_path(chpl_home, "util"))
env.set(
"CHPL_MAKE_THIRD_PARTY",
join_path(self.prefix.lib, "chapel", self._output_version_short),
)
env.set("CHPL_HOME", chpl_home)

def get_main_version_from_cmakelists(self) -> str:
cmake_lists = None
if os.path.exists(join_path(self.prefix.share, "chapel", "CMakeLists.txt")):
cmake_lists = join_path(self.prefix.share, "chapel", "CMakeLists.txt")
else:
cmake_lists = join_path(self.build_directory, "CMakeLists.txt")
assert cmake_lists is not None and os.path.exists(cmake_lists)
with open(cmake_lists, "r") as f:
# read CMakeLists.txt to get the CHPL_MAJOR_VERSION and CHPL_MINOR_VERSION
# and then construct the path from that
chpl_major_version = None
chpl_minor_version = None
chpl_patch_version = None
for line in f:
if "set(CHPL_MAJOR_VERSION" in line:
chpl_major_version = line.split()[1].strip(")")
if "set(CHPL_MINOR_VERSION" in line:
chpl_minor_version = line.split()[1].strip(")")
if "set(CHPL_PATCH_VERSION" in line:
chpl_patch_version = line.split()[1].strip(")")
if (
chpl_major_version is not None
and chpl_minor_version is not None
and chpl_patch_version is not None
):
break
assert (
chpl_major_version is not None
and chpl_minor_version is not None
and chpl_patch_version is not None
)
chpl_version_string = "{}.{}.{}".format(
chpl_major_version, chpl_minor_version, chpl_patch_version
)
return chpl_version_string

def is_versioned_release(self) -> bool:
# detect main or possibly other branch names
matches = re.findall(r"[^0-9.]", str(self.spec.version))
return len(matches) == 0

@property
@llnl.util.lang.memoized
def _output_version_long(self):
if str(self.spec.version).lower() == "main":
return "2.3.0"
def _output_version_long(self) -> str:
if not self.is_versioned_release():
return self.get_main_version_from_cmakelists()
spec_vers_str = str(self.spec.version.up_to(3))
return spec_vers_str

@property
@llnl.util.lang.memoized
def _output_version_short(self):
if str(self.spec.version).lower() == "main":
return "2.3"
def _output_version_short(self) -> str:
if not self.is_versioned_release():
return self.get_main_version_from_cmakelists()[-2]
spec_vers_str = str(self.spec.version.up_to(2))
return spec_vers_str

Expand Down
Loading