Skip to content

Commit 1b41734

Browse files
committed
chore: support bazel
1 parent e080051 commit 1b41734

File tree

5 files changed

+99
-1
lines changed

5 files changed

+99
-1
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,13 @@
33
.coverage
44
build
55
__snapshots__
6+
7+
### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
8+
# Ignore the `external` link (that is added by `bazel-compile-commands-extractor`). The link differs between macOS/Linux and Windows, so it shouldn't be checked in. The pattern must not end with a trailing `/` because it's a symlink on macOS/Linux.
9+
/external
10+
# Ignore links to Bazel's output. The pattern needs the `*` because people can change the name of the directory into which your repository is cloned (changing the `bazel-<workspace_name>` symlink), and must not end with a trailing `/` because it's a symlink on macOS/Linux.
11+
/bazel-*
12+
# Ignore generated output. Although valuable (after all, the primary purpose of `bazel-compile-commands-extractor` is to produce `compile_commands.json`!), it should not be checked in.
13+
/compile_commands.json
14+
# Ignore the directory in which `clangd` stores its local index.
15+
/.cache/

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"files.insertFinalNewline": true,
77
"files.trimFinalNewlines": true,
88
"clangd.arguments": [
9-
"--compile-commands-dir=./build",
9+
"--compile-commands-dir=./",
1010
"--background-index",
1111
"--header-insertion=iwyu",
1212
"--all-scopes-completion",

BUILD.bazel

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
common_copts = [
4+
"-std=c++17",
5+
"-O3",
6+
"-g",
7+
"-Wall",
8+
"-Wextra",
9+
"-Werror",
10+
]
11+
12+
cc_library(
13+
name = "snapshot",
14+
hdrs = glob(["include/snapshot/**/*.h"]),
15+
includes = [
16+
"include",
17+
],
18+
)
19+
20+
cc_binary(
21+
name = "benchmark",
22+
srcs = glob([
23+
"test/*_benchmark.cc",
24+
]),
25+
copts = common_copts,
26+
deps = [
27+
":snapshot",
28+
"@google_benchmark//:benchmark_main",
29+
],
30+
)
31+
32+
cc_binary(
33+
name = "unittest",
34+
srcs = glob([
35+
"test/*_test.cc",
36+
"test/**/*_test.cc",
37+
]),
38+
copts = common_copts + [
39+
"-Wno-unused-result",
40+
],
41+
deps = [
42+
":snapshot",
43+
"@gtest//:gtest_main",
44+
],
45+
)

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ clean_test:
3838
fi
3939

4040
.PHONY: clean clean_test
41+
42+
bazel_bench:
43+
bazel run :benchmark --compilation_mode=opt
44+
45+
bazel_ut:
46+
bazel run :unittest --compilation_mode=opt
47+
48+
bazel_clean:
49+
rm -rf bazel-* external
50+
51+
bazel_refresh_all:
52+
bazel run @bazel_compile_commands_extractor//:refresh_all

WORKSPACE

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
2+
3+
git_repository(
4+
name = "bazel_build_files",
5+
remote = "https://github.com/Dup4/bazel-build-files.git",
6+
tag = "v0.0.1",
7+
)
8+
9+
git_repository(
10+
name = "google_benchmark",
11+
branch = "main",
12+
build_file = "@bazel_build_files//google-benchmark:BUILD.bazel",
13+
remote = "https://github.com/google/benchmark.git",
14+
)
15+
16+
git_repository(
17+
name = "gtest",
18+
branch = "main",
19+
build_file = "@bazel_build_files//gtest:BUILD.bazel",
20+
remote = "https://github.com/google/googletest.git",
21+
)
22+
23+
git_repository(
24+
name = "bazel_compile_commands_extractor",
25+
branch = "main",
26+
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
27+
)
28+
29+
load("@bazel_compile_commands_extractor//:workspace_setup.bzl", "hedron_compile_commands_setup")
30+
31+
hedron_compile_commands_setup()

0 commit comments

Comments
 (0)