Skip to content

Commit

Permalink
Add Spack-based CI (NOAA-EMC#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderRichert-NOAA authored Sep 12, 2023
1 parent 0e8bce8 commit af57730
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 2 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/Spack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# This is a CI workflow for the NCEPLIBS-ip project.
#
# This workflow builds ip with Spack, including installing with the "--test
# root" option to run the CTest suite. It also has a one-off job that validates
# the recipe by ensuring that every CMake option that should be set in the
# Spack recipe is so set.
#
# Alex Richert, Sep 2023
name: Spack
on:
push:
branches:
- develop
pull_request:
branches:
- develop

jobs:
# This job builds with Spack using every combination of variants and runs the CTest suite each time
Spack:
strategy:
matrix:
os: ["ubuntu-latest"]
openmp: ["+openmp", "~openmp"]
sharedlibs: ["+shared", "~shared"]
pic: ["+pic", "~pic"]
precision: ["precision=d", "precision=4", "precision=8"]
runs-on: ${{ matrix.os }}

steps:

- name: checkout-ip
uses: actions/checkout@v4
with:
path: ip

- name: spack-build-and-test
run: |
git clone -c feature.manyFiles=true https://github.com/spack/spack
. spack/share/spack/setup-env.sh
spack env create ip-env
spack env activate ip-env
cp $GITHUB_WORKSPACE/ip/spack/package.py $SPACK_ROOT/var/spack/repos/builtin/packages/ip/package.py
mv $GITHUB_WORKSPACE/ip $SPACK_ENV/ip
spack develop --no-clone ip@develop
spack add ip@develop%gcc@11 ${{ matrix.openmp }} ${{ matrix.sharedlibs }} ${{ matrix.pic }} ${{ matrix.precision }} target=x86_64
spack external find cmake gmake
spack concretize
# Run installation and run CTest suite
spack install --verbose --fail-fast --test root
# Run 'spack load' to check for obvious errors in setup_run_environment
spack load ip
# This job validates the Spack recipe by making sure each cmake build option is represented
recipe-check:
runs-on: ubuntu-latest

steps:

- name: checkout-ip
uses: actions/checkout@v4
with:
path: ip

- name: recipe-check
run: |
echo "If this jobs fails, look at the most recently output CMake option below and make sure that option appears in spack/package.py"
for opt in $(grep -ioP '^option\(\K(?!(ENABLE_DOCS))[^ ]+' $GITHUB_WORKSPACE/ip/CMakeLists.txt) ; do
echo "Checking for presence of '$opt' CMake option in package.py"
grep -cP "define.+\b${opt}\b" $GITHUB_WORKSPACE/ip/spack/package.py
done
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BUILD_4 "Build the 4-byte real version of the library, libip_4.a" ON)
option(BUILD_D "Build the 8-byte real version of the library, libip_d.a" ON)
option(BUILD_8 "Build the 8-byte integer version of the library, libsp_8.a" OFF)
option(BUILD_TESTING "Build tests of the library" ON)

# Figure whether user wants a _4, a _d, and/or _8.
if(BUILD_4)
Expand Down Expand Up @@ -72,8 +71,8 @@ endif()
add_subdirectory(src)

# Build tests.
include(CTest)
if(BUILD_TESTING)
include(CTest)
add_subdirectory(tests)
endif()

Expand Down
3 changes: 3 additions & 0 deletions spack/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This directory contains an authoritative, up-to-date Spack recipe for NCEPLIBS-ip, which is found under Spack as "ip".

Before each release of NCEPLIBS-ip, this file should be updated to accommodate changes in build options, etc., and .github/workflows/spack.yml should be updated to exercise all variants. Only the version entry should need to be updated after the release prior to incorporation into the Spack repository and the JCSDA Spack fork.
91 changes: 91 additions & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack.package import *


class Ip(CMakePackage):
"""The NCEP general interpolation library (iplib) contains Fortran 90
subprograms to be used for interpolating between nearly all grids used at
NCEP. This is part of the NCEPLIBS project."""

homepage = "https://noaa-emc.github.io/NCEPLIBS-ip"
url = "https://github.com/NOAA-EMC/NCEPLIBS-ip/archive/refs/tags/v3.3.3.tar.gz"
git = "https://github.com/NOAA-EMC/NCEPLIBS-ip"

maintainers("AlexanderRichert-NOAA", "edwardhartnett", "Hang-Lei-NOAA")

version("develop", branch="develop")
version("4.2.0", sha256="9b9f47106822044ff224c6dfd9f140c146dffc833904f2a0c5db7b5d8932e39e")
version("4.1.0", sha256="b83ca037d9a5ad3eb0fb1acfe665c38b51e01f6bd73ce9fb8bb2a14f5f63cdbe")
version("4.0.0", sha256="a2ef0cc4e4012f9cb0389fab6097407f4c623eb49772d96eb80c44f804aa86b8")
version(
"3.3.3",
sha256="d5a569ca7c8225a3ade64ef5cd68f3319bcd11f6f86eb3dba901d93842eb3633",
preferred=True,
)

variant("openmp", description="Enable OpenMP threading", default=True)
variant("pic", default=True, description="Build with position-independent-code")
variant("shared", default=False, description="Build shared library", when="@4.1:")
variant(
"precision",
default=["4", "d"],
values=["4", "d"],
multi=True,
description="Set precision (_4/_d library versions)",
when="@4.1:",
)
variant(
"precision",
default=["4", "d"],
values=["4", "d", "8"],
multi=True,
description="Set precision (_4/_d/_8 library versions)",
when="@4.2:",
)

depends_on("sp")
depends_on("sp@:2.3.3", when="@:4.0")
depends_on("sp precision=4", when="@4.1: precision=4")
depends_on("sp precision=d", when="@4.1: precision=d")
depends_on("sp precision=8", when="@4.1: precision=8")

def cmake_args(self):
args = [
self.define_from_variant("OPENMP", "openmp"),
self.define_from_variant("CMAKE_POSITION_INDEPENDENT_CODE", "pic"),
]

if self.spec.satisfies("@4:"):
args.append(self.define("BUILD_TESTING", self.run_tests))

if self.spec.satisfies("@4.1:"):
args.append(self.define_from_variant("BUILD_SHARED_LIBS", "shared"))
args.append(self.define("BUILD_4", self.spec.satisfies("precision=4")))
args.append(self.define("BUILD_D", self.spec.satisfies("precision=d")))

if self.spec.satisfies("@4.2:"):
args.append(self.define("BUILD_8", self.spec.satisfies("precision=8")))

return args

def setup_run_environment(self, env):
suffixes = (
self.spec.variants["precision"].value
if self.spec.satisfies("@4.1:")
else ["4", "8", "d"]
)
shared = False if self.spec.satisfies("@:4.0") else self.spec.satisfies("+shared")
for suffix in suffixes:
lib = find_libraries(
"libip_" + suffix, root=self.prefix, shared=shared, recursive=True
)
env.set("IP_LIB" + suffix, lib[0])
env.set("IP_INC" + suffix, join_path(self.prefix, "include_" + suffix))

def check(self):
with working_dir(self.builder.build_directory):
make("test")

0 comments on commit af57730

Please sign in to comment.