Skip to content

Commit 580df2a

Browse files
author
seel.xu
committed
[Feature]: add base code
1 parent 55c6091 commit 580df2a

File tree

10 files changed

+324
-2
lines changed

10 files changed

+324
-2
lines changed

.bazelrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
common --announce_rc
2+
3+
build --cxxopt="-std=c++17"
4+
build --cxxopt="-gz" --cxxopt="-gdwarf-4"
5+
build --cxxopt="-Wall" --cxxopt="-Wextra" --cxxopt="-Werror"
6+
build --cxxopt="-Wno-cast-function-type-mismatch"
7+
build --cxxopt="-Wno-unused-function" --cxxopt="-Wno-unused-parameter" # protobuf require
8+
build --cxxopt="-Wno-deprecated-declarations" # cuda require
9+
build --linkopt="-Wl,--export-dynamic" --linkopt="-Wl,--build-id"
10+
build --linkopt="-flto=thin"
11+
build --compilation_mode=opt --copt=-g --copt=-O3
12+
13+
# Use --config=clang to build with clang instead of gcc and nvcc.
14+
build:clang --repo_env=CC=clang
15+
16+
test --test_output=all
17+
test --cxxopt="-Wno-deprecated-declarations"

.clang-format

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
BasedOnStyle: Google
3+
---
4+
Language: Cpp
5+
Cpp11BracedListStyle: true
6+
Standard: Cpp11
7+
AllowShortFunctionsOnASingleLine: None
8+
AllowShortLambdasOnASingleLine: None
9+
DerivePointerAlignment: false
10+
PointerAlignment: Left
11+
CommentPragmas: "^ NOLINT"
12+
ColumnLimit: 100
13+
IncludeCategories:
14+
- Regex: '^<(.*)(\.h>)$'
15+
Priority: 1
16+
- Regex: "^<"
17+
Priority: 2
18+
- Regex: '^"([a-zA-Z_]*)(\.h")$'
19+
Priority: 3
20+
- Regex: '^"(gtest|gflags|glog|google|boost)/'
21+
Priority: 5
22+
- Regex: '^"(proto)/'
23+
Priority: 7
24+
- Regex: ".*"
25+
Priority: 8
26+
---

.clang-tidy

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
Checks: '-*,
3+
clang-analyzer-core.*,
4+
clang-analyzer-cplusplus.*,
5+
modernize-deprecated-headers,
6+
modernize-make-shared,
7+
modernize-make-unique,
8+
modernize-redundant-void-arg,
9+
modernize-use-bool-literals,
10+
modernize-use-emplace,
11+
modernize-use-equals-default,
12+
modernize-use-nullptr,
13+
modernize-use-override,
14+
google-build-explicit-make-pair,
15+
google-build-namespaces,
16+
google-build-using-namespace,
17+
google-default-arguments,
18+
google-explicit-constructor,
19+
google-global-names-in-headers,
20+
google-readability-avoid-underscore-in-googletest-name,
21+
google-readability-casting,
22+
google-runtime-int,
23+
readability-braces-around-statements,
24+
readability-container-size-empty,
25+
readability-identifier-naming.GlobalConstant,
26+
readability-identifier-naming.ConstantMember,
27+
readability-identifier-naming.ClassCase,
28+
readability-identifier-naming.StructCase,
29+
readability-identifier-naming.TypedefCase,
30+
readability-identifier-naming.EnumCase,
31+
readability-make-member-function-const,
32+
readability-non-const-parameter,
33+
readability-redundant-smartptr-get,
34+
cert-dcl21-cpp,
35+
bugprone-undelegated-constructor,
36+
bugprone-macro-parentheses,
37+
bugprone-macro-repeated-side-effects,
38+
bugprone-forward-declaration-namespace,
39+
bugprone-bool-pointer-implicit-conversion,
40+
bugprone-misplaced-widening-cast,
41+
misc-unconventional-assign-operator,
42+
misc-unused-parameters'
43+
WarningsAsErrors: ''
44+
HeaderFilterRegex: ''
45+
CheckOptions:
46+
# Modernize
47+
- key: modernize-deprecated-headers
48+
value: 'true'
49+
- key: modernize-make-shared
50+
value: 'true'
51+
- key: modernize-make-unique
52+
value: 'true'
53+
- key: modernize-redundant-void-arg
54+
value: 'true'
55+
- key: modernize-use-bool-literals
56+
value: 'false'
57+
- key: modernize-use-emplace
58+
value: 'true'
59+
- key: modernize-use-equals-default
60+
value: 'true'
61+
- key: modernize-use-nullptr
62+
value: 'true'
63+
- key: modernize-use-override
64+
value: 'true'
65+
# Google
66+
- key: google-build-explicit-make-pair
67+
value: 'true'
68+
- key: google-build-namespaces
69+
value: 'true'
70+
- key: google-build-using-namespace
71+
value: 'true'
72+
- key: google-default-arguments
73+
value: 'true'
74+
- key: google-explicit-constructor
75+
value: 'true'
76+
- key: google-global-names-in-headers
77+
value: 'true'
78+
- key: google-readability-avoid-underscore-in-googletest-name
79+
value: 'true'
80+
- key: google-readability-casting
81+
value: 'true'
82+
- key: google-runtime-int
83+
value: 'true'
84+
# Readability
85+
- key: readability-braces-around-statements
86+
value: 'true'
87+
- key: readability-container-size-empty
88+
value: 'true'
89+
- key: readability-identifier-naming.GlobalConstant
90+
value: 'kCamelCase'
91+
- key: readability-identifier-naming.ConstantMember
92+
value: 'kCamelCase'
93+
- key: readability-identifier-naming.ClassCase
94+
value: 'CamelCase'
95+
- key: readability-identifier-naming.StructCase
96+
value: 'CamelCase'
97+
- key: readability-identifier-naming.TypedefCase
98+
value: 'CamelCase'
99+
- key: readability-identifier-naming.EnumCase
100+
value: 'CamelCase'
101+
- key: readability-make-member-function-const
102+
value: 'true'
103+
- key: readability-non-const-parameter
104+
value: 'true'
105+
- key: readability-redundant-smartptr-get
106+
value: 'true'
107+
# CERT
108+
- key: cert-dcl21-cpp
109+
value: 'true'
110+
# Bugprone
111+
- key: bugprone-undelegated-constructor
112+
value: 'true'
113+
- key: bugprone-macro-parentheses
114+
value: 'true'
115+
- key: bugprone-macro-repeated-side-effects
116+
value: 'true'
117+
- key: bugprone-forward-declaration-namespace
118+
value: 'true'
119+
- key: bugprone-bool-pointer-implicit-conversion
120+
value: 'true'
121+
- key: bugprone-misplaced-widening-cast
122+
value: 'true'
123+
# CppCoreGuidelines
124+
# Miscellaneous
125+
- key: misc-unconventional-assign-operator
126+
value: 'true'
127+
- key: misc-unused-parameters
128+
value: 'true'

BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
load("@rules_pkg//pkg:tar.bzl", "pkg_tar")
2+
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")

MODULE.bazel

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Hedron's Compile Commands Extractor for Bazel
2+
# https://github.com/hedronvision/bazel-compile-commands-extractor
3+
bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
4+
git_override(
5+
module_name = "hedron_compile_commands",
6+
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
7+
commit = "1e08f8e0507b6b6b1f4416a9a22cf5c28beaba93",
8+
# Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main).
9+
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
10+
)
11+
12+
bazel_dep(name = "rules_pkg", version = "0.9.1")
13+
bazel_dep(name = 'rules_cc', version = '0.0.12')
14+
bazel_dep(name = 'rules_proto', version = '6.0.2')
15+
bazel_dep(name = "nlohmann_json", version = "3.11.3.bcr.1")
16+
bazel_dep(name = "googletest", version = "1.12.1", repo_name = "com_google_googletest")
17+
bazel_dep(name = "gflags", version = "2.2.2", repo_name = "com_github_gflags_gflags")
18+
bazel_dep(name = "glog", version = "0.7.1", repo_name = "com_github_glog_glog")
19+
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
20+
bazel_dep(name = "llvm")
21+
22+
# Boost
23+
# Famous C++ library that has given rise to many new additions to the C++ Standard Library
24+
# Makes @boost available for use: For example, add `@boost//:algorithm` to your deps.
25+
# For more, see https://github.com/nelhage/rules_boost and https://www.boost.org
26+
bazel_dep(name = "rules_boost", repo_name = "com_github_nelhage_rules_boost")
27+
archive_override(
28+
module_name = "rules_boost",
29+
urls = "https://github.com/nelhage/rules_boost/archive/refs/heads/master.tar.gz",
30+
strip_prefix = "rules_boost-master",
31+
# It is recommended to edit the above URL and the below sha256 to point to a specific version of this repository.
32+
# integrity = "sha256-...",
33+
)
34+
35+
non_module_boost_repositories = use_extension("@com_github_nelhage_rules_boost//:boost/repositories.bzl", "non_module_dependencies")
36+
use_repo(
37+
non_module_boost_repositories,
38+
"boost",
39+
)
40+
41+
# Python rules for Bazel
42+
bazel_dep(name = "rules_python", version = "0.38.0")
43+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
44+
python.toolchain(
45+
configure_coverage_tool = False,
46+
ignore_root_user_error = True,
47+
python_version = "3.10",
48+
)
49+
50+
local_path_override(
51+
module_name = "llvm",
52+
path = "llvm",
53+
)

docker/Dockerfile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ RUN apt update && \
8888
# install zsh & fix ssh env
8989
WORKDIR /tmp
9090
RUN apt update && apt install zsh openssh-client openssh-server -y && \
91-
echo "export \$(cat /proc/1/environ |tr '\\0' '\\n' | xargs)" >> /etc/profile && \
92-
echo "export \$(cat /proc/1/environ |tr '\\0' '\\n' | xargs)" >> /etc/zsh/zprofile && \
91+
echo "export \$(cat /proc/1/environ |tr '\\\0' '\\\n' | xargs)" >> /etc/profile && \
92+
echo "export \$(cat /proc/1/environ |tr '\\\0' '\\\n' | xargs)" >> /etc/zsh/zprofile && \
9393
rm -rf ~/.oh-my-zsh || true && \
9494
curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -o install.sh && \
9595
chmod +x install.sh && \
@@ -121,6 +121,10 @@ RUN apt update && \
121121
FROM base as final-build
122122
USER root
123123
WORKDIR /workspace
124+
ENV CC "clang"
125+
ENV CXX "clang++"
126+
ENV CPP "clang++ -E"
127+
ENV LD "clang++"
124128
ENV PATH $PATH:/usr/local/cuda/bin:/usr/src/tensorrt/bin
125129
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib:/usr/lib/llvm-20/lib
126130
ENV LIBRARY_PATH $LIBRARY_PATH::/usr/local/lib:/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib:/usr/lib/llvm-20/lib
@@ -130,6 +134,10 @@ ENV CPLUS_INCLUDE_PATH $CPLUS_INCLUDE_PATH:/usr/local/cuda/include://usr/include
130134
FROM dev-stage as final-dev
131135
USER root
132136
WORKDIR /workspace
137+
ENV CC "clang"
138+
ENV CXX "clang++"
139+
ENV CPP "clang++ -E"
140+
ENV LD "clang++"
133141
ENV PATH $PATH:/usr/local/cuda/bin:/usr/src/tensorrt/bin
134142
ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib:/usr/lib/llvm-20/lib
135143
ENV LIBRARY_PATH $LIBRARY_PATH::/usr/local/lib:/usr/local/cuda/lib64:/usr/local/cuda/targets/x86_64-linux/lib:/usr/lib/llvm-20/lib

llvm/BUILD.bazel

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
cc_library(
2+
name = "clang_libs",
3+
linkopts = [
4+
"-L/usr/lib/llvm-20/lib",
5+
"-Wl,--start-group",
6+
"-lclangAPINotes",
7+
"-lclangARCMigrate",
8+
"-lclangAST",
9+
"-lclangASTMatchers",
10+
"-lclangAnalysis",
11+
"-lclangBasic",
12+
"-lclangCodeGen",
13+
"-lclangCrossTU",
14+
"-lclangDependencyScanning",
15+
"-lclangDirectoryWatcher",
16+
"-lclangDriver",
17+
"-lclangDynamicASTMatchers",
18+
"-lclangEdit",
19+
"-lclangFormat",
20+
"-lclangFrontend",
21+
"-lclangFrontendTool",
22+
"-lclangHandleCXX",
23+
"-lclangHandleLLVM",
24+
"-lclangIndex",
25+
"-lclangInterpreter",
26+
"-lclangLex",
27+
"-lclangTooling",
28+
"-lclangToolingCore",
29+
"-lclangToolingInclusions",
30+
"-lclangToolingRefactoring",
31+
"-lclangToolingSyntax",
32+
"-lclangParse",
33+
"-lclangRewrite",
34+
"-lclangRewriteFrontend",
35+
"-lclangSema",
36+
"-lclangSerialization",
37+
"-lclangSupport",
38+
"-lLLVM-20",
39+
"-Wl,--end-group",
40+
"-ldl",
41+
"-lpthread",
42+
"-lrt",
43+
"-ltinfo",
44+
"-lm",
45+
"-lncurses",
46+
],
47+
visibility = ["//visibility:public"],
48+
)

llvm/MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module(
2+
name = "llvm",
3+
)

scripts/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Bazel build
6+
bazel build $(bazel query //...) --action_env=LIBRARY_PATH=$LIBRARY_PATH

scripts/update_compile_commands.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# This script is used to update the compile_commands.json file in the root of the project.
6+
# This file is used by clang-tidy and other tools to get the compile commands for each file.
7+
# This script should be run after building the project with bazel
8+
9+
info() {
10+
echo -e "\033[0;34m[INFO]\033[0m $1"
11+
}
12+
13+
error() {
14+
echo -e "\033[0;31m[ERROR]\033[0m $1"
15+
}
16+
17+
warning() {
18+
echo -e "\033[0;33m[WARNING]\033[0m $1"
19+
}
20+
21+
ok() {
22+
echo -e "\033[0;32m[OK]\033[0m $1"
23+
}
24+
25+
26+
info "Updating compile_commands.json file\n"
27+
28+
bazel build $(bazel query //...) --action_env=LIBRARY_PATH=$LIBRARY_PATH || true
29+
bazel run @hedron_compile_commands//:refresh_all
30+
31+
ok "Successfully updated compile_commands.json file"

0 commit comments

Comments
 (0)