Skip to content

bazel: use aspect to run oclint on sources #68

bazel: use aspect to run oclint on sources

bazel: use aspect to run oclint on sources #68

Workflow file for this run

name: Build
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build-host:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
# from https://github.com/bazel-contrib/setup-bazel
- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Share build cache between workflows.
disk-cache: true
# Share repository cache between workflows.
repository-cache: true
- name: Build
run: |
bazel run @hedron_compile_commands//:refresh_all
bazel build //...
- name: Test
run: bazel test //...
lint-host:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
# from https://github.com/bazel-contrib/setup-bazel
- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Share build cache between workflows.
disk-cache: true
# Share repository cache between workflows.
repository-cache: true
- name: bazel-oclint
run: |
shopt -s globstar
make oclint
- name: bazel-dwyu
run: |
bazel build --aspects=//tools:aspect.bzl%your_dwyu_aspect --output_groups=dwyu //... || true
bazel run @depend_on_what_you_use//:apply_fixes -- --fix-all --dry-run
- name: bazel-iwyu
run: |
bazel run --run_under="cd $(bazel info workspace) &&" @multitool//tools/iwyu -- \
-I src/geometry/include src/geometry/rectangle.cc
- name: clang-format
# run clang-format without modifying the files and treat any formatting
# discrepancies as errors, causing the command to return a non-zero exit code
run: |
# running build actions in a sandbox does not seem to be supported by toolchains_llvm
# docker build -t docker-container-build-env -f platforms/advanced/Dockerfile --load .
wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb
sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb
shopt -s globstar
bazel run //:clang-format -- --verbose --dry-run -Werror $(realpath **/*.cc **/*.hpp)
- name: clang-tidy
run: |
# certain headers won't be found when using a static clang-tidy binary so need to install clang
# and pass extra include paths to the compiler command line;
sudo apt install clang-19
# a header needs to be generated first
bazel build //generated:header-generated-genrule
# this is necessary for clang-tidy to find all the includes
bazel run @hedron_compile_commands//:refresh_all
# rules_multitool let you run a tool in the workspace root
shopt -s globstar
bazel run @multitool//tools/clang-tidy:workspace_root -- \
--extra-arg="-I/usr/lib/llvm-19/lib/clang/19/include" \
-p compile_commands.json \
src/**/*.cc
# skipping headers (src/**/*.hpp) because the compilation database does not contain
# the the catch2 headers (for some reason):
# external/catch2+/src/catch2/internal/catch_test_macro_impl.hpp:11:10: error: 'catch2/catch_user_config.hpp'
# file not found [clang-diagnostic-error]
# 11 | #include <catch2/catch_user_config.hpp>
build-hermetic:
runs-on: ubuntu-24.04
strategy:
matrix:
arch: [amd64, arm64]
steps:
- name: Checkout code
uses: actions/checkout@v4
# from https://github.com/bazel-contrib/setup-bazel
- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Share build cache between workflows.
disk-cache: true
# Share repository cache between workflows.
repository-cache: true
- name: Build ${{ matrix.arch }}
run: |
mkdir -p dist/
mkdir -p /tmp/zig-cache && bazel build \
--action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \
--config=hermetic-linux-${{ matrix.arch }} \
//src/apps:math
cp bazel-bin/src/apps/math dist/math-${{ matrix.arch }}
- name: Upload cross-compiled binary
uses: actions/upload-artifact@v4
with:
name: math-arm64
path: dist/math-arm64
build-hermetic-llvm:
runs-on: ubuntu-24.04
strategy:
matrix:
# TODO: add arm64
arch: [amd64,]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
disk-cache: true
repository-cache: true
- name: Build ${{ matrix.arch }}
run: |
wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb
sudo dpkg -i libtinfo5_6.3-2ubuntu0.1_amd64.deb
bazel build \
--action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \
--config=hermetic-linux-${{ matrix.arch }}-llvm \
//src/apps:math
test-hermetic:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
# from https://github.com/bazel-contrib/setup-bazel
- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Share build cache between workflows.
disk-cache: true
# Share repository cache between workflows.
repository-cache: true
- name: Test
run: |
bazel run @hedron_compile_commands//:refresh_all
mkdir -p /tmp/zig-cache && bazel test \
--action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \
--config=hermetic-linux-amd64 \
--test_tag_filters=static \
//...
build-docker-container:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
# from https://github.com/bazel-contrib/setup-bazel
- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Share build cache between workflows.
disk-cache: true
# Share repository cache between workflows.
repository-cache: true
- name: Create and load Docker image
run: |
bazel run //containers:image_load
- name: Run image with Docker
run: |
docker run --rm release:latest 14 3
push-docker-registry:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
# from https://github.com/bazel-contrib/setup-bazel
- name: Setup Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
# Avoid downloading Bazel every time.
bazelisk-cache: true
# Share build cache between workflows.
disk-cache: true
# Share repository cache between workflows.
repository-cache: true
- name: Set up Docker registry
run: |
docker run -d -p 5000:5000 --name registry registry:2
- name: Create and load Docker image
run: |
bazel run //containers:image_push
- name: List registry images
run: |
curl http://localhost:5000/v2/apps/cpp/tags/list
test-arm64-emulated:
name: run-arm64-binary-docker
needs: build-hermetic
runs-on: ubuntu-24.04
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: math-arm64
path: ./bin
- name: Run binary in an arm64 Docker container
run: |
chmod +x ./bin/math-arm64
docker run --rm -v "$PWD/bin:/app" --platform linux/arm64 ubuntu bash -c "/app/math-arm64 1"