You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorial_configuration.rst
+62-96Lines changed: 62 additions & 96 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,7 +211,7 @@ Compiler Configuration
211
211
For most tasks, we can use Spack with the compilers auto-detected the first time Spack runs on a system.
212
212
As discussed in the basic installation tutorial, we can also tell Spack where compilers are located using the ``spack compiler add`` command.
213
213
However, in some circumstances, we want even more fine-grained control over the compilers available.
214
-
This section will teach you how to exercise that control using the compilers configuration file.
214
+
This section will teach you how to exercise that control using the compilers configuration.
215
215
216
216
We will start by opening the compilers configuration (which lives in the packages section):
217
217
@@ -252,56 +252,34 @@ We start with no active environment, so this will open a ``packages.yaml`` file
252
252
253
253
This specifies two versions of the GCC compiler and one version of the Clang compiler with no Flang compiler.
254
254
Now suppose we have a code that we want to compile with the Clang compiler for C/C++ code, but with gfortran for Fortran components.
255
-
We can do this by adding another entry to the ``compilers.yaml`` file:
256
-
257
-
.. code-block:: yaml
258
-
:emphasize-lines: 2,6-7
259
-
260
-
- compiler:
261
-
spec: clang@=14.0.0-gfortran
262
-
paths:
263
-
cc: /usr/bin/clang
264
-
cxx: /usr/bin/clang++
265
-
f77: /usr/bin/gfortran
266
-
fc: /usr/bin/gfortran
267
-
flags: {}
268
-
operating_system: ubuntu22.04
269
-
target: x86_64
270
-
modules: []
271
-
environment: {}
272
-
extra_rpaths: []
273
-
274
-
275
-
Let's talk about the sections of this compiler entry that we've changed.
276
-
The biggest change we've made is to the ``paths`` section.
277
-
This lists the paths to the compilers to use for each language/specification.
278
-
In this case, we point to the Clang compiler for C/C++ and the gfortran compiler for both specifications of Fortran.
279
-
We've also changed the ``spec`` entry for this compiler.
280
-
The ``spec`` entry is effectively the name of the compiler for Spack.
281
-
It consists of a name and a version number, separated by the ``@`` sigil.
282
-
The name must be one of the supported compiler names in Spack (aocc, apple-clang, arm, cce, clang, dpcpp, fj, gcc, intel, msvc, nag, nvhpc, oneapi, pgi, rocmcc, xl, xl_r).
283
-
The version number can be an arbitrary string of alphanumeric characters, as well as ``-``, ``.``, and ``_``.
284
-
The ``target`` and ``operating_system`` sections we leave unchanged.
285
-
These sections specify when Spack can use different compilers, and are primarily useful for configuration files that will be used across multiple systems.
286
-
287
-
We can verify that our new compiler works by invoking it now:
255
+
We can do this by adding creating a toolchain config:
Note the identifier `clang_gfortran` is not itself a spec (you don't version it). You reference it in other specs.
280
+
Note that without `when: '%fortran'`, you could not use `clang_gfortran` with packages unless they depended on Fortran (likewise for the `when` statements on c/cxx).
304
281
282
+
.. These sections specify when Spack can use different compilers, and are primarily useful for configuration files that will be used across multiple systems.
305
283
306
284
^^^^^^^^^^^^^^
307
285
Compiler flags
@@ -315,22 +293,20 @@ As on the command line, the flags are set through the implicit build variables `
315
293
Let's open our compilers configuration file again and add a compiler flag:
316
294
317
295
.. code-block:: yaml
318
-
:emphasize-lines: 8-9
319
-
320
-
- compiler:
321
-
spec: clang@=14.0.0-gfortran
322
-
paths:
323
-
cc: /usr/bin/clang
324
-
cxx: /usr/bin/clang++
325
-
f77: /usr/bin/gfortran
326
-
fc: /usr/bin/gfortran
327
-
flags:
328
-
cppflags: -g
329
-
operating_system: ubuntu22.04
330
-
target: x86_64
331
-
modules: []
332
-
environment: {}
333
-
extra_rpaths: []
296
+
:emphasize-lines: 11-12
297
+
298
+
packages:
299
+
gcc:
300
+
externals:
301
+
- spec: gcc@11.4.0 languages:='c,c++,fortran'
302
+
prefix: /usr
303
+
extra_attributes:
304
+
compilers:
305
+
c: /usr/bin/gcc
306
+
cxx: /usr/bin/g++
307
+
fortran: /usr/bin/gfortran
308
+
flags:
309
+
cppflags: -g
334
310
335
311
336
312
We can test this out using the ``spack spec`` command to show how the spec is concretized:
@@ -341,62 +317,52 @@ We can test this out using the ``spack spec`` command to show how the spec is co
341
317
342
318
We can see that ``cppflags="-g"`` has been added to every node in the DAG.
343
319
320
+
.. It even added it to gcc-runtime, hmm...
321
+
344
322
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
345
323
Advanced compiler configuration
346
324
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
347
325
348
-
There are four fields of the compiler configuration entry that we have not yet talked about.
349
-
350
-
The ``target`` field of the compiler defines the cpu architecture **family** that the compiler supports.
326
+
Some additional fields not discussed yet, in an example:
351
327
352
328
.. code-block:: yaml
329
+
:emphasize-lines: 6-7, 15-19
353
330
354
-
- compiler:
355
-
...
356
-
target: ppc64le
357
-
...
358
-
359
-
The ``modules`` field of the compiler was originally designed to support older Cray systems, but can be useful on any system that has compilers that are only usable when a particular module is loaded.
360
-
Any modules in the ``modules`` field of the compiler configuration will be loaded as part of the build environment for packages using that compiler:
331
+
packages:
332
+
gcc:
333
+
externals:
334
+
- spec: gcc@11.4.0 languages:='c,c++,fortran'
335
+
prefix: /usr
336
+
modules:
337
+
- gcc/11.4.0
338
+
extra_attributes:
339
+
compilers:
340
+
c: /usr/bin/gcc
341
+
cxx: /usr/bin/g++
342
+
fortran: /usr/bin/gfortran
343
+
flags:
344
+
cppflags: -g
345
+
extra_rpaths:
346
+
- /a/path/to/somewhere/important
347
+
environment:
348
+
set:
349
+
EG_A_LICENSE_FILE: 1713@license4
361
350
362
-
.. code-block:: yaml
351
+
.. The ``target`` field of the compiler defines the cpu architecture **family** that the compiler supports.
352
+
.. (target isn't in the compiler schema in packages anymore: how do we say "target generic x86_64 whenever you use this compiler")
363
353
364
-
- compiler:
365
-
...
366
-
modules:
367
-
- PrgEnv-gnu
368
-
- gcc/5.3.0
369
-
...
354
+
The ``modules`` field of the compiler was originally designed to support older Cray systems, but can be useful on any system that has compilers that are only usable when a particular module is loaded.
355
+
Any modules in the ``modules`` field of the compiler configuration will be loaded as part of the build environment for packages using that compiler.
370
356
371
357
The ``environment`` field of the compiler configuration is used for compilers that require environment variables to be set during build time.
372
-
For example, if your Intel compiler suite requires the ``INTEL_LICENSE_FILE`` environment variable to point to the proper license server, you can set this in ``compilers.yaml`` as follows:
373
-
374
-
.. code-block:: yaml
375
-
376
-
- compiler:
377
-
...
378
-
environment:
379
-
set:
380
-
INTEL_LICENSE_FILE: 1713@license4
381
-
...
382
-
383
-
358
+
For example, if your Intel compiler suite requires the ``INTEL_LICENSE_FILE`` environment variable to point to the proper license server.
384
359
In addition to ``set``, ``environment`` also supports ``unset``, ``prepend_path``, and ``append_path``.
385
360
386
361
The ``extra_rpaths`` field of the compiler configuration is used for compilers that do not rpath all of their dependencies by default.
387
362
Since compilers are often installed externally to Spack, Spack is unable to manage compiler dependencies and enforce rpath usage.
388
363
This can lead to packages not finding link dependencies imposed by the compiler properly.
389
364
For compilers that impose link dependencies on the resulting executables that are not rpath'ed into the executable automatically, the ``extra_rpaths`` field of the compiler configuration tells Spack which dependencies to rpath into every executable created by that compiler.
390
365
The executables will then be able to find the link dependencies imposed by the compiler.
0 commit comments