This document provides a synopsis and loose guidelines for how to contribute to this project. It is a work in progress. Maintainers should expand this document.
This repository includes an opinionated clang-format
specification to ensure that we maintain a common code style. For convenience, a pre-commit hook is also provided in .githooks
which will run clang-format
against any staged changes prior to executing a commit.
clang-format@18
or newer
To set up the pre-commit hook:
git config --local core.hooksPath .githooks/
To run the formatter on the full source tree:
./format.sh
clang-format does not recognize the syntax for inline asm that is required by mwccarm, so it should be disabled for non-matching functions specifically. clang-format accepts directives via comments of the form // clang-format [on|off]
. Example:
#ifdef NONMATCHING
void func() {
// ...
}
#else
// clang-format off
asm void func() {
push {lr}
// ...
pop {pc}
}
// clang-format on
#endif // NONMATCHING
On older versions of Ubuntu, clang-format will default to earlier versions. To install clang-format-18 on Ubuntu (WSL), run the following:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo apt install clang-format-18
And then create a symbolic link:
ln -s /usr/bin/clang-format-18 /usr/bin/clang-format
If you're using the pre-commit hook, you also want to set up a symlink for git:
git config alias.clang-format clang-format-18