diff --git a/configs/sites/tier1/hercules/packages_oneapi-2025.3.1.yaml b/configs/sites/tier1/hercules/packages_oneapi-2025.3.1.yaml index 2d96294c1d..e14516e786 100644 --- a/configs/sites/tier1/hercules/packages_oneapi-2025.3.1.yaml +++ b/configs/sites/tier1/hercules/packages_oneapi-2025.3.1.yaml @@ -26,6 +26,8 @@ packages: environment: prepend_path: LD_LIBRARY_PATH: '/usr/lib:/usr/lib64' + # EPIC-installed oneAPI compiler module + MODULEPATH: '/apps/contrib/spack-stack/modulefiles' intel-oneapi-mkl: buildable: false externals: diff --git a/configs/sites/tier1/orion/packages_oneapi-2025.3.1.yaml b/configs/sites/tier1/orion/packages_oneapi-2025.3.1.yaml index 0ec52951fc..6e97117c49 100644 --- a/configs/sites/tier1/orion/packages_oneapi-2025.3.1.yaml +++ b/configs/sites/tier1/orion/packages_oneapi-2025.3.1.yaml @@ -26,6 +26,8 @@ packages: environment: prepend_path: LD_LIBRARY_PATH: '/usr/lib:/usr/lib64' + # EPIC-installed oneAPI compiler module + MODULEPATH: '/apps/contrib/spack-stack/modulefiles' intel-oneapi-mkl: buildable: false externals: diff --git a/spack-ext/lib/spack-stack/stack/meta_modules.py b/spack-ext/lib/spack-stack/stack/meta_modules.py index 0757f59f77..d3dae411d9 100755 --- a/spack-ext/lib/spack-stack/stack/meta_modules.py +++ b/spack-ext/lib/spack-stack/stack/meta_modules.py @@ -424,7 +424,8 @@ def setup_meta_modules(): compiler_subs["COMPFLAGS"] = compiler_subs["COMPFLAGS"].rstrip("\n") logging.debug(" ... ... COMPFLAGS: {}".format(compiler_subs["COMPFLAGS"])) - # Environment variables + # MODULEPATH must be set before the module loads, https://github.com/JCSDA/spack-stack/issues/2144 + compiler_modulepaths = "" if "environment" in compiler.extra_attributes.keys(): for action in compiler.extra_attributes["environment"].keys(): for env_name in compiler.extra_attributes["environment"][action]: @@ -432,12 +433,16 @@ def setup_meta_modules(): env_values = None else: env_values = compiler.extra_attributes["environment"][action][env_name] - compiler_subs["ENVVARS"] += envmod_command( + command = envmod_command( module_choice, action, env_name, env_values ) + if env_name == "MODULEPATH": + compiler_modulepaths += command + else: + compiler_subs["ENVVARS"] += command # https://github.com/JCSDA/spack-stack/issues/1903 # Attempt to locate directory "compiler" in the same directory where # "icx" resides. If found, add it to PATH in the compiler module @@ -455,6 +460,7 @@ def setup_meta_modules(): # Spack compiler module hierarchy - append all saved modulepaths for modulepath in MODULEPATHS_SAVE: compiler_subs["MODULEPATHS"] += modulepath_prepend_command(module_choice, modulepath) + compiler_subs["MODULEPATHS"] += compiler_modulepaths compiler_subs["MODULEPATHS"] = compiler_subs["MODULEPATHS"].rstrip("\n") logging.debug(" ... ... MODULEPATHS : {}".format(compiler_subs["MODULEPATHS"])) diff --git a/spack-ext/lib/spack-stack/tests/test_setup_meta_modules.py b/spack-ext/lib/spack-stack/tests/test_setup_meta_modules.py index f62cf95da8..381b44c0c1 100644 --- a/spack-ext/lib/spack-stack/tests/test_setup_meta_modules.py +++ b/spack-ext/lib/spack-stack/tests/test_setup_meta_modules.py @@ -59,6 +59,8 @@ def test_setup_meta_modules(): environment: unset: - DUMMYVAR + prepend_path: + MODULEPATH: /opt/test-compiler-modulefiles mpi: buildable: false openmpi: @@ -89,6 +91,15 @@ def test_setup_meta_modules(): f"Expected module {expected_comp_meta_module} not found" ) + # The compiler's MODULEPATH must be set before the module loads that need it + with open(expected_comp_meta_module) as f: + comp_meta_module = f.read() + modulepath_line = "prepend-path {MODULEPATH} {/opt/test-compiler-modulefiles}" + load_line = "module load gcc/11.5.0" + assert modulepath_line in comp_meta_module + assert load_line in comp_meta_module + assert comp_meta_module.index(modulepath_line) < comp_meta_module.index(load_line) + expected_mpi_meta_module = os.path.join(module_dir, "gcc", "11.5.0", "stack-openmpi", "5.0.8") assert( os.path.exists(expected_mpi_meta_module),