Skip to content
Draft
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
190 changes: 190 additions & 0 deletions .github/actions/setup-spack/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#-------------------------------- -*- yaml -*- ---------------------------------#
# Copyright Celeritas contributors: see top-level COPYRIGHT file for details
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
#-----------------------------------------------------------------------------#
# Bootstrap a Spack environment, install dependencies, and activate it.
#
# Adapted from Celeritas .github/actions/setup-spack: the spack and
# spack-packages commits and the scripts/spack config files must match the
# Celeritas ones so that dependencies are pulled from the Celeritas spack
# buildcache (ghcr.io/celeritas-project/spack-buildcache). Unlike Celeritas,
# G4VG never pushes to the buildcache.
#-----------------------------------------------------------------------------#

name: "Set up Spack environment"
description: "Check out Spack, concretize/install deps, and activate the view"
inputs:
cxxstd:
description: "C++ standard to concretize Spack with"
required: true
env-file:
description: "Base environment file to use (optionally relative to scripts/spack/)"
required: false
add:
description: "Space-separated list of additional spack packages to add"
required: false
default: ""

runs:
using: "composite"
steps:
- name: Set environment and local variables
id: vars
shell: sh
run: |
SPACK_ROOT=$GITHUB_WORKSPACE/spack-src
{
echo "G4VG_SPACK_ENV=$GITHUB_WORKSPACE/spack-env"
echo "G4VG_SPACK_VIEW=/opt/view"
# Used by spack
echo "SPACK_COLOR=always"
echo "SPACK_DISABLE_LOCAL_CONFIG=1"
echo "SPACK_ROOT=$SPACK_ROOT"
} >> "$GITHUB_ENV"
echo "SPACK_PACKAGES_ROOT=$GITHUB_WORKSPACE/spack-pkg" >> "$GITHUB_OUTPUT"
echo "$SPACK_ROOT/bin" >> "$GITHUB_PATH"
# NOTE: keep these refs in sync with Celeritas to reuse its buildcache
- name: Checkout Spack
uses: actions/checkout@v7
with:
repository: spack/spack
path: ${{env.SPACK_ROOT}}
ref: 307d3b0a68316341401d311c1ef6442ed2f13868 # upstream/develop, 12 September 2026
- name: Checkout Spack packages
uses: actions/checkout@v7
with:
repository: spack/spack-packages
path: ${{steps.vars.outputs.SPACK_PACKAGES_ROOT}}
ref: fa11df3be41f58bac19b73346422e06b103ee5b5 # upstream/develop, 6 October 2026

- name: Initialize spack environment
id: init
shell: sh
env:
CXXSTD: ${{inputs.cxxstd}}
SPACK_ENV_FILE: ${{inputs.env-file}}
G4VG_SOURCE_DIR: "${{github.workspace}}"
G4VG_SPACK_OPT: "/opt/spack"
SPACK_PACKAGES_ROOT: "${{steps.vars.outputs.SPACK_PACKAGES_ROOT}}"
run: |
mkdir -p "$G4VG_SPACK_ENV"
cd "$G4VG_SPACK_ENV"
"${G4VG_SOURCE_DIR}/scripts/ci/setup-spack-ci-env.sh" ${{inputs.add}}

# Prefix padding is only needed when pushing to a buildcache
spack -e . config add "config:install_tree:padded_length:False"

# Dump config file, which encodes the full spack environment settings
{
spack -e . config get --json | jq -c '.["spack"]'
printf '{"repos": {"core": "%s", "builtin": "%s"}}\n' \
"$(git -C "$SPACK_ROOT" rev-parse HEAD)" \
"$(git -C "$SPACK_PACKAGES_ROOT" rev-parse HEAD)"
} > spack.config.jsonl

{
echo "config-hash=$(sha256sum spack.config.jsonl | cut -d' ' -f1)"
echo "stage-dir=$(spack -e . location -S)"
} >> "$GITHUB_OUTPUT"
- name: Dump spack config blame
if: ${{runner.debug}}
shell: sh
working-directory: ${{env.G4VG_SPACK_ENV}}
run: |
spack -e . config blame

- name: Restore cached lockfile
id: restore
uses: actions/cache/restore@v6
with:
path: ${{env.G4VG_SPACK_ENV}}/spack.lock
key: lock-${{steps.init.outputs.config-hash}}-${{github.run_id}}
restore-keys: lock-${{steps.init.outputs.config-hash}}
- name: Concretize
if: ${{ !steps.restore.outputs.cache-matched-key }}
id: concretize
shell: sh
working-directory: ${{env.G4VG_SPACK_ENV}}
run: |
echo "::group::Bootstrapping spack"
spack bootstrap now
echo "::endgroup::"
echo "Using mirrors:"
spack -e . mirror list
echo "::group::Available buildcache that explicitly uses cxxstd=$CXXSTD"
spack -e . buildcache list -a -l cxxstd=$CXXSTD || true
echo "::endgroup::"
# NOTE: unlike Celeritas, *don't* use --fresh, so that matching specs
# in the Celeritas buildcache are reused
spack -e . -v concretize
env:
CXXSTD: ${{inputs.cxxstd}}
- name: Cache lockfile
if: ${{ steps.concretize.outcome == 'success' }}
uses: actions/cache/save@v6
with:
path: ${{env.G4VG_SPACK_ENV}}/spack.lock
key: lock-${{steps.init.outputs.config-hash}}-${{github.run_id}}
- name: Install dependencies
id: install
shell: sh
working-directory: ${{env.G4VG_SPACK_ENV}}
run: |
spack ${{runner.debug && '-vd' || ''}} -e . \
install -p 8 --use-buildcache=auto
- name: Upload spack config+lockfile on new concretization or failures
if: >-
${{ !cancelled()
&& (!steps.restore.outputs.cache-matched-key
|| steps.concretize.outcome == 'failure'
|| steps.install.outcome == 'failure')
}}
uses: actions/upload-artifact@v7
with:
name: >-
${{format(
'spack-{0}-{1}-{2}',
steps.init.outputs.config-hash,
github.job || 'action',
strategy.job-index || 0
)}}
path: "${{env.G4VG_SPACK_ENV}}/spack.*"
retention-days: 1
- name: Upload logs only if install failed
if: ${{ !cancelled() && steps.install.outcome == 'failure' }}
uses: actions/upload-artifact@v7
with:
name: >-
${{format(
'spack-logs-{0}-{1}-{2}',
steps.init.outputs.config-hash,
github.job || 'action',
strategy.job-index || 0
)}}
path: "${{steps.init.outputs.stage-dir}}/*.log"
- name: List installed dependencies
if: ${{ !cancelled() }}
shell: sh
working-directory: ${{env.G4VG_SPACK_ENV}}
run: |
echo "::group::Local and concretized"
spack -e . find -lv -c
echo "::endgroup::"
{
echo '```'
spack -e . find -v
echo '```'
} >> "$GITHUB_STEP_SUMMARY"

- name: Update environment and create rc file
shell: sh
# NOTE: the env transformation might be sensitive to spack version changes
run: |
echo "$G4VG_SPACK_VIEW/bin" >> "$GITHUB_PATH"
spack env activate --sh "$G4VG_SPACK_ENV" > "${G4VG_SPACK_VIEW}/rc"
grep '^export ' "${G4VG_SPACK_VIEW}/rc" \
| grep -v '^export PATH=' \
| sed 's/^export \(.*\);\s*$/\1/' >> "$GITHUB_ENV"
echo "::group::Dump ${G4VG_SPACK_VIEW}/rc"
cat "${G4VG_SPACK_VIEW}/rc"
echo "::endgroup::"
91 changes: 81 additions & 10 deletions .github/workflows/build-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,39 @@ concurrency:
group: build-${{github.ref}}-${{github.event.pull_request.number || github.run_number}}-${{github.workflow}}
cancel-in-progress: true

env:
# VecGeom 2.3 development commit built with HIP for the ROCm image.
# Keep in sync with VECGEOM_2_3_COMMIT in build-spack.yml.
VECGEOM_2_3_COMMIT: 9cb15a8a6c776df385357688260567f1e714a434
VECGEOM_PREFIX: /opt/vecgeom
VECGEOM_BUILD_DIR: /opt/vecgeom-build
# Keep in sync with the image tags below
CI_IMAGE_DATE: 2026-11-12

jobs:
# TODO: this currently includes non-GPU builds as well
# and won't actually run on device
# TODO: need to add vecgeom~shared for testing
# NOTE: the containers have GPU toolchains but GitHub runners have no GPU,
# so tests run on host only
gpu:
name: gpu
name: gpu-${{matrix.buildtype}}-${{matrix.image}}
strategy:
fail-fast: false
matrix:
special: [null]
buildtype: ['debug', 'ndebug']
image: ['rocky-cuda']
image: ['ubuntu-cuda', 'ubuntu-rocm']
env:
CELER_DISABLE_DEVICE: 1 # IMPORTANT
CMAKE_PRESET: >-
${{matrix.buildtype}}${{matrix.special && '-' || ''}}${{matrix.special}}
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
container:
# Celeritas CI images: see celeritas scripts/spack/env-docker-{cuda,rocm}.yaml
# - ci-cuda: Ubuntu 24.04, CUDA 13, VecGeom 2.2 +cuda cuda_arch=80, Geant4 11.3
# - ci-rocm: Ubuntu 24.04, ROCm 7.2, Geant4 11.3, *no* VecGeom (built below)
image: >-
docker.io/celeritas/${{
matrix.image == 'rocky-cuda' && 'ci-rocky-cuda12:2024-12-29'
ghcr.io/celeritas-project/${{
matrix.image == 'ubuntu-cuda' && 'ci-cuda:2026-11-12'
|| matrix.image == 'ubuntu-rocm' && 'ci-rocm:2026-11-12'
|| null
}}
steps:
Expand All @@ -36,14 +48,73 @@ jobs:
. /etc/profile
echo "/opt/view/bin" >> $GITHUB_PATH
echo "CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" >> $GITHUB_ENV
# NOTE: checkout must occur *after* setting up environment for git tags to work
- name: Check out
uses: actions/checkout@v4
uses: actions/checkout@v7
with:
fetch-depth: 0

### VecGeom 2.3 with HIP (ROCm image only) ###

- name: Restore VecGeom HIP installation
if: ${{matrix.image == 'ubuntu-rocm'}}
id: vecgeom-cache
uses: actions/cache@v6
with:
# NOTE: VecGeom's config points to the builtin VecCore installed
# in its build directory, so that must be cached too
path: |
${{env.VECGEOM_PREFIX}}
${{env.VECGEOM_BUILD_DIR}}/installExternals
key: vecgeom-hip-static-v2-gfx90a-${{env.VECGEOM_2_3_COMMIT}}-ci-rocm-${{env.CI_IMAGE_DATE}}
# NOTE: static, since linking the shared libvecgeom.so with HIP device
# code fails with ROCm 7.2 (undefined hidden __hip_gpubin_handle_*)
- name: Build VecGeom with HIP
if: >-
${{ matrix.image == 'ubuntu-rocm'
&& steps.vecgeom-cache.outputs.cache-hit != 'true' }}
working-directory: /tmp
run: |
git clone --filter=blob:none --no-checkout \
https://gitlab.cern.ch/VecGeom/VecGeom.git vecgeom-src
git -C vecgeom-src checkout --detach "${VECGEOM_2_3_COMMIT}"
cmake -S vecgeom-src -B "${VECGEOM_BUILD_DIR}" -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${VECGEOM_PREFIX}" \
-DCMAKE_PREFIX_PATH=/opt/rocm \
-DCMAKE_CXX_COMPILER=/opt/rocm/llvm/bin/clang++ \
-DCMAKE_HIP_COMPILER=/opt/rocm/llvm/bin/clang++ \
-DCMAKE_HIP_ARCHITECTURES=gfx90a \
-DCMAKE_CXX_STANDARD=17 \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_TESTING=OFF \
-DVECGEOM_ENABLE_HIP=ON \
-DVECGEOM_BUILTIN_VECCORE=ON \
-DVECGEOM_GDML=ON
cmake --build "${VECGEOM_BUILD_DIR}" -j4
cmake --install "${VECGEOM_BUILD_DIR}"
- name: Add VecGeom to environment
if: ${{matrix.image == 'ubuntu-rocm'}}
run: |
echo "CMAKE_PREFIX_PATH=${VECGEOM_PREFIX}:/opt/rocm:${CMAKE_PREFIX_PATH}" >> $GITHUB_ENV
{
printf 'VecGeom: [%s](https://gitlab.cern.ch/VecGeom/VecGeom/-/commit/%s) (HIP, %s)\n' \
"${VECGEOM_2_3_COMMIT}" "${VECGEOM_2_3_COMMIT}" \
"${{steps.vecgeom-cache.outputs.cache-hit == 'true' && 'cached' || 'built'}}"
} >> $GITHUB_STEP_SUMMARY

### G4VG ###

- name: Configure
run: |
git config --global --add safe.directory ${PWD}
git fetch --tags
ln -fs scripts/cmake-presets/ci-${{matrix.image}}.json CMakeUserPresets.json
cmake --preset=${CMAKE_PRESET} --log-level=VERBOSE
- name: Check VecGeom version
shell: bash
run: |
grep -h 'define G4VG_VECGEOM_VERSION' $(find build -name G4VGVersion.hh) \
| tee -a "$GITHUB_STEP_SUMMARY"
- name: Build
working-directory: build
run: |
Expand Down
Loading
Loading