Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverlee committed Jan 6, 2024
0 parents commit 68d4073
Show file tree
Hide file tree
Showing 23 changed files with 1,104 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=7.0.0
28 changes: 28 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
common --enable_bzlmod=false

build --action_env="BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1"
build --color=yes
build --curses=yes

build:clang --extra_toolchains=//toolchain:clang
build:gcc --extra_toolchains=//toolchain:gcc

build:clang-format --aspects @bazel_clang_format//:defs.bzl%clang_format_aspect
build:clang-format --@bazel_clang_format//:binary=@llvm_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=clang
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_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

...
87 changes: 87 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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,
# NOTE: still false positive with LLVM 17.0.2,
-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,
# too many false positives,
-misc-include-cleaner,
# doesn't work with auto&,
-modernize-use-trailing-return-type,
# there are magic numbers in tests,
-readability-magic-numbers,
# hinnant style special member functions,
-cppcoreguidelines-special-member-functions,
# references are stored in short-lived objects that only live,
# until the end of the enclosing expression,
-cppcoreguidelines-avoid-const-or-ref-data-members,
# this library defines a DSL,
-misc-unconventional-assign-operator,
# false positives,
-readability-simplify-boolean-expr,
CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: true
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: false
- key: readability-implicit-bool-conversion.AllowIntegerConditions
value : true
- key: readability-implicit-bool-conversion.AllowPointerConditions
value : true

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

WarningsAsErrors: '*'

35 changes: 35 additions & 0 deletions .github/actions/ci-env-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "ci environment setup"
description: |
* set up color diagnostics for clang
* mount bazel cache
* set home bazelrc
inputs:
bazel-cache-key:
required: true
bazel-cache-path:
required: false
default: "~/.cache/bazel"

runs:
using: "composite"
steps:
- name: install libtinfo5
shell: bash
# 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
- name: mount bazel cache
uses: actions/cache@v3
with:
path: ${{ inputs.bazel-cache-path }}
key: ${{ inputs.bazel-cache-key }}

- name: setup ci bazelrc
shell: bash
run: |
cp .github/workflows/ci.bazelrc ~/.bazelrc
13 changes: 13 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
coverage:
status:
project:
default:
target: auto
threshold: 0%
patch:
default:
target: auto
threshold: 0%

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

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

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

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/ci-env-setup
with:
bazel-cache-key: bazel-test-${{ matrix.toolchain }}-${{ matrix.feature }}

- run: |
bazel \
test \
--config=${{ matrix.toolchain }} \
--features=${{ matrix.feature }} \
//...
coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/ci-env-setup
with:
bazel-cache-key: bazel-coverage

- run: |
bazel \
run \
//tools:lcov_list
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./bazel-out/_coverage/_coverage_report.dat
fail_ci_if_error: true

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

- uses: ./.github/actions/ci-env-setup
with:
bazel-cache-key: bazel-build-${{ matrix.flag }}

- run: |
bazel \
build \
${{ matrix.flag }} \
//...
buildifier:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/ci-env-setup
with:
bazel-cache-key: bazel-buildifier

- run: |
bazel \
run \
//tools:buildifier.check
24 changes: 24 additions & 0 deletions .github/workflows/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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
build --curses=no

test --test_output=errors
test --test_verbose_timeout_warnings

# at least some of these options are needed to address errors in CI, even
# without use of remote execution
#
# https://bazel.build/configure/coverage#remote-execution
# https://github.com/bazelbuild/bazel/issues/4685
coverage --strategy=CoverageReport=local
coverage --experimental_split_coverage_postprocessing
coverage --experimental_fetch_all_coverage_outputs
coverage --remote_download_outputs=all
coverage --experimental_remote_download_regex=.*/(coverage.dat$|_coverage/_coverage_report.dat$)

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
22 changes: 22 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

package(default_visibility = ["//:__subpackages__"])

exports_files(["README.md"])

filegroup(
name = "format_config",
srcs = [".clang-format"],
)

filegroup(
name = "tidy_config",
srcs = [".clang-tidy"],
)

cc_library(
name = "geometry",
srcs = [],
hdrs = ["geometry/geometry.hpp"],
visibility = ["//visibility:public"],
)
Loading

0 comments on commit 68d4073

Please sign in to comment.