Skip to content

Commit

Permalink
Setup bazel build and check workflow in CI (#1)
Browse files Browse the repository at this point in the history
Set up Bazel with hermetic GCC 12 and Clang 16 toolchains, ClangFormat,
ClangTidy, sanitizers, and Buildifier. boost.ut is introduced as the
test framework library.

This commit also sets up a check workflow in CI testing the above
mentioned tools.

This is largely copied the configuration from
https://github.com/garymm/gpu-deflate/

Change-Id: I71bfc757c90a13277ac38baca15539e114b6b5d3
  • Loading branch information
oliverlee authored Jul 21, 2023
1 parent 2b675da commit 994e75a
Show file tree
Hide file tree
Showing 24 changed files with 1,011 additions and 0 deletions.
1 change: 1 addition & 0 deletions .bazeliskrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
USE_BAZEL_VERSION=6.2.1
25 changes: 25 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
build --incompatible_enable_cc_toolchain_resolution
build --action_env="BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1"

build:clang16 --extra_toolchains=//toolchain:clang16
build:gcc12 --extra_toolchains=//toolchain:gcc12

build:clang-format --aspects @bazel_clang_format//:defs.bzl%clang_format_aspect
build:clang-format --@bazel_clang_format//:binary=@llvm_16_toolchain//:clang-format
build:clang-format --@bazel_clang_format//:config=//:format_config
build:clang-format --output_groups=report
build:clang-format --keep_going

build:clang-tidy-base --config=clang16
build:clang-tidy-base --aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect
build:clang-tidy-base --@bazel_clang_tidy//:clang_tidy_config=//:tidy_config
build:clang-tidy-base --output_groups=report
build:clang-tidy-base --keep_going

build:verbose-clang-tidy --config=clang-tidy-base
build:verbose-clang-tidy --@bazel_clang_tidy//:clang_tidy_executable=//tools:verbose-clang-tidy

build:clang-tidy --config=clang-tidy-base
build:clang-tidy --@bazel_clang_tidy//:clang_tidy_executable=@llvm_16_toolchain//:clang-tidy

try-import %workspace%/user.bazelrc
77 changes: 77 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
BasedOnStyle: LLVM
AlignAfterOpenBracket: Align
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortBlocksOnASingleLine: Empty
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakAfterAttributes: Always
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterEnum: true
AfterFunction: true
AfterStruct: true
AfterUnion: true
SplitEmptyFunction: false
SplitEmptyRecord: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 80
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: true
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IndentCaseLabels: true
IndentWidth: 2
InsertNewlineAtEOF: true
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyIndentedWhitespace: 200
PenaltyReturnTypeOnItsOwnLine: 1
PointerAlignment: Left
QualifierAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Custom
SpaceBeforeParensOptions:
AfterRequiresInClause: true
AfterRequiresInExpression: true
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest

IncludeCategories:
- Regex: '"test'
Priority: 2
- Regex: '"fmt'
Priority: 3
- Regex: 'metal.hpp'
Priority: 3
- Regex: 'boost/ut.hpp'
Priority: 4
- Regex: '<[[:alnum:|_].]+>'
Priority: 5
- Regex: '".*"'
Priority: 1

...
65 changes: 65 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
UseColor: true

Checks: >
bugprone-*,
clang-analyzer-cplusplus*,
concurrency-*,
cppcoreguidelines-*,
misc-*,
modernize-*,
performance-*,
readability-*,
# Bazel does this for determinism,
-clang-diagnostic-builtin-macro-redefined,
# suppress due to assert,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
# short names are fine for short lifetimes,
-readability-identifier-length,
# allow unused variables to be unnamed,
-readability-named-parameter,
# C-arrays necessary as function args,
-modernize-avoid-c-arrays,
# use iterators as abstractions, not pointers,
-readability-qualified-auto,
# it's okay for exceptions to escape main,
-bugprone-exception-escape,
# false positive with spaceship operator,
# https://reviews.llvm.org/D95714?id=320393,
-modernize-use-nullptr,
# disable common aliases,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-c-copy-assignment-signature,
-cppcoreguidelines-explicit-virtual-functions,
-cppcoreguidelines-non-private-member-variables-in-classes,
# disable EXTREMELY SLOW checks,
-bugprone-reserved-identifier,
-readability-identifier-naming,
-misc-confusable-identifiers,
CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: true
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: false

# only lint files coming from this project
HeaderFilterRegex: '__main__/'

# clang-diagnostic-builtin-macro-redefined must be manually suppressed here
# https://github.com/erenon/bazel_clang_tidy/issues/29
# https://github.com/llvm/llvm-project/issues/56709
#
WarningsAsErrors: '*,-clang-diagnostic-builtin-macro-redefined'


95 changes: 95 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: check

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

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain: [gcc12, clang16]
feature: ['', asan, tsan, ubsan]

steps:
- uses: actions/checkout@v3

- name: install libtinfo5
# clang tools load libtinfo5 for color diagnostics but `ubuntu-latest`
# runners already have `libtinfo.so.6` installed. We just create a
# symlink since it's faster than installing libtinfo5.
# https://github.com/circleci/circleci-images/issues/430#issuecomment-522602495
run: |
sudo ln -s /lib/x86_64-linux-gnu/libtinfo.so.6 /lib/x86_64-linux-gnu/libtinfo.so.5
- run: |
bazel \
--bazelrc=.github/workflows/ci.bazelrc \
test \
--config=${{ matrix.toolchain }} \
--features=${{ matrix.feature }} \
//...
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
flag:
- '--config=clang-format'
- '--config=clang-tidy'
- '--config=verbose-clang-tidy'
- '--compilation_mode=opt'
exclude:
- flag: ${{ github.event_name == 'pull_request' && '--config=verbose-clang-tidy' || 'dummy' }}

steps:
- uses: actions/checkout@v3

- name: install libtinfo5
# clang tools load libtinfo5 for color diagnostics but `ubuntu-latest`
# runners already have `libtinfo.so.6` installed. We just create a
# symlink since it's faster than installing libtinfo5.
# https://github.com/circleci/circleci-images/issues/430#issuecomment-522602495
run: |
sudo ln -s /lib/x86_64-linux-gnu/libtinfo.so.6 /lib/x86_64-linux-gnu/libtinfo.so.5
- run: |
bazel \
--bazelrc=.github/workflows/ci.bazelrc \
build \
${{ matrix.flag }} \
//...
build-without-terminfo:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toolchain: [gcc12, clang16]

steps:
- uses: actions/checkout@v3

- run: |
bazel \
--bazelrc=.github/workflows/ci.bazelrc \
build \
--config=${{ matrix.toolchain }} \
//...
buildifier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- run: |
bazel \
--bazelrc=.github/workflows/ci.bazelrc \
run \
//:buildifier.check
11 changes: 11 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This is from Bazel's former travis setup, to avoid blowing up the RAM usage.
startup --host_jvm_args=-Xmx2500m

build --show_timestamps
build --announce_rc
build --color=yes
build --terminal_columns=120
build --remote_download_minimal

test --test_output=all
test --test_verbose_timeout_warnings
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bazel-*
.envrc

user.bazelrc
42 changes: 42 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
load("@bazel_clang_format//:defs.bzl", "clang_format_update")
load("@bazel_clang_tidy//:defs.bzl", "clang_tidy_apply_fixes")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "format_config",
srcs = [".clang-format"],
visibility = ["//visibility:public"],
)

filegroup(
name = "tidy_config",
srcs = [".clang-tidy"],
visibility = ["//visibility:public"],
)

clang_format_update(
name = "clang-format",
binary = "@llvm_16_toolchain//:clang-format",
config = ":format_config",
)

clang_tidy_apply_fixes(
name = "clang-tidy-fix",
apply_replacements_binary = "@llvm_16_toolchain//:clang-apply-replacements",
tidy_binary = "@llvm_16_toolchain//:clang-tidy",
tidy_config = ":tidy_config",
)

buildifier(
name = "buildifier.check",
lint_mode = "warn",
mode = "check",
)

buildifier(
name = "buildifier.fix",
lint_mode = "warn",
mode = "fix",
)
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# bike2

A successor to [bike1](https://github.com/oliverlee/robot.bicycle).

## Set up

Should work on Linux.

* Install `bazel` or `bazelisk`

* Verify that you can build and test:
```sh
bazel test //...
```

Loading

0 comments on commit 994e75a

Please sign in to comment.