Skip to content

Commit

Permalink
Merge pull request #192 from AlexanderRichert-NOAA/add_spack_ci
Browse files Browse the repository at this point in the history
Add Spack-based CI workflow
  • Loading branch information
edwardhartnett authored Sep 27, 2023
2 parents 624f1e6 + c0b6f53 commit c6246e5
Show file tree
Hide file tree
Showing 4 changed files with 162 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-w3emc project.
#
# This workflow builds w3emc 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"]
pic_shared_extradeps: ["+pic +shared", "+pic ~shared +extradeps", "+pic ~shared ~extradeps", "~pic +extradeps", "~pic ~extradeps"]
precision: ["precision=d", "precision=4", "precision=8"]
bufr: ["~bufr"]

runs-on: ${{ matrix.os }}

steps:

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

- name: spack-build-and-test
run: |
git clone -c feature.manyFiles=true https://github.com/jcsda/spack
. spack/share/spack/setup-env.sh
spack env create w3emc-env
spack env activate w3emc-env
cp $GITHUB_WORKSPACE/w3emc/spack/package.py $SPACK_ROOT/var/spack/repos/builtin/packages/w3emc/package.py
mv $GITHUB_WORKSPACE/w3emc $SPACK_ENV/w3emc
spack develop --no-clone w3emc@develop
spack add w3emc@develop%gcc@11 ${{ matrix.pic_shared_extradeps }} ${{ matrix.precision }} ${{ matrix.bufr }}
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 w3emc
# This job validates the Spack recipe by making sure each cmake build option is represented
recipe-check:
runs-on: ubuntu-latest

steps:

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

- 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/w3emc/CMakeLists.txt) ; do
echo "Checking for presence of '$opt' CMake option in package.py"
grep -cP "define.+\b${opt}\b" $GITHUB_WORKSPACE/w3emc/spack/package.py
done
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BUILD_4 "Build the 4-byte real version of the library, libw3emc_4.a" ON)
option(BUILD_D "Build the 8-byte real version of the library, libw3emc_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)
option(BUILD_WITH_EXTRA_DEPS "Build w3emc with subprograms which call unknown dependencies" OFF)
option(BUILD_WITH_BUFR "Build w3emc with subprograms which call NCEPLIBS-bufr" OFF)

Expand Down Expand Up @@ -91,8 +90,8 @@ endif()
add_subdirectory(src)

# Add tests.
include(CTest)
if(BUILD_TESTING)
enable_testing()
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-w3emc, which is found under Spack as "w3emc".

Before each release of NCEPLIBS-w3emc, 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.
87 changes: 87 additions & 0 deletions spack/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# 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 W3emc(CMakePackage):
"""This library contains Fortran 90 decoder/encoder routines for GRIB
edition 1 with EMC changes.
This is part of the NCEPLIBS project."""

homepage = "https://noaa-emc.github.io/NCEPLIBS-w3emc/"
url = "https://github.com/NOAA-EMC/NCEPLIBS-w3emc/archive/refs/tags/v2.9.0.tar.gz"
git = "https://github.com/NOAA-EMC/NCEPLIBS-w3emc"

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

version("develop", branch="develop")
version("2.10.0", sha256="366b55a0425fc3e729ecb9f3b236250349399fe4c8e19f325500463043fd2f18")
version("2.9.3", sha256="9ca1b08dd13dfbad4a955257ae0cf38d2e300ccd8d983606212bc982370a29bc")
version("2.9.2", sha256="eace811a1365f69b85fdf2bcd93a9d963ba72de5a7111e6fa7c0e6578b69bfbc")
version("2.9.1", sha256="d3e705615bdd0b76a40751337d943d5a1ea415636f4e5368aed058f074b85df4")
version("2.9.0", sha256="994f59635ab91e34e96cab5fbaf8de54389d09461c7bac33b3104a1187e6c98a")
version("2.7.3", sha256="eace811a1365f69b85fdf2bcd93a9d963ba72de5a7111e6fa7c0e6578b69bfbc")

variant("pic", default=True, description="Build with position-independent-code")
variant("bufr", default=False, description="Build with BUFR routines", when="@2.10:")
variant(
"precision",
default=("4", "d"),
values=("4", "d", "8"),
multi=True,
description="Set precision (_4/_d/_8 library versions)",
when="@2.10:",
)
variant("shared", default=False, description="Build shared library", when="@2.10: +pic")
variant(
"extradeps",
default=False,
description="Build w3emc with subprograms which call unknown dependencies",
when="@2.10:",
)

conflicts("+shared +extradeps", msg="Shared library cannot be built with unknown dependencies")

depends_on("bufr", when="@2.10: +bufr")
depends_on("bacio", when="@2.9.2:")

# w3emc 2.7.3 contains gblevents which has these dependencies
depends_on("nemsio", when="@2.7.3")
depends_on("sigio", when="@2.7.3")
depends_on("netcdf-fortran", when="@2.7.3")

def setup_run_environment(self, env):
if self.spec.satisfies("@:2.9"):
suffixes = ("4", "d", "8")
shared = False
else:
suffixes = self.spec.variants["precision"].value
shared = self.spec.satisfies("+shared")

for suffix in suffixes:
lib = find_libraries(
"libw3emc_" + suffix, root=self.prefix, shared=shared, recursive=True
)
env.set("W3EMC_LIB" + suffix, lib[0])
env.set("W3EMC_INC" + suffix, join_path(self.prefix, "include_" + suffix))

def cmake_args(self):
args = [
self.define_from_variant("BUILD_WITH_BUFR", "bufr"),
self.define_from_variant("CMAKE_POSITION_INDEPENDENT_CODE", "pic"),
self.define("BUILD_4", self.spec.satisfies("precision=4")),
self.define("BUILD_D", self.spec.satisfies("precision=d")),
self.define("BUILD_8", self.spec.satisfies("precision=8")),
self.define_from_variant("BUILD_SHARED_LIBS", "shared"),
self.define_from_variant("BUILD_WITH_EXTRA_DEPS", "extradeps"),
]

return args

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

0 comments on commit c6246e5

Please sign in to comment.