@@ -25,11 +25,13 @@ Also, note that the `--style` flag can also fully define the options without
25
25
the configuration file as follows, but this is not recommended as the
26
26
configuration could change before this guide is updated to reflect as such.
27
27
28
+ <!-- markdownlint-disable MD046 MD013 -->
28
29
??? Danger "Terminal One-(long-)liner"
29
30
30
31
```bash {.copy}
31
32
clang-format [-i] --style="{BasedOnStyle: llvm, ColumnLimit: 100, AlignConsecutiveAssignments: true, AlignConsecutiveBitFields: true, AlignConsecutiveMacros: true, AlignEscapedNewlines: true, AlignTrailingComments: true}" <path/to/c++/source/file(s)>
32
33
```
34
+ <!-- markdownlint-enable MD046 MD013 -->
33
35
34
36
## Installing ` clang-format `
35
37
@@ -39,6 +41,7 @@ building `llvm v14` from scratch.
39
41
If you are a non-admin user of a multi-user cluster, HPC platform, etc., then
40
42
it is likely to be an *** easy*** process, though potentially not immediate.
41
43
44
+ <!-- markdownlint-disable MD046 -->
42
45
??? Note "If you require or already have multiple versions of ` clang-format ` installed"
43
46
44
47
Note that, depending on your requirements, this could be placed in your shell
@@ -73,24 +76,27 @@ it is likely to be an ***easy*** process, though potentially not immediate.
73
76
$ which clang-format
74
77
/usr/local/bin/clang-format-14
75
78
```
79
+ <!-- markdownlint-enable MD046 -->
76
80
77
81
=== "Personal Machine"
78
-
82
+
83
+ <!-- markdownlint-disable MD046 -->
79
84
=== "Mac Users (Homebrew Package Manager)"
80
-
85
+
81
86
For Mac users, the [Homebrew](https://brew.sh)
82
- package manager (` brew ` ) is the quickest and most straightforward way to get
83
- ` clang-format ` installed.
84
- Since ` clang-format ` v14 is not available to install directly from Homebrew, we
85
- install the entire LLVM package at version 14, and this is as simple as
86
-
87
+ package manager (`brew`) is the quickest and most straightforward way
88
+ to get `clang-format` installed.
89
+ Since `clang-format` v14 is not available to install directly from
90
+ Homebrew, we install the entire LLVM package at version 14, and this
91
+ is as simple as
92
+
87
93
```bash {.copy}
88
94
brew install llvm@14
89
95
```
90
-
96
+
91
97
It it likely that Homebrew will issue a message about not linking the
92
98
`clang`-related tools by default, so next we add the binary to our `PATH`.
93
-
99
+
94
100
```bash {.copy}
95
101
$ export PATH="/opt/homebrew/opt/llvm@14/bin/clang-format:$PATH"
96
102
# Note: this is the default location for a recent Mac running Apple silicon.
@@ -99,49 +105,50 @@ it is likely to be an ***easy*** process, though potentially not immediate.
99
105
$ which clang-format
100
106
/opt/homebrew/opt/llvm@14/bin/clang-format
101
107
```
102
-
108
+
103
109
Note also, that if your system has multiple version of `clang-format` installed,
104
110
it may be preferable to instead set a versioned alias to `clang-format`
105
111
(`clang-format-14`) as in
106
-
112
+
107
113
```c++
108
114
// create a shell-alias
109
115
alias clang-format-14="/opt/homebrew/opt/llvm@14/bin/clang-format"
110
116
```
111
-
117
+
112
118
=== "Linux Users (Package Manager)"
113
-
119
+
114
120
Given the many flavors of Linux, it is difficult to generalize, but there
115
121
is a high probability the proper version of `clang-format` or `llvm` is
116
122
provided by the built-in package manager.
117
123
The commands will differ based on your Linux distribution, but using the
118
124
Debian/Ubuntu `apt` syntax, it could be accomplished via something like
119
-
125
+
120
126
```bash {.copy}
121
127
$ apt search clang-format
122
128
[...]
123
129
clang-format-14/...
124
130
$ apt install clang-format-14
125
131
```
126
-
132
+
127
133
=== "Build from Source"
128
-
129
- If you do not succeed in the above, ` clang-format ` can also be fully built
130
- from the [ LLVM Compiler Infrastructure] ( https://github.com/llvm/llvm-project ) .
131
- It will begin with something like
132
-
133
- ```bash {.copy}
134
- git clone git@github.com : llvm /llvm-project.git
135
- git checkout llvmorg-14.0.6 # version tag
136
- ```
137
-
138
- Also, if you only need ` clang-format ` and not any of the other tooling,
139
- it will build faster/smaller if you use the CMake flag
140
- ` -DLLVM_ENABLE_PROJECTS="clang" ` to only build ` clang ` and it's friends,
141
- rather than all of ` llvm ` .
142
- And finally, the README for [ LLVM version 14.0.6] ( https://github.com/llvm/llvm-project/tree/llvmorg-14.0.6 )
143
- is far more comprehensive that the one for the latest version, and it contains
144
- instructions specific to that build.
134
+
135
+ If you do not succeed in the above, `clang-format` can also be fully built
136
+ from the [LLVM Compiler Infrastructure](https://github.com/llvm/llvm-project).
137
+ It will begin with something like
138
+
139
+ ```bash {.copy}
140
+ git clone git@github.com:llvm/llvm-project.git
141
+ git checkout llvmorg-14.0.6 # version tag
142
+ ```
143
+
144
+ Also, if you only need `clang-format` and not any of the other tooling,
145
+ it will build faster/smaller if you use the CMake flag
146
+ `-DLLVM_ENABLE_PROJECTS="clang"` to only build `clang` and it's friends,
147
+ rather than all of `llvm`.
148
+ And finally, the README for [LLVM version 14.0.6](https://github.com/llvm/llvm-project/tree/llvmorg-14.0.6)
149
+ is far more comprehensive that the one for the latest version, and it contains
150
+ instructions specific to that build.
151
+ <!-- markdownlint-enable MD046 -->
145
152
146
153
=== "Multi-user System"
147
154
@@ -160,6 +167,7 @@ administrator to get an official version installed.[^but-conda]
160
167
161
168
---
162
169
170
+ <!-- markdownlint-disable MD046 -->
163
171
??? Tip "Unnecessary but Convenient Workflow Customization (` direnv ` )"
164
172
165
173
If you'd like to add a layer of automation/complexity to ensure you only use
@@ -170,10 +178,10 @@ administrator to get an official version installed.[^but-conda]
170
178
environment variables based on `$PWD` using a `.envrc` file.
171
179
As an example, here's my `.envrc` that adds `clang-format v14` to the path
172
180
when I'm working on `EAMxx`.
173
-
181
+
174
182
```bash {.copy}
175
183
PATH_add /opt/homebrew/opt/llvm@14/bin/clang-format
176
-
184
+
177
185
# also, since I often forget to load a python environment that's required for
178
186
# running ctest, this creates or loads a python 3 virtual environment with numpy
179
187
layout python3
@@ -182,16 +190,17 @@ administrator to get an official version installed.[^but-conda]
182
190
# the front end to avoid pip endlessly reminding you to update
183
191
pip install numpy
184
192
```
185
-
193
+
186
194
This file can be placed in the top-level `EAMxx` directory, and running
187
195
`direnv allow` enables the functionality.
188
196
Namely, executing `cd EAMxx` loads the defined environment that stays loaded
189
197
in any subdirectories, and resets the standard environment when exiting to a
190
198
directory above/outside of `EAMxx`.
191
-
199
+
192
200
For the `conda` fans, this tool can also be used to auto-load a
193
201
pre-configured `conda` environment since the `.envrc` is essentially a bash
194
202
script with a few bells and whistles tacked on.
203
+ <!-- markdownlint-enable MD046 -->
195
204
196
205
[ ^ but-conda ] : There are rumors of using ` conda ` creatively to do a user-install,
197
206
but that is not an option we support or suggest.
0 commit comments