Skip to content
Merged
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
26 changes: 26 additions & 0 deletions repos/spack_repo/builtin/packages/fms/llvmflang.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--- a/cmake/fms_compiler_flags.cmake
+++ b/cmake/fms_compiler_flags.cmake
@@ -7,6 +7,8 @@ if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel")
include(compiler_flags_Intel_Fortran)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM")
include(compiler_flags_IntelLLVM_Fortran)
+elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
+ include(compiler_flags_LLVMFlang_Fortran)
else()
message(WARNING "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
endif()
--- /dev/null
+++ b/cmake/compiler_flags_LLVMFlang_Fortran.cmake
@@ -0,0 +1,11 @@
+# Precision-based Fortran compiler flags
+set(r8_flags "-fdefault-real-8 -fdefault-double-8")
+set(r4_flags "-fdefault-real-4")
+
+# LLVM Flang
+set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS}")
+set(CMAKE_Fortran_FLAGS_RELEASE "-O2")
+set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g")
+set(CMAKE_Fortran_LINK_FLAGS "")
+
+# UFS flags are not known for LLVM Flang.
4 changes: 4 additions & 0 deletions repos/spack_repo/builtin/packages/fms/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class Fms(CMakePackage):
when="@2023.03",
)

# Add LLVM Flang precision flags. Based on the GEOS Baselibs patch:
# https://github.com/GEOS-ESM/ESMA-Baselibs/blob/main/patches/FMS/llvm.patch
patch("llvmflang.patch", when="@2026.01.01 %fortran=clang")

variant(
"portable_kinds",
description="Use iso_c_binding variable kinds",
Expand Down
41 changes: 41 additions & 0 deletions repos/spack_repo/builtin/packages/hdf5/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,22 @@ def is_enabled(text):
def setup_build_environment(self, env: EnvironmentModifications) -> None:
env.set("SZIP_INSTALL", self.spec["szip"].prefix)

@run_before("cmake")
def fix_darwin_fortran_link_flags(self):
if not self.spec.satisfies("@2.0.0: platform=darwin") or not (
self.spec.satisfies("%fortran=clang") or self.spec.satisfies("%fortran=nag")
):
return

# HDF5 uses CMake's C linker flag variables for version flags on all
# targets. Forward them explicitly so Flang and NAG pass them to ld.
filter_file(
'LINK_FLAGS "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}${PACKAGE_CURRENT} ${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}${PACKAGE_COMPATIBILITY}"',
'LINK_FLAGS "-Wl,-current_version -Wl,${PACKAGE_CURRENT} -Wl,-compatibility_version -Wl,${PACKAGE_COMPATIBILITY}"',
"config/HDF5Macros.cmake",
string=True,
)

def cmake_args(self):
spec = self.spec

Expand Down Expand Up @@ -646,6 +662,31 @@ def cmake_args(self):
# NAG cannot pass Spack's padded build rpath through its linker.
args.append(self.define("CMAKE_SKIP_RPATH", True))

if spec.satisfies("@2.0.0: platform=darwin %fortran=clang"):
# CMake's generic Darwin rule sends -install_name directly to the
# driver, but LLVM Flang requires Darwin linker flags via
# -Xlinker. CMake emits this flag and its value separately.
args.append(
self.define(
"CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG",
"-Xlinker -install_name -Xlinker ",
)
)

if spec.satisfies("@2.0.0: platform=darwin +mpi +fortran") and (
spec.satisfies("%fortran=clang") or spec.satisfies("%fortran=nag")
):
# HDF5's nested Fortran project loses the OpenMPI module directory
# discovered by FindMPI, so its generated modules cannot resolve
# mpi_f08.mod (Flang) or mpi.mod (NAG) while building the high-level
# Fortran library.
args.append(
self.define(
"MPI_Fortran_INCLUDE_DIRS",
f"{spec['mpi'].prefix.include};{spec['mpi'].prefix.lib}",
)
)

return args

@run_after("install")
Expand Down
10 changes: 9 additions & 1 deletion repos/spack_repo/builtin/packages/llvm/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,21 @@ class Llvm(CMakePackage, CudaPackage, LlvmDetection, CompilerPackage):
# Note: remember to update `provides("libllvm")` according to major versions listed

# Latest stable
version("23.1.2", sha256="75788d759e6987a910975b902f554dc77c08b076b945b2cebde54116d8e831ca")
version("23.1.1", sha256="851b3d701a4fbdd9f69536d4acda578469e810ca7056687d6556443f5fd39557")
version("23.1.0", sha256="d8657b2a7291e518407bf13c4b41c85ef2cded2d4354097a2f451644dfc817b0")

# Previous stable series releases
version("22.1.8", sha256="ad18b70e287954c3d62bc7e0b86e7b7af2adf87bcfce21c15fe717f101d7aace")
version("22.1.7", sha256="da1578ea1faf2050e4b1923fce150b5656db1dbdeda71fe02498ac04f35b03d3")
version("22.1.6", sha256="ba534c6835a5b9c2162c806e269799fe41fca952a3c25baff1afcff23841ec2b")
version("22.1.5", sha256="263e99bd0b590664a886b0332037ff060e108f4e7b0310b7c8277208858f867d")
version("22.1.4", sha256="e813bf8da34ec2b7c108c4067937380fa7d5a04a13f4fe13555dbe388482d69f")
version("22.1.3", sha256="7e144bd6da8177757434cc0dfd1476122f143413df379c6d6cf03843512b5a9e")
version("22.1.2", sha256="a252efd7a4a268d2cc5145b17adcaa82757fdee1d06d748b4c24137807710ecb")
version("22.1.1", sha256="c48878550911a8a8993a749e6118446082656768e62b26456ac7d39c4422b409")
version("22.1.0", sha256="933765a1c2cd518d95a9033a92d88d7109a79aefa4609247c31f28b8bc8dd96e")

# Previous stable series releases
version("21.1.8", sha256="7ba3f2a8d8fda88be18a31d011e8195d3b7f87f9fa92b20c94cba2d7f65b0e3f")
version("21.1.7", sha256="9ee167cdf8f6b5221d6b02dbe9a664cf8c6fee70fab071aaa4a3889c7c265258")
version("21.1.6", sha256="2380973eb435b48bd70881939da3629069009a851c81676dfb211a1b068d72a6")
Expand Down Expand Up @@ -272,6 +279,7 @@ class Llvm(CMakePackage, CudaPackage, LlvmDetection, CompilerPackage):

variant("utils", default=False, description="Install utility binaries (FileCheck, etc.)")

provides("libllvm@23", when="@23")
provides("libllvm@22", when="@22")
provides("libllvm@21", when="@21")
provides("libllvm@20", when="@20")
Expand Down
18 changes: 16 additions & 2 deletions repos/spack_repo/builtin/packages/openmpi/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,24 @@ def libs(self):
return find_libraries(libraries, root=self.prefix, shared=True, recursive=True)

def setup_build_environment(self, env: EnvironmentModifications) -> None:
# We need to unset MACOSX_DEPLOYMENT_TARGET on macOS if building with NAG Fortran
if self.spec.satisfies("platform=darwin") and self.spec.satisfies("%fortran=nag"):
# Match OpenMPI's Darwin configuration when using Flang or NAG.
# It avoids a shared-library path that these compilers do not support
# for the older Fortran bindings.
if self.spec.satisfies("platform=darwin") and (
self.spec.satisfies("%fortran=nag") or self.spec.satisfies("%fortran=clang")
):
env.unset("MACOSX_DEPLOYMENT_TARGET")

@run_after("configure")
def fix_darwin_flang_libtool(self):
if not self.spec.satisfies("platform=darwin %fortran=clang"):
return

# Libtool recognizes a direct `flang` command but not Spack's absolute
# compiler-wrapper path. Consequently it passes Darwin linker flags
# directly to Flang instead of through -Wl,.
filter_file(r"flang\*", r"*/flang|flang*", "libtool")

def setup_run_environment(self, env: EnvironmentModifications) -> None:
# Because MPI is both a runtime and a compiler, we have to setup the
# compiler components as part of the run environment.
Expand Down
9 changes: 9 additions & 0 deletions repos/spack_repo/builtin/packages/parallelio/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ def cmake_args(self):
if spec.satisfies("%nag"):
# NAG cannot pass Spack's padded build rpath through its linker.
args.append(define("CMAKE_SKIP_RPATH", True))
if spec.satisfies("platform=darwin %fortran=clang"):
# CMake's generic Darwin rule sends -install_name directly to the
# compiler driver, but LLVM Flang requires linker flags via -Xlinker.
args.append(
define(
"CMAKE_SHARED_LIBRARY_SONAME_Fortran_FLAG",
"-Xlinker -install_name -Xlinker ",
)
)
if spec.satisfies("+ncint"):
args.extend([define("PIO_ENABLE_NETCDF_INTEGRATION", True)])
if spec.satisfies("+pnetcdf"):
Expand Down
12 changes: 12 additions & 0 deletions repos/spack_repo/builtin/packages/pfunit/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ def patch(self):
for file in glob.glob("*/CMakeLists.txt"):
filter_file(r".*/mod($|[^\w].*)", "", file)

@run_before("cmake")
def fix_darwin_llvmflang_ranlib(self):
if self.spec.satisfies("platform=darwin %fortran=clang"):
# pFUnit's macOS override passes a GNU ranlib-only option that
# LLVM ranlib rejects. CMake's default archive rule is valid.
filter_file(
"if (APPLE)",
'if (APPLE AND NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")',
"CMakeLists.txt",
string=True,
)

def url_for_version(self, version):
url_base = "https://github.com/Goddard-Fortran-Ecosystem/pFUnit"
# Version 4.2.3+ has a v...
Expand Down