Skip to content

Commit

Permalink
Based on the bazel set up build environment
Browse files Browse the repository at this point in the history
  • Loading branch information
zyfjeff committed Mar 26, 2019
0 parents commit 3373467
Show file tree
Hide file tree
Showing 21 changed files with 487 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Use the Google style in this project.
BasedOnStyle: Google
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bazel-*
36 changes: 36 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make")
load(
"@com_google_absl//absl:copts/configure_copts.bzl",
"GCC_FLAGS",
"GCC_TEST_FLAGS",
"LLVM_FLAGS",
"LLVM_TEST_FLAGS",
"MSVC_FLAGS",
"MSVC_TEST_FLAGS",
)

WERROR = ["-Werror=return-type", "-Werror=switch"]

DEFAULT_COPTS = select({
"//opencensus:llvm_compiler": LLVM_FLAGS + WERROR,
"//opencensus:windows": MSVC_FLAGS,
"//conditions:default": GCC_FLAGS + WERROR,
})

TEST_COPTS = DEFAULT_COPTS + select({
"//opencensus:llvm_compiler": LLVM_TEST_FLAGS + WERROR,
"//opencensus:windows": MSVC_TEST_FLAGS,
"//conditions:default": GCC_TEST_FLAGS + WERROR,
})

configure_make(
name = "libevent",
visibility = ["//visibility:public"],
configure_options = [
"--enable-shared=no",
"--disable-libevent-regress",
"--disable-openssl",
],
lib_source = "@com_github_libevent//:all",
out_lib_dir = "lib",
)
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<img src="https://user-images.githubusercontent.com/9434884/43697219-3cb4ef3a-9975-11e8-9a9c-73f4f537442d.png" alt="Sentinel Logo" width="50%">

# Sentinel: Sentinel of Your Application

## Build

1. Install the latest version of [Bazel](https://bazel.build/versions/master/docs/install.html) in your environment.
2. Build the examples to see how it works.
```
bazel build -c opt //examples/...
```

54 changes: 54 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2019 Alibaba Inc. All rights reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

workspace(name = "com_alibaba_sentinel")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Rule repository
http_archive(
name = "rules_foreign_cc",
strip_prefix = "rules_foreign_cc-master",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/master.zip",
)

load("@rules_foreign_cc//:workspace_definitions.bzl", "rules_foreign_cc_dependencies")

rules_foreign_cc_dependencies()

# abseil-cpp
http_archive(
name = "com_google_absl",
urls = ["https://github.com/abseil/abseil-cpp/archive/7c7754fb3ed9ffb57d35fe8658f3ba4d73a31e72.zip"], # 2019-03-14
strip_prefix = "abseil-cpp-7c7754fb3ed9ffb57d35fe8658f3ba4d73a31e72",
sha256 = "71d00d15fe6370220b6685552fb66e5814f4dd2e130f3836fc084c894943753f",
)

# Google Test
http_archive(
name = "com_google_googletest",
urls = ["https://github.com/google/googletest/archive/8b6d3f9c4a774bef3081195d422993323b6bb2e0.zip"], # 2019-03-05
strip_prefix = "googletest-8b6d3f9c4a774bef3081195d422993323b6bb2e0",
sha256 = "d21ba93d7f193a9a0ab80b96e8890d520b25704a6fac976fe9da81fffb3392e3",
)

# Google Benchmark
http_archive(
name = "com_google_benchmark",
urls = ["https://github.com/google/benchmark/archive/505be96ab23056580a3a2315abba048f4428b04e.tar.gz"],
strip_prefix = "benchmark-505be96ab23056580a3a2315abba048f4428b04e",
sha256 = "0de43b6eaddd356f1d6cd164f73f37faf2f6c96fd684e1f7ea543ce49c1d144e",
)

load("//bazel:third_party_repositories.bzl", "include_third_party_repositories")
include_third_party_repositories()
Empty file added bazel/BUILD
Empty file.
15 changes: 15 additions & 0 deletions bazel/fmtlib.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
licenses(["notice"]) # Apache 2

cc_library(
name = "fmtlib",
srcs = glob([
"fmt/*.cc",
]),
hdrs = glob([
"include/fmt/*.h",
]),
defines = ["FMT_HEADER_ONLY"],
includes = ["include"],
visibility = ["//visibility:public"],
)

14 changes: 14 additions & 0 deletions bazel/spdlog.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
licenses(["notice"]) # Apache 2

cc_library(
name = "spdlog",
hdrs = glob([
"include/**/*.cc",
"include/**/*.h",
]),
defines = ["SPDLOG_FMT_EXTERNAL"],
includes = ["include"],
visibility = ["//visibility:public"],
deps = ["@com_github_fmtlib_fmt//:fmtlib"],
)

27 changes: 27 additions & 0 deletions bazel/third_party_repositories.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""

def include_third_party_repositories():
http_archive(
name = "com_github_libevent",
build_file_content = all_content,
strip_prefix = "libevent-2.1.8-stable",
urls = ["https://github.com/libevent/libevent/releases/download/release-2.1.8-stable/libevent-2.1.8-stable.tar.gz"],
)

http_archive(
name = "com_github_fmtlib_fmt",
sha256 = "4c0741e10183f75d7d6f730b8708a99b329b2f942dad5a9da3385ab92bb4a15c",
strip_prefix = "fmt-5.3.0",
urls = ["https://github.com/fmtlib/fmt/releases/download/5.3.0/fmt-5.3.0.zip"],
build_file = "//bazel:fmtlib.BUILD",
)

http_archive(
name = "com_github_gabime_spdlog",
build_file = "//bazel:spdlog.BUILD",
sha256 = "160845266e94db1d4922ef755637f6901266731c4cb3b30b45bf41efa0e6ab70",
strip_prefix = "spdlog-1.3.1",
urls = ["https://github.com/gabime/spdlog/archive/v1.3.1.tar.gz"],
)
7 changes: 7 additions & 0 deletions examples/abseil/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc_binary(
name = "asbeil_string",
srcs = ["abseil_string.cc"],
deps = [
"@com_google_absl//absl/strings",
],
)
13 changes: 13 additions & 0 deletions examples/abseil/abseil_string.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <iostream>
#include <string>

#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"

std::string Greet(absl::string_view person) {
return absl::StrCat("Hello ", person);
}

int main(int argc, char* argv[]) {
std::cout << Greet(argc < 2 ? "world" : argv[1]) << std::endl;
}
7 changes: 7 additions & 0 deletions examples/benchmark/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc_binary(
name = "benchmark_test",
srcs = ["benchamrk_test.cc"],
deps = [
"@com_google_benchmark//:benchmark",
],
)
16 changes: 16 additions & 0 deletions examples/benchmark/benchamrk_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <benchmark/benchmark.h>

static void BM_StringCreation(benchmark::State& state) {
for (auto _ : state) std::string empty_string;
}
// Register the function as a benchmark
BENCHMARK(BM_StringCreation);

// Define another benchmark
static void BM_StringCopy(benchmark::State& state) {
std::string x = "hello";
for (auto _ : state) std::string copy(x);
}

BENCHMARK(BM_StringCopy);
BENCHMARK_MAIN();
7 changes: 7 additions & 0 deletions examples/fmt/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc_binary(
name = "fmt_test",
srcs = ["fmt_test.cc"],
deps = [
"@com_github_fmtlib_fmt//:fmtlib",
],
)
10 changes: 10 additions & 0 deletions examples/fmt/fmt_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>
#include <string>

#include "fmt/format.h"

int main() {
std::string s = fmt::format("I'd rather be {1} than {0}.", "right", "happy");
std::cout << s << std::endl;
return 0;
}
7 changes: 7 additions & 0 deletions examples/gtest/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc_test(
name = "hello_test",
srcs = ["hello_test.cc"],
deps = [
"@com_google_googletest//:gtest_main",
],
)
5 changes: 5 additions & 0 deletions examples/gtest/hello_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <string>

#include "gtest/gtest.h"

TEST(HelloTest, Basic) { EXPECT_EQ("Hello tester", "Hello tester"); }
7 changes: 7 additions & 0 deletions examples/libevent/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cc_binary(
name = "libevent_echosrv1",
srcs = ["libevent_echosrv1.c"],
deps = [
"//:libevent",
],
)
Loading

0 comments on commit 3373467

Please sign in to comment.