Add clang spec.
parent
6ced63df3b
commit
27bc9f7283
|
@ -0,0 +1,3 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
cp -r template/. "$OUT"
|
|
@ -0,0 +1,8 @@
|
|||
BasedOnStyle: Google
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
BinPackArguments: false
|
||||
BinPackParameters: false
|
||||
ColumnLimit: 80
|
||||
ContinuationIndentWidth: 2
|
||||
IndentCaseLabels: false
|
||||
IndentWidth: 2
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if command -v git > /dev/null && on_git_branch; then
|
||||
git config --local core.hooksPath .githooks/
|
||||
fi
|
||||
|
||||
use flake
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
filesToFormat=$(
|
||||
git --no-pager diff --name-status --no-color --cached | \
|
||||
awk '$1 != "D" && $2 ~ /\.c$|\.h$/ {print $NF}'
|
||||
)
|
||||
|
||||
for path in $filesToFormat
|
||||
do
|
||||
clang-format -i "$path"
|
||||
git add "$path"
|
||||
done;
|
|
@ -0,0 +1,17 @@
|
|||
# Directory used by clangd LSP.
|
||||
.cache/
|
||||
|
||||
# Directory used by `direnv` to hold `use flake`-generated profiles.
|
||||
.direnv/
|
||||
|
||||
# The compilation database produced by `bear`.
|
||||
compile_commands.json
|
||||
|
||||
# The directory containing all build outputs.
|
||||
dist/
|
||||
|
||||
# The directory generated by `Doxygen`.
|
||||
docs/
|
||||
|
||||
# A symlink produced by default when running `nix build`.
|
||||
result
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,53 @@
|
|||
# Clang Flake Template
|
||||
|
||||
This is a template for constructing a working environment for C development with
|
||||
the [clang](https://clang.llvm.org/) (version 16.0.6) toolchain.
|
||||
|
||||
[direnv](https://direnv.net/) can be used to launch a dev shell upon entering
|
||||
this directory (refer to `.envrc`). Otherwise, run via:
|
||||
```bash
|
||||
nix develop
|
||||
```
|
||||
|
||||
## Language Server
|
||||
|
||||
The [clangd](https://clangd.llvm.org/) LSP (version 14.0.6) is included in this
|
||||
flake. The [codelldb](https://github.com/vadimcn/codelldb) VSCode plugin is also
|
||||
included to interface with the LSP. Note this plugin, despite its name, is
|
||||
compatible with other editors (e.g. neovim). To configure, refer to your
|
||||
editor's documentation.
|
||||
|
||||
To use the LSP across files, a [compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html)
|
||||
must be generated. For this reason, [bear](https://github.com/rizsotto/Bear)
|
||||
(version 3.1.3) is included in this flake. Use as follows to generate a
|
||||
`compile_commands.json` file:
|
||||
```bash
|
||||
$> bear -- <your-build-command>
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation is generated using [Doxygen](https://www.doxygen.nl/index.html)
|
||||
(version 1.9.7). The included Doxyfile was generated by running:
|
||||
```bash
|
||||
$> doxygen -g
|
||||
```
|
||||
(Re)generate documentation by editing the `Doxyfile` and running:
|
||||
```bash
|
||||
$> doxygen
|
||||
```
|
||||
|
||||
## Formatting
|
||||
|
||||
Formatting depends on the [clang-format](https://clang.llvm.org/docs/ClangFormat.html)
|
||||
(version 14.0.6) tool. Refer to `.clang-format` for default formatting options.
|
||||
A `pre-commit` hook is included in `.githooks` that can be used to format all
|
||||
`*.c$` and `*.h$` files prior to commit. Install via:
|
||||
```bash
|
||||
$> git config --local core.hooksPath .githooks/
|
||||
```
|
||||
If running [direnv](https://direnv.net/), this hook is installed automatically.
|
||||
|
||||
## Direnv
|
||||
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
(import
|
||||
(
|
||||
let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in
|
||||
fetchTarball {
|
||||
url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
|
||||
sha256 = lock.nodes.flake-compat.locked.narHash;
|
||||
}
|
||||
)
|
||||
{ src = ./.; }
|
||||
).defaultNix
|
|
@ -0,0 +1,76 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-compat": {
|
||||
"locked": {
|
||||
"lastModified": 1696426674,
|
||||
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
|
||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||
"revCount": 57,
|
||||
"type": "tarball",
|
||||
"url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz"
|
||||
},
|
||||
"original": {
|
||||
"type": "tarball",
|
||||
"url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"
|
||||
}
|
||||
},
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1694529238,
|
||||
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1700794826,
|
||||
"narHash": "sha256-RyJTnTNKhO0yqRpDISk03I/4A67/dp96YRxc86YOPgU=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5a09cb4b393d58f9ed0d9ca1555016a8543c2ac8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nixos",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-compat": "flake-compat",
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
description = ''
|
||||
An opinionated clang flake.
|
||||
|
||||
To generate a copy of this template elsewhere, run:
|
||||
$> bootstrap clang
|
||||
'';
|
||||
|
||||
inputs = {
|
||||
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, ... }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
|
||||
codelldb = pkgs.writeShellScriptBin "codelldb" ''
|
||||
exec ${pkgs.vscode-extensions.vadimcn.vscode-lldb}/share/vscode/extensions/vadimcn.vscode-lldb/adapter/codelldb "$@"
|
||||
'';
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell.override {
|
||||
# https://nixos.wiki/wiki/Using_Clang_instead_of_GCC
|
||||
stdenv = pkgs.clangStdenv;
|
||||
} {
|
||||
packages = with pkgs; [
|
||||
bear
|
||||
clang-tools
|
||||
codelldb
|
||||
doxygen
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char *argv[argc + 1]) { return EXIT_SUCCESS; }
|
Loading…
Reference in New Issue