Skip to content

Commit

Permalink
chore: support bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
Dup4 committed Dec 27, 2022
1 parent e080051 commit 1b41734
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
.coverage
build
__snapshots__

### Automatically added by Hedron's Bazel Compile Commands Extractor: https://github.com/hedronvision/bazel-compile-commands-extractor
# 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.
/external
# 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.
/bazel-*
# 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.
/compile_commands.json
# Ignore the directory in which `clangd` stores its local index.
/.cache/
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"clangd.arguments": [
"--compile-commands-dir=./build",
"--compile-commands-dir=./",
"--background-index",
"--header-insertion=iwyu",
"--all-scopes-completion",
Expand Down
45 changes: 45 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package(default_visibility = ["//visibility:public"])

common_copts = [
"-std=c++17",
"-O3",
"-g",
"-Wall",
"-Wextra",
"-Werror",
]

cc_library(
name = "snapshot",
hdrs = glob(["include/snapshot/**/*.h"]),
includes = [
"include",
],
)

cc_binary(
name = "benchmark",
srcs = glob([
"test/*_benchmark.cc",
]),
copts = common_copts,
deps = [
":snapshot",
"@google_benchmark//:benchmark_main",
],
)

cc_binary(
name = "unittest",
srcs = glob([
"test/*_test.cc",
"test/**/*_test.cc",
]),
copts = common_copts + [
"-Wno-unused-result",
],
deps = [
":snapshot",
"@gtest//:gtest_main",
],
)
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ clean_test:
fi

.PHONY: clean clean_test

bazel_bench:
bazel run :benchmark --compilation_mode=opt

bazel_ut:
bazel run :unittest --compilation_mode=opt

bazel_clean:
rm -rf bazel-* external

bazel_refresh_all:
bazel run @bazel_compile_commands_extractor//:refresh_all
31 changes: 31 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
name = "bazel_build_files",
remote = "https://github.com/Dup4/bazel-build-files.git",
tag = "v0.0.1",
)

git_repository(
name = "google_benchmark",
branch = "main",
build_file = "@bazel_build_files//google-benchmark:BUILD.bazel",
remote = "https://github.com/google/benchmark.git",
)

git_repository(
name = "gtest",
branch = "main",
build_file = "@bazel_build_files//gtest:BUILD.bazel",
remote = "https://github.com/google/googletest.git",
)

git_repository(
name = "bazel_compile_commands_extractor",
branch = "main",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
)

load("@bazel_compile_commands_extractor//:workspace_setup.bzl", "hedron_compile_commands_setup")

hedron_compile_commands_setup()

0 comments on commit 1b41734

Please sign in to comment.