Skip to content

Commit

Permalink
meta: add clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
64 committed Nov 1, 2024
1 parent eb70663 commit b317855
Show file tree
Hide file tree
Showing 5 changed files with 725 additions and 497 deletions.
33 changes: 33 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
BasedOnStyle: LLVM
Language: Cpp

ColumnLimit: 100
IndentWidth: 4
TabWidth: 4
UseTab: Always

ContinuationIndentWidth: 4
ConstructorInitializerIndentWidth: 4

AlignAfterOpenBracket: BlockIndent

# Put function names + args on their own lines
AlwaysBreakAfterReturnType: All

# Put all initializers onto their own lines.
PackConstructorInitializers: CurrentLine

# Put all function arguments on their own lines.
BinPackArguments: false
BinPackParameters: false

# If control statements are wrapped to multiple lines, we want the { to be on the next line
# to improve readability. Otherwise, it can happen that the line containing the { gets the same
# indentation level as the control statement's body.
BreakBeforeBraces: Custom
BraceWrapping:
AfterControlStatement: MultiLine

# Format braces as {1, 2, 3}, not as { 1, 2, 3 }.
Cpp11BracedListStyle: true
11 changes: 11 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: pre-commit

on: [merge_group, pull_request]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
fail_fast: false
repos:
- repo: https://github.com/pocc/pre-commit-hooks
rev: 336fdd7c3cab698ead0b1c95157b9e74d3906b62
hooks:
- id: clang-format
additional_dependencies: [clang-format==19.1.3]
args: ["-i"]
exclude: >
(?x)^(
options/ansi/musl-generic-math/.*|
options/ansi/generic/complex/.*|
options/posix/musl-generic-regex/.*
)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ The type of library to be built (static, shared, or both) is controlled by meson

We also support building with `-Db_sanitize=undefined` to use UBSan inside mlibc. Note that this does not enable UBSan for external applications which link against `libc.so`, but it can be useful during development to detect internal bugs (e.g when adding new sysdeps).

## Running pre-commit hooks

To format your code before submitting a PR, you should install [`pre-commit`](https://pre-commit.com/). Then do `pre-commit install` to install the git hook which runs each time you commit. Alternatively, you can do `pre-commit run -a` to manually format all files.

## Running Tests

The `mlibc` test suite can be run under a Linux host. To do this, first install a set of kernel headers (as described [here](https://docs.kernel.org/kbuild/headers_install.html)), then run from the project root:
Expand Down
Loading

0 comments on commit b317855

Please sign in to comment.