Run ./scripts/fmt_all.sh in CI (#2290)

* pppp

* fix

* xx

* add clang18

* fix

* chg

* purge existing clang..

* tmate

* trigger

* bruh

* finally..

* Don't fmt when not in cargo-fmt

* fix

* aaaaaa

* fuck
This commit is contained in:
Dongjia "toka" Zhang 2024-06-08 01:41:39 +02:00 committed by GitHub
parent 1e2fac6f53
commit e99fcad326
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 46 additions and 35 deletions

View File

@ -117,7 +117,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: ./.github/workflows/ubuntu-prepare - uses: ./.github/workflows/ubuntu-prepare
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- name: Add nightly rustfmt and clippy - name: Add nightly clippy
run: rustup toolchain install nightly --component miri --allow-downgrade run: rustup toolchain install nightly --component miri --allow-downgrade
# --- miri undefined behavior test -- # --- miri undefined behavior test --
- name: Run miri tests - name: Run miri tests
@ -136,22 +136,19 @@ jobs:
run: sudo apt purge llvm* clang* lld* lldb* opt* run: sudo apt purge llvm* clang* lld* lldb* opt*
- name: Install and cache deps - name: Install and cache deps
run: sudo apt update && sudo apt install ninja-build shellcheck libgtk-3-dev gcc-arm-linux-gnueabi g++-arm-linux-gnueabi libslirp-dev libz3-dev run: sudo apt update && sudo apt install ninja-build shellcheck libgtk-3-dev gcc-arm-linux-gnueabi g++-arm-linux-gnueabi libslirp-dev libz3-dev
- name: Add nightly rustfmt and clippy - name: Add nightly clippy
run: rustup toolchain install nightly --component rustfmt --component clippy --component miri --allow-downgrade run: rustup toolchain install nightly --component clippy --component miri --allow-downgrade
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: { shared-key: "ubuntu" } with: { shared-key: "ubuntu" }
- name: Install LLVM and Clang - name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1 uses: KyleMayes/install-llvm-action@v2
with: with:
directory: ${{ runner.temp }}/llvm directory: ${{ runner.temp }}/llvm
version: 17 version: 17
# ---- format check ----
# pcguard edges and pcguard hitcounts are not compatible and we need to build them seperately # pcguard edges and pcguard hitcounts are not compatible and we need to build them seperately
- name: Check pcguard edges - name: Check pcguard edges
run: cargo check --features=sancov_pcguard_edges run: cargo check --features=sancov_pcguard_edges
- name: Run clang-format style check for C/C++ programs.
run: clang-format -n -Werror --style=file $(find . -type f \( -name '*.cpp' -o -iname '*.hpp' -o -name '*.cc' -o -name '*.cxx' -o -name '*.cc' -o -name '*.h' \) | grep -v '/target/' | grep -v 'libpng-1\.6\.37' | grep -v 'stb_image\.h' | grep -v 'dlmalloc\.c' | grep -v 'QEMU-Nyx')
- name: run shellcheck - name: run shellcheck
run: shellcheck ./scripts/*.sh run: shellcheck ./scripts/*.sh
# ---- build normal and examples ---- # ---- build normal and examples ----
@ -172,19 +169,18 @@ jobs:
- name: Install and cache deps - name: Install and cache deps
run: sudo apt update && sudo apt install ninja-build shellcheck libgtk-3-dev gcc-arm-linux-gnueabi g++-arm-linux-gnueabi libslirp-dev libz3-dev run: sudo apt update && sudo apt install ninja-build shellcheck libgtk-3-dev gcc-arm-linux-gnueabi g++-arm-linux-gnueabi libslirp-dev libz3-dev
- name: Add nightly rustfmt and clippy - name: Add nightly clippy
run: rustup toolchain install nightly --component clippy --allow-downgrade && rustup default nightly run: rustup toolchain install nightly --component clippy --allow-downgrade && rustup default nightly
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
with: { shared-key: "ubuntu" } with: { shared-key: "ubuntu" }
- name: Install LLVM and Clang - name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1 uses: KyleMayes/install-llvm-action@v2
with: with:
directory: ${{ runner.temp }}/llvm directory: ${{ runner.temp }}/llvm
version: 17 version: 17
- name: Run clippy - name: Run clippy
run: ./scripts/clippy.sh run: ./scripts/clippy.sh
# --- test embedding the libafl_libfuzzer_runtime library # --- test embedding the libafl_libfuzzer_runtime library
# Fix me plz # Fix me plz
# - name: Test Build libafl_libfuzzer with embed # - name: Test Build libafl_libfuzzer with embed
@ -234,7 +230,7 @@ jobs:
- name: Remove existing clang and LLVM - name: Remove existing clang and LLVM
run: sudo apt purge llvm* clang* run: sudo apt purge llvm* clang*
- name: Install LLVM and Clang - name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v1 uses: KyleMayes/install-llvm-action@v2
with: with:
directory: ${{ runner.temp }}/llvm directory: ${{ runner.temp }}/llvm
version: 17 version: 17
@ -259,8 +255,15 @@ jobs:
override: true override: true
components: rustfmt components: rustfmt
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Remove existing clang and LLVM
run: sudo apt purge llvm* clang*
- name: Install LLVM and Clang
uses: KyleMayes/install-llvm-action@v2
with:
directory: ${{ runner.temp }}/llvm
version: 17
- name: Format Check - name: Format Check
run: cargo fmt -- --check run: ./scripts/fmt_all.sh check
fuzzers-preflight: fuzzers-preflight:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -386,7 +389,7 @@ jobs:
profile: minimal profile: minimal
toolchain: nightly toolchain: nightly
override: true override: true
components: rustfmt, rust-src components: rust-src
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- name: Add targets - name: Add targets
@ -406,7 +409,7 @@ jobs:
profile: minimal profile: minimal
toolchain: nightly toolchain: nightly
override: true override: true
components: rustfmt, clippy, rust-src components: clippy, rust-src
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
- name: Add targets - name: Add targets
@ -488,8 +491,8 @@ jobs:
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: stable
- name: Add nightly rustfmt and clippy - name: Add nightly clippy
run: rustup toolchain install nightly --component rustfmt --component clippy --allow-downgrade && rustup default nightly run: rustup toolchain install nightly --component clippy --allow-downgrade && rustup default nightly
- name: Install deps - name: Install deps
run: brew install z3 gtk+3 run: brew install z3 gtk+3
- name: Install cxxbridge - name: Install cxxbridge
@ -503,7 +506,7 @@ jobs:
- name: Run Tests - name: Run Tests
run: cargo test run: cargo test
- name: Clippy - name: Clippy
run: cargo +nightly clippy --tests --all run: cargo +nightly clippy --tests --all --exclude libafl_nyx --exclude symcc_runtime --exclude runtime_test
ios: ios:
runs-on: macOS-latest runs-on: macOS-latest

View File

@ -13,12 +13,12 @@ runs:
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: stable
- name: Add stable rustfmt and clippy - name: Add stable clippy
shell: bash shell: bash
run: rustup toolchain install stable --component rustfmt --component clippy --allow-downgrade run: rustup toolchain install stable --component clippy --allow-downgrade
- name: Add nightly rustfmt and clippy - name: Add nightly clippy
shell: bash shell: bash
run: rustup toolchain install nightly --component rustfmt --component clippy --allow-downgrade run: rustup toolchain install nightly --component clippy --allow-downgrade
- name: Add no_std toolchain - name: Add no_std toolchain
shell: bash shell: bash
run: rustup toolchain install nightly-x86_64-unknown-linux-gnu ; rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu run: rustup toolchain install nightly-x86_64-unknown-linux-gnu ; rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu

View File

@ -16,12 +16,12 @@ runs:
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: stable
- name: Add stable rustfmt and clippy - name: Add stable clippy
shell: bash shell: bash
run: rustup toolchain install stable --component rustfmt --component clippy --allow-downgrade run: rustup toolchain install stable --component clippy --allow-downgrade
- name: Add nightly rustfmt and clippy - name: Add nightly clippy
shell: bash shell: bash
run: rustup toolchain install nightly --component rustfmt --component clippy --allow-downgrade run: rustup toolchain install nightly --component clippy --allow-downgrade
- name: Remove obsolete llvm (Linux) - name: Remove obsolete llvm (Linux)
if: runner.os == 'Linux' if: runner.os == 'Linux'
shell: bash shell: bash

View File

@ -49,14 +49,11 @@ do
cd "$fuzzer" || exit 1 cd "$fuzzer" || exit 1
# Clippy checks # Clippy checks
if [ "$1" != "--no-fmt" ]; then if [ "$1" != "--no-clippy" ]; then
echo "[*] Checking fmt for $fuzzer"
cargo fmt --all -- --check || exit 1
echo "[*] Running clippy for $fuzzer" echo "[*] Running clippy for $fuzzer"
cargo clippy || exit 1 cargo clippy || exit 1
else else
echo "[+] Skipping fmt and clippy for $fuzzer (--no-fmt specified)" echo "[+] Skipping fmt and clippy for $fuzzer (--no-clippy specified)"
fi fi
if [ -e ./Makefile.toml ] && grep -qF "skip_core_tasks = true" Makefile.toml; then if [ -e ./Makefile.toml ] && grep -qF "skip_core_tasks = true" Makefile.toml; then

View File

@ -32,7 +32,10 @@ async fn run_cargo_fmt(path: PathBuf, is_check: bool, verbose: bool) -> io::Resu
if !res.status.success() { if !res.status.success() {
println!("{}", from_utf8(&res.stderr).unwrap()); println!("{}", from_utf8(&res.stderr).unwrap());
return Err(io::Error::new(ErrorKind::Other, "Cargo fmt failed.")); return Err(io::Error::new(
ErrorKind::Other,
format!("Cargo fmt failed. Run cargo fmt for {:#?}", path),
));
} }
Ok(()) Ok(())
@ -88,8 +91,14 @@ struct Cli {
#[tokio::main] #[tokio::main]
async fn main() -> io::Result<()> { async fn main() -> io::Result<()> {
let cli = Cli::parse(); let cli = Cli::parse();
let libafl_root_dir = project_root::get_project_root().expect("Could not locate project root."); let libafl_root_dir = match project_root::get_project_root() {
Ok(p) => p,
Err(_) => std::env::current_dir()
.expect("Failed to get current directory")
.into(),
};
println!("Using {:#?} as the project root", libafl_root_dir);
let rust_excluded_directories = RegexSet::new([ let rust_excluded_directories = RegexSet::new([
r".*target.*", r".*target.*",
r".*utils/noaslr.*", r".*utils/noaslr.*",
@ -107,6 +116,7 @@ async fn main() -> io::Result<()> {
r".*dlmalloc\.c$", r".*dlmalloc\.c$",
r".*QEMU-Nyx.*", r".*QEMU-Nyx.*",
r".*AFLplusplus.*", r".*AFLplusplus.*",
r".*cms_transform_fuzzer.cc.*",
]) ])
.expect("Could not create the regex set from the given regex"); .expect("Could not create the regex set from the given regex");
@ -134,8 +144,9 @@ async fn main() -> io::Result<()> {
tokio_joinset.spawn(run_cargo_fmt(project, cli.check, cli.verbose)); tokio_joinset.spawn(run_cargo_fmt(project, cli.check, cli.verbose));
} }
let (clang, warning) = if which("clang-format-18").is_ok() { let (clang, warning) = if which("clang-format-17").is_ok() {
(Some("clang-format-18"), None) // can't use 18 for ci.
(Some("clang-format-17"), None)
} else if which("clang-format").is_ok() { } else if which("clang-format").is_ok() {
( (
Some("clang-format"), Some("clang-format"),
@ -147,7 +158,7 @@ async fn main() -> io::Result<()> {
Some("clang-format not found. Skipping C formatting..."), Some("clang-format not found. Skipping C formatting..."),
) )
}; };
// println!("Using {:#?} to format...", clang);
if let Some(clang) = clang { if let Some(clang) = clang {
let c_files_to_fmt: Vec<PathBuf> = WalkDir::new(&libafl_root_dir) let c_files_to_fmt: Vec<PathBuf> = WalkDir::new(&libafl_root_dir)
.into_iter() .into_iter()