add bazel build support

Signed-off-by: fan <yfan3763@gmail.com>
This commit is contained in:
fan 2022-10-24 06:31:09 +08:00
parent aa5479bbf4
commit c971b8fe9d
12 changed files with 589 additions and 0 deletions

9
BUILD.bazel Normal file
View File

@ -0,0 +1,9 @@
package(default_visibility = ["//visibility:public"])
# default use clang compiler
config_setting(
name = "clang_compiler",
flag_values = {
"@bazel_tools//tools/cpp:compiler": "clang",
},
)

View File

@ -49,6 +49,15 @@ Quick start:
mkdir -p build && cd build
cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build .
```
Bazel Support:
```bash
# build all
bazel build "..."
```
bazel generate compile_commands.json, this command need python support. and the version can't be too old.
```bash
bazel run @hedron_compile_commands//:refresh_all
```
### Building for Windows

33
WORKSPACE Normal file
View File

@ -0,0 +1,33 @@
workspace(name = "leveldb")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
http_archive(
name = "com_google_googletest",
sha256 = "a1d3123179024258f9c399d45da3e0b09c4aaf8d2c041466ce5b4793a8929f23",
strip_prefix = "googletest-86add13493e5c881d7e4ba77fb91c1f57752b3a4",
urls = ["https://github.com/google/googletest/archive/86add13493e5c881d7e4ba77fb91c1f57752b3a4.zip"],
)
http_archive(
name = "com_google_benchmark", # 2021-09-20T09:19:51Z
sha256 = "62e2f2e6d8a744d67e4bbc212fcfd06647080de4253c97ad5c6749e09faf2cb0",
strip_prefix = "benchmark-0baacde3618ca617da95375e0af13ce1baadea47",
urls = ["https://github.com/google/benchmark/archive/0baacde3618ca617da95375e0af13ce1baadea47.zip"],
)
# generate compile_commands.json
http_archive(
name = "hedron_compile_commands",
# Replace the commit hash in both places (below) with the latest, rather than using the stale one here.
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
urls = [
"https://github.com/hedronvision/bazel-compile-commands-extractor/archive/af9af15f7bc16fc3e407e2231abfcb62907d258f.tar.gz",
],
strip_prefix = "bazel-compile-commands-extractor-af9af15f7bc16fc3e407e2231abfcb62907d258f",
# When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
)
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup()

42
benchmarks/BUILD.bazel Normal file
View File

@ -0,0 +1,42 @@
package(default_visibility = ["//visibility:public"])
load("//:copts.bzl", "LEVELDB_FLAGS")
cc_test(
name = "db_bench",
srcs = glob(["db_bench.cc"]),
deps = [
"//include/leveldb",
"//db:db_lib",
"@com_google_googletest//:gtest_main",
"@com_google_benchmark//:benchmark_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "db_bench_sqlite3",
srcs = glob(["db_bench_sqlite3.cc"]),
deps = [
"//include/leveldb",
"//db:db_lib",
"@com_google_googletest//:gtest_main",
"@com_google_benchmark//:benchmark_main",
],
copts = LEVELDB_FLAGS,
linkopts = [
"-lsqlite3",
],
)
cc_test(
name = "db_bench_log",
srcs = glob(["db_bench_log.cc"]),
deps = [
"//include/leveldb",
"//db:db_lib",
"@com_google_googletest//:gtest_main",
"@com_google_benchmark//:benchmark_main",
],
copts = LEVELDB_FLAGS,
)

18
copts.bzl Normal file
View File

@ -0,0 +1,18 @@
LEVELDB_FLAGS = [
"-Wall",
"-Wextra",
"-Wconversion-null",
"-Wformat-security",
"-Woverlength-strings",
"-Wpointer-arith",
"-Wundef",
"-Wunused-local-typedefs",
"-Wunused-result",
"-Wvarargs",
"-Wvla",
"-Wwrite-strings",
# "-Werror",
"-DNOMINMAX",
"-fno-exceptions",
]

132
db/BUILD.bazel Normal file
View File

@ -0,0 +1,132 @@
package(default_visibility = ["//visibility:public"])
load("//:copts.bzl", "LEVELDB_FLAGS")
cc_library(
name = "db_lib",
srcs = glob(
["*.cc"],
exclude = glob([
"*_test.cc",
"leveldbutil.cc",
"db_bench.cc",
]),
),
hdrs = glob([
"*.h",
]),
deps = [
"//include/leveldb",
"//table:table_lib",
"//util:util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_binary(
name = "leveldbutil",
srcs = ["leveldbutil.cc"],
deps = [
":db_lib",
"//include/leveldb",
"//util:util_lib",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "autocompact_test",
srcs = ["autocompact_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "corruption_test",
srcs = ["corruption_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "db_test",
srcs = ["db_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "dbformat_test",
srcs = ["dbformat_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "fault_injection_test",
srcs = ["fault_injection_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "filename_test",
srcs = ["filename_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "log_test",
srcs = ["log_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "recovery_test",
srcs = ["recovery_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "skiplist_test",
srcs = ["skiplist_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "version_edit_test",
srcs = ["version_edit_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "write_batch_test",
srcs = ["write_batch_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "version_set_test",
srcs = ["version_set_test.cc"],
deps = [":db_lib",
"//helpers/memenv:mem_lib"],
copts = LEVELDB_FLAGS,
)

View File

@ -0,0 +1,20 @@
package(default_visibility = ["//visibility:public"])
load("//:copts.bzl", "LEVELDB_FLAGS")
cc_library(
name = "mem_lib",
srcs = glob(
["memenv.h",
"memenv.cc"],
),
hdrs = glob(
["*.h"],
),
visibility = ["//visibility:public"],
deps = [
"//port:port_lib",
"//util:leveldb_mutex_lib",
"//include/leveldb",
],
copts = LEVELDB_FLAGS,
)

View File

@ -0,0 +1,9 @@
package(default_visibility = ["//visibility:public"])
load("//:copts.bzl", "LEVELDB_FLAGS")
cc_library(
name = "leveldb",
hdrs = glob(["*.h"]),
include_prefix = "leveldb",
copts = LEVELDB_FLAGS,
)

41
issues/BUILD.bazel Normal file
View File

@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])
load("//:copts.bzl", "LEVELDB_FLAGS")
cc_test(
name = "issue178_test",
srcs = glob(["issue178_test.cc"]),
deps = [
"//include/leveldb",
"//util:util_lib",
"//table:table_lib",
"//db:db_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "issue200_test",
srcs = glob(["issue200_test.cc"]),
deps = [
"//include/leveldb",
"//util:util_lib",
"//table:table_lib",
"//db:db_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "issue320_test",
srcs = glob(["issue320_test.cc"]),
deps = [
"//include/leveldb",
"//util:util_lib",
"//table:table_lib",
"//db:db_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)

51
port/BUILD.bazel Normal file
View File

@ -0,0 +1,51 @@
package(default_visibility = ["//visibility:public"])
config_setting(
name = "osx_x86_64",
constraint_values = [
"@bazel_tools//platforms:osx",
"@bazel_tools//platforms:x86_64",
],
visibility = ["//visibility:public"],
)
config_setting(
name = "linux_x86_64",
constraint_values = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
visibility = ["//visibility:public"],
)
config_setting(
name = "windows_x86_64",
constraint_values = [
"@bazel_tools//platforms:windows",
"@bazel_tools//platforms:x86_64",
],
visibility = ["//visibility:public"],
)
cc_library(
name = "port_lib",
hdrs = glob(["*.h"]),
defines = select({
":osx_x86_64": [
"LEVELDB_PLATFORM_POSIX=1",
"LEVELDB_IS_BIG_ENDIAN=0",
],
":linux_x86_64": [
"LEVELDB_PLATFORM_POSIX=1",
"LEVELDB_IS_BIG_ENDIAN=0",
],
":windows_x86_64": [
"LEVELDB_PLATFORM_WINDOWS=1",
"LEVELDB_IS_BIG_ENDIAN=0",
],
"//conditions:default": [
"LEVELDB_PLATFORM_posix=1",
"LEVELDB_IS_BIG_ENDIAN=0",
],
}),
)

38
table/BUILD.bazel Normal file
View File

@ -0,0 +1,38 @@
package(default_visibility = ["//visibility:public"])
load("//:copts.bzl", "LEVELDB_FLAGS")
cc_library(
name = "table_lib",
srcs = glob(
["*.cc"],
exclude = glob(["*_test.cc"]),
),
hdrs = glob(["*.h"]),
deps = [
"//include/leveldb",
"//util:util_lib",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "table_test",
srcs = ["table_test.cc"],
deps = [
":table_lib",
"//db:db_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "filter_block_test",
srcs = ["filter_block_test.cc"],
deps = [
":table_lib",
"//db:db_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)

187
util/BUILD.bazel Normal file
View File

@ -0,0 +1,187 @@
package(default_visibility = ["//visibility:public"])
load("//:copts.bzl", "LEVELDB_FLAGS")
cc_library(
name = "unix_env_lib",
srcs = [
"env_posix.cc",
"env.cc",
"env_posix_test.cc",
"env_posix_test_helper.h",
"posix_logger.h",
"testutil.h",
"random.h",
"testutil.cc",
],
deps = [
"//include/leveldb",
"//port:port_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_library(
name = "windows_env_lib",
srcs = select({
"//port:windows_x86_64":[
"env.cc",
"testutil.cc",
"random.h",
"testutil.h",
"env_windows.cc",
"env_windows_test.cc",
"env_windows_test_helper.h",
],
"//conditions:default": [
],
}),
deps = [
"//include/leveldb",
"//port:port_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_library(
name = "util_lib",
srcs = glob(
["*.cc"],
exclude = glob(["env*",]),
),
hdrs = glob(["*.h"]),
linkopts = select({
"//port:osx_x86_64": [
"-pthread",
],
"//port:linux_x86_64": [
"-pthread",
],
"//port:windows_x86_64": [],
"//conditions:default": [],
}),
deps = select({
"//port:windows_x86_64": ["windows_env_lib"],
"//port:linux_x86_64": ["unix_env_lib"],
"//port:osx_x86_64": ["unix_env_lib"],
"//conditions:default": ["unix_env_lib"],
}),
copts = LEVELDB_FLAGS,
)
cc_library(
name = "leveldb_mutex_lib",
srcs = glob(
["mutexlock.h",],
),
deps = [
"//port:port_lib"
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "arena_test",
srcs = ["arena_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "bloom_test",
srcs = ["bloom_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "cache_test",
srcs = ["cache_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "coding_test",
srcs = ["coding_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "crc32c_test",
srcs = ["crc32c_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "env_posix_test",
srcs = ["env_posix_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "env_test",
srcs = ["env_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "hash_test",
srcs = ["hash_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "logging_test",
srcs = ["logging_test.cc"],
deps = [":util_lib",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)
cc_test(
name = "status_test",
srcs = ["status_test.cc"],
deps = [
":util_lib",
"//include/leveldb",
"//helpers/memenv:mem_lib",
"@com_google_googletest//:gtest_main",
],
copts = LEVELDB_FLAGS,
)