Creating a spack.yaml file¶
Let's create a spack.yaml file that will allow us to create a Spack
environment for compiling FluidSynth using CMake.
Below is a spack.yaml file which you can also find in the
spack-config-templates repository
inside the environment-templates sub-directory for the version of Spack you
are using - called spack-cmake.yaml. Either copy and paste the below or grab
the example from the repository, make sure it is named spack.yaml and save it
into a directory of your choice for your environment. For the purposes of this
tutorial I am going to save it as:
/gpfs/scratch/${USER}/spack-environments/spack-cmake/spack.yaml
(please create the directory first if it doesn't exist). This means the Spack
environment will also be stored in
/gpfs/scratch/${USER}/spack-environments/spack-cmake. You may wish to store
your own environments in an alternative location if you need to keep them
for longer. Please refer back to the
Configuration overview page for further
information.
Bash variables aren't expanded in prefix_inspections
Rather than using ${USER} or any other bash variables for
prefix_inspections paths, you must use the full real path (i.e. use your
actual username (abc123) not a variable).
Contents of spack.yaml (click to expand)
spack:
concretizer:
unify: true
config:
install_tree:
root: /gpfs/scratch/${USER}/spack/apps
projections:
^mpi: '{architecture}/{compiler.name}-{compiler.version}/{name}/{version}-{^mpi.name}-{^mpi.version}-{hash:7}'
all: '{architecture}/{compiler.name}-{compiler.version}/{name}/{version}-{hash:7}'
license_dir: /gpfs/scratch/${USER}/spack/licenses
source_cache: /gpfs/scratch/${USER}/spack/cache
modules:
prefix_inspections:
/gpfs/scratch/abc123/fluidsynth-install/bin:
- PATH
./share/aclocal:
- ACLOCAL_PATH
./lib:
- LD_LIBRARY_PATH
- LIBRARY_PATH
./lib64:
- LD_LIBRARY_PATH
- LIBRARY_PATH
/gpfs/scratch/abc123/fluidsynth-install/lib64:
- LD_LIBRARY_PATH
- LIBRARY_PATH
./include:
- C_INCLUDE_PATH
- CPLUS_INCLUDE_PATH
/gpfs/scratch/abc123/fluidsynth-install/include:
- C_INCLUDE_PATH
- CPLUS_INCLUDE_PATH
packages:
all:
target: [x86_64_v4]
gcc:
externals:
- spec: gcc@11.4.1 languages='c,c++,fortran'
prefix: /usr
extra_attributes:
compilers:
c: /usr/bin/gcc
cxx: /usr/bin/g++
fortran: /usr/bin/gfortran
- spec: gcc@12.2.0 languages='c,c++,fortran'
prefix: /share/apps/rocky9/spack/apps/linux-rocky9-x86_64_v4/gcc-11.4.1/gcc/12.2.0-6frskzg
extra_attributes:
compilers:
c: /share/apps/rocky9/spack/apps/linux-rocky9-x86_64_v4/gcc-11.4.1/gcc/12.2.0-6frskzg/bin/gcc
cxx: /share/apps/rocky9/spack/apps/linux-rocky9-x86_64_v4/gcc-11.4.1/gcc/12.2.0-6frskzg/bin/g++
fortran: /share/apps/rocky9/spack/apps/linux-rocky9-x86_64_v4/gcc-11.4.1/gcc/12.2.0-6frskzg/bin/gfortran
flags: {}
environment: {}
extra_rpaths: []
openmpi:
buildable: false
prefer:
- '@5.0.3 +gpfs'
externals:
- spec: "openmpi@5.0.3 +gpfs %gcc@12.2.0"
prefix: /share/apps/rocky9/general/libs/openmpi/gcc/12.2.0/5.0.3
- spec: "openmpi@5.0.3-nogpfs ~gpfs %gcc@12.2.0"
prefix: /share/apps/rocky9/general/libs/openmpi/gcc/12.2.0/5.0.3-nogpfs
ucx:
buildable: false
externals:
- spec: "ucx@1.16.0%gcc@12.2.0"
prefix: /share/apps/rocky9/general/libs/ucx/gcc/12.2.0/1.16.0
repos:
builtin:
destination: /share/apps/rocky9/general/apps/spack-packages/2026.03.0
specs:
- cmake
- gcc@12.2.0
- glib
upstreams:
apocrita:
install_tree: /share/apps/rocky9/spack/apps
view:
default:
root: .spack-env/view
It's basically identical to our
Python example apart from the specs list
(which now has cmake, gcc@12.2.0 and glib). As before, the modules
section sets the prefix_inspections: required to set the environment variables
we are going to need for the manual compilation of FluidSynth using CMake. It
also adds some additional paths to the modules: section, which we be explained
later in this tutorial.