Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: pre-commit

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install pre-commit
run: pip install pre-commit

- name: Run pre-commit
run: pre-commit run --all-files
21 changes: 21 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Exclude git submodules from all hooks
exclude: |
(?x)^(
test/benchmark/CGRA-Bench/.*|
test/benchmark/Zeonica_Testbench/.*
)$

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v20.1.7
hooks:
- id: clang-format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we able to set style = Google?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can change the code style to Google by modifying the .clang-format with clang-format --style=Google --dump-config > .clang-format

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will transition from the LLVM code style to the Google code style.

CC @n0thingNoob @ShangkunLi @HobbitQia @YanzhouTang @guosran @MeowMJ

types_or: [c++, c]
41 changes: 40 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,43 @@ To follow this style, you can use `clang-format` to generate the format configur
$ clang-format -style=LLVM -dump-config > .clang-format
```

Then use some format extentions in your editor to enable automatic code formatting (e.g., `clangd` in VS Code).
Then use some format extentions in your editor to enable automatic code formatting (e.g., `clangd` in VS Code).

## Pre-commit Hooks

We use [pre-commit](https://pre-commit.com/) to automatically format code and check files before committing. This ensures consistent code style and catches common issues early.

### Setup

Install pre-commit and set up the git hooks:

```sh
pip install pre-commit
pre-commit install
pre-commit install --hook-type pre-commit
```

### What it does

The pre-commit hooks will automatically:
- Format C/C++ code using `clang-format` (with the project's `.clang-format` configuration)
- Remove trailing whitespace
- Ensure files end with a newline
- Validate YAML syntax
- Prevent committing large files

### How it works

Once installed, pre-commit hooks run automatically on your staged files every time you run `git commit`. If any issues are found, the commit will be interrupted and the hooks will attempt to fix them. You can then stage the fixed files and commit again.

### Running manually

To run pre-commit on all files manually (useful for initial setup or checking the entire codebase):

```sh
pre-commit run --all-files
```

This is typically only needed when you first set up pre-commit or want to check files that weren't part of a commit.

Please ensure your code passes all pre-commit checks before submitting a pull request.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,28 @@ Build LLVM & Neura
$ /workspace/llvm-project/build/bin/llvm-lit test.mlir -v
```

Code Formatting with Pre-commit
--------------------------------------------------------
This project uses [pre-commit](https://pre-commit.com/) to automatically format code and check files before committing.

### Setup

```sh
pip install pre-commit
pre-commit install
pre-commit install --hook-type pre-commit
```

Once installed, pre-commit hooks run automatically on your staged files every time you run `git commit`.

To manually check the entire codebase:

```sh
pre-commit run --all-files
```

See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.

Sync `test/e2e` outputs into Zeonica_Testbench (submodule)
--------------------------------------------------------
This repo vendors [`sarchlab/Zeonica_Testbench`](https://github.com/sarchlab/Zeonica_Testbench.git) as a git submodule at `test/benchmark/Zeonica_Testbench`.
Expand Down
Loading