Skip to content

Commit ad0893c

Browse files
committed
more edits
1 parent c89aa2c commit ad0893c

2 files changed

Lines changed: 69 additions & 120 deletions

File tree

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
1-
$ spack spec json-fortran%clang@14.0.0-gfortran
2-
Input spec
3-
--------------------------------
4-
- json-fortran%clang@14.0.0-gfortran
5-
6-
Concretized
7-
--------------------------------
8-
- json-fortran@8.3.0%clang@14.0.0-gfortran cppflags="-g" ~ipo build_system=cmake build_type=Release generator=make arch=linux-ubuntu22.04-x86_64_v3
9-
- ^cmake@3.27.7%clang@14.0.0-gfortran cppflags="-g" ~doc+ncurses+ownlibs build_system=generic build_type=Release arch=linux-ubuntu22.04-x86_64_v3
10-
- ^curl@8.4.0%clang@14.0.0-gfortran cppflags="-g" ~gssapi~ldap~libidn2~librtmp~libssh~libssh2+nghttp2 build_system=autotools libs=shared,static tls=openssl arch=linux-ubuntu22.04-x86_64_v3
11-
- ^nghttp2@1.57.0%clang@14.0.0-gfortran cppflags="-g" build_system=autotools arch=linux-ubuntu22.04-x86_64_v3
12-
- ^openssl@3.1.3%clang@14.0.0-gfortran cppflags="-g" ~docs+shared build_system=generic certs=mozilla arch=linux-ubuntu22.04-x86_64_v3
13-
- ^ca-certificates-mozilla@2023-05-30%clang@14.0.0-gfortran cppflags="-g" build_system=generic arch=linux-ubuntu22.04-x86_64_v3
14-
- ^perl@5.38.0%clang@14.0.0-gfortran cppflags="-g" +cpanm+opcode+open+shared+threads build_system=generic patches=714e4d1 arch=linux-ubuntu22.04-x86_64_v3
15-
- ^berkeley-db@18.1.40%clang@14.0.0-gfortran cppflags="-g" +cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-ubuntu22.04-x86_64_v3
16-
- ^bzip2@1.0.8%clang@14.0.0-gfortran cppflags="-g" ~debug~pic+shared build_system=generic arch=linux-ubuntu22.04-x86_64_v3
17-
- ^diffutils@3.9%clang@14.0.0-gfortran cppflags="-g" build_system=autotools arch=linux-ubuntu22.04-x86_64_v3
18-
- ^libiconv@1.17%clang@14.0.0-gfortran cppflags="-g" build_system=autotools libs=shared,static arch=linux-ubuntu22.04-x86_64_v3
19-
- ^gdbm@1.23%clang@14.0.0-gfortran cppflags="-g" build_system=autotools arch=linux-ubuntu22.04-x86_64_v3
20-
- ^readline@8.2%clang@14.0.0-gfortran cppflags="-g" build_system=autotools patches=bbf97f1 arch=linux-ubuntu22.04-x86_64_v3
21-
- ^pkgconf@1.9.5%clang@14.0.0-gfortran cppflags="-g" build_system=autotools arch=linux-ubuntu22.04-x86_64_v3
22-
- ^ncurses@6.4%clang@14.0.0-gfortran cppflags="-g" ~symlinks+termlib abi=none build_system=autotools arch=linux-ubuntu22.04-x86_64_v3
23-
- ^zlib-ng@2.1.4%clang@14.0.0-gfortran cppflags="-g" +compat+opt build_system=autotools arch=linux-ubuntu22.04-x86_64_v3
24-
- ^gmake@4.4.1%clang@14.0.0-gfortran cppflags="-g" ~guile build_system=generic arch=linux-ubuntu22.04-x86_64_v3
1+
$ spack spec zlib%gcc@11.4.0
2+
- zlib@1.3.1 cppflags=-g +optimize+pic+shared build_system=makefile arch=linux-ubuntu22.04-x86_64 %c,cxx=gcc@11.4.0
3+
- ^compiler-wrapper@1.0 build_system=generic arch=linux-ubuntu22.04-x86_64
4+
[e] ^gcc@11.4.0~binutils+bootstrap~graphite~nvptx~piclibs~profiled~strip build_system=autotools build_type=RelWithDebInfo languages:='c,c++,fortran' arch=linux-ubuntu22.04-x86_64
5+
- ^gcc-runtime@11.4.0 cppflags=-g build_system=generic arch=linux-ubuntu22.04-x86_64
6+
[e] ^glibc@2.35 build_system=autotools arch=linux-ubuntu22.04-x86_64
7+
- ^gmake@4.4.1 cppflags=-g ~guile build_system=generic arch=linux-ubuntu22.04-x86_64 %c=gcc@11.4.0

tutorial_configuration.rst

Lines changed: 62 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Compiler Configuration
211211
For most tasks, we can use Spack with the compilers auto-detected the first time Spack runs on a system.
212212
As discussed in the basic installation tutorial, we can also tell Spack where compilers are located using the ``spack compiler add`` command.
213213
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.
215215

216216
We will start by opening the compilers configuration (which lives in the packages section):
217217

@@ -252,56 +252,34 @@ We start with no active environment, so this will open a ``packages.yaml`` file
252252
253253
This specifies two versions of the GCC compiler and one version of the Clang compiler with no Flang compiler.
254254
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:
288256

289257
.. code-block:: console
290258
291-
$ spack install --no-cache zlib %clang@14.0.0-gfortran
292-
...
259+
$ spack config edit toolchains
293260
261+
.. code-block:: yaml
262+
263+
toolchains:
264+
clang_gfortran:
265+
- spec: '%c=llvm@14.0.0'
266+
when: '%c'
267+
- spec: '%cxx=llvm@14.0.0'
268+
when: '%cxx'
269+
- spec: '%fortran=gcc@11.4.0'
270+
when: '%fortran'
294271
295-
This new compiler also works on Fortran codes.
296-
We'll show this by compiling a small package using ``cmake%gcc@11.4.0`` as a build dependency, since it is already available in our binary cache:
272+
We are essentially saying "use Clang for c/c++, and use GCC for Fortran".
273+
You can use this new entry like so:
297274

298275
.. code-block:: console
299276
300-
$ spack install --reuse cmake %gcc@11.4.0
301-
...
302-
$ spack install --no-cache --reuse json-fortran %clang@=14.0.0-gfortran ^cmake%gcc@11.4.0
303-
...
277+
$ spack spec openblas %clang_gfortran
278+
279+
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).
304281

282+
.. These sections specify when Spack can use different compilers, and are primarily useful for configuration files that will be used across multiple systems.
305283
306284
^^^^^^^^^^^^^^
307285
Compiler flags
@@ -315,22 +293,20 @@ As on the command line, the flags are set through the implicit build variables `
315293
Let's open our compilers configuration file again and add a compiler flag:
316294

317295
.. 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
334310
335311
336312
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
341317

342318
We can see that ``cppflags="-g"`` has been added to every node in the DAG.
343319

320+
.. It even added it to gcc-runtime, hmm...
321+
344322
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
345323
Advanced compiler configuration
346324
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
347325

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:
351327

352328
.. code-block:: yaml
329+
:emphasize-lines: 6-7, 15-19
353330
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
361350
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")
363353
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.
370356

371357
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.
384359
In addition to ``set``, ``environment`` also supports ``unset``, ``prepend_path``, and ``append_path``.
385360

386361
The ``extra_rpaths`` field of the compiler configuration is used for compilers that do not rpath all of their dependencies by default.
387362
Since compilers are often installed externally to Spack, Spack is unable to manage compiler dependencies and enforce rpath usage.
388363
This can lead to packages not finding link dependencies imposed by the compiler properly.
389364
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.
390365
The executables will then be able to find the link dependencies imposed by the compiler.
391-
As an example, this field can be set by:
392-
393-
.. code-block:: yaml
394-
395-
- compiler:
396-
...
397-
extra_rpaths:
398-
- /apps/intel/ComposerXE2017/compilers_and_libraries_2017.5.239/linux/compiler/lib/intel64_lin
399-
...
400366

401367

402368
.. _configs-tutorial-package-prefs:

0 commit comments

Comments
 (0)