From 6aa85d5240ff5e4d29211dbf8737874e27b2ad63 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Thu, 29 Feb 2024 18:03:12 +0800 Subject: [PATCH 1/3] add virtual destructor (#612) --- include/ylt/coro_io/rate_limiter.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/ylt/coro_io/rate_limiter.hpp b/include/ylt/coro_io/rate_limiter.hpp index 62340b775..bb2372770 100644 --- a/include/ylt/coro_io/rate_limiter.hpp +++ b/include/ylt/coro_io/rate_limiter.hpp @@ -42,6 +42,8 @@ class rate_limiter { do_set_rate(permitsPerSecond, current_time_mills()); } + virtual ~rate_limiter() {} + protected: virtual void do_set_rate( double permitsPerSecond, @@ -67,6 +69,9 @@ class rate_limiter { }; class abstract_smooth_rate_limiter : public rate_limiter { + public: + virtual ~abstract_smooth_rate_limiter() {} + protected: virtual void do_set_rate(double permits_per_second, double stable_internal_micros) = 0; From fbccf7cfd1ba2da3c8f94475e9f5c5f3a0a32c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=BF=AF?= Date: Thu, 29 Feb 2024 18:01:16 +0800 Subject: [PATCH 2/3] bazel build support --- BUILD.bazel | 46 +++++++++++++++++++++++++++--- README.md | 9 ++++++ WORKSPACE | 1 + WORKSPACE.bazel | 0 src/coro_http/examples/BUILD.bazel | 23 --------------- 5 files changed, 52 insertions(+), 27 deletions(-) create mode 100644 WORKSPACE delete mode 100644 WORKSPACE.bazel delete mode 100644 src/coro_http/examples/BUILD.bazel diff --git a/BUILD.bazel b/BUILD.bazel index d291c09d8..85eda49d9 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1,13 +1,51 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") + package(default_visibility = ["//visibility:public"]) cc_library( name = "ylt", - hdrs = glob([ - "include/**", - "src/include/**" + srcs = glob([ + "include/ylt/**/*.hpp", + "include/ylt/**/*.h", + "include/ylt/**/*.ipp", ]), - includes = ["include", "include/ylt/thirdparty","src/include"], + includes = [ + "include", + "include/ylt", + "include/ylt/thirdparty", + "src/include", + ], linkopts = ["-lpthread"], visibility = ["//visibility:public"], ) + +# List one example for ylt tests. +cc_test( + name = "easylog_test", + srcs = ["src/easylog/benchmark/main.cpp"], + includes = [ + "include", + "include/ylt/thirdparty", + "src/include", + ], + deps = [":ylt"], +) + +cc_binary( + name = "coro_http_example", + srcs = ["src/coro_http/examples/example.cpp"], + copts = [ + "-fcoroutines", + "-fno-tree-slp-vectorize", # -ftree-slp-vectorize with coroutine cause link error. disable it util gcc fix. + "-Wno-unused-but-set-variable", + "-Wno-unused-value", + ], + includes = [ + "include", + "include/ylt", + "include/ylt/thirdparty", + "src/include", + ], + linkopts = ["-lpthread"], + deps = [":ylt"], +) diff --git a/README.md b/README.md index 00965132d..e2dcd8097 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,15 @@ cd build cmake .. cmake --build . --config debug # add -j, if you have enough memory to parallel compile ctest . # run tests + +``` + +- Build in bazel: +```shell +bazel build ylt # Please make sure bazel in you bin path. +bazel build coro_http_example # Or replace in anyone you want to build and test. +# Actually you might take it in other project in prefix @com_alibaba_yalangtinglibs, like +bazel build @com_alibaba_yalangtinglibs://ylt ``` You can see the test/example/benchmark executable file in `./build/output/`. diff --git a/WORKSPACE b/WORKSPACE new file mode 100644 index 000000000..54df50fca --- /dev/null +++ b/WORKSPACE @@ -0,0 +1 @@ +workspace(name = "com_alibaba_yalantinglibs") diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/coro_http/examples/BUILD.bazel b/src/coro_http/examples/BUILD.bazel deleted file mode 100644 index e9db42d44..000000000 --- a/src/coro_http/examples/BUILD.bazel +++ /dev/null @@ -1,23 +0,0 @@ -cc_binary( - name = "coro_http_example", - srcs = - [ - "example.cpp", - ], - copts = [ - "-std=c++20", - ], - deps = ["//:ylt"], -) - -cc_binary( - name = "coro_http_channel", - srcs = - [ - "channel.cpp", - ], - copts = [ - "-std=c++20", - ], - deps = ["//:ylt"], -) From c24c828330846061b74669246a2e701f303b5836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E6=BF=AF?= Date: Thu, 29 Feb 2024 18:15:11 +0800 Subject: [PATCH 3/3] more coro http example bin build --- .bazelrc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ BUILD.bazel | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 87 insertions(+), 5 deletions(-) create mode 100644 .bazelrc diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 000000000..1349acf39 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,52 @@ +# Must be first. Enables build:windows, build:linux, build:macos, build:freebsd, build:openbsd +build --enable_platform_specific_config +############################################################################### +# On Windows, provide: BAZEL_SH, and BAZEL_LLVM (if using clang-cl) +# On all platforms, provide: PYTHON3_BIN_PATH=python +############################################################################### +build --action_env=PATH +# For --compilation_mode=dbg, consider enabling checks in the standard library as well (below). +build --compilation_mode=opt +build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" +# Using C++ 20 on all platforms. +build:linux --cxxopt="-std=c++20" +build:macos --cxxopt="-std=c++20" +build:clang-cl --cxxopt="-std=c++20" +build:msvc-cl --cxxopt="/std:c++20" +build:windows --cxxopt="/std:c++20" +# This workaround is needed to prevent Bazel from compiling the same file twice (once PIC and once not). +build:linux --force_pic +build:macos --force_pic +build:clang-cl --compiler=clang-cl +build:msvc-cl --compiler=msvc-cl +# `LC_ALL` and `LANG` is needed for cpp worker tests, because they will call "ray start". +# If we don't add them, python's `click` library will raise an error. +build --action_env=LC_ALL +build --action_env=LANG +# Allow C++ worker tests to execute "ray start" with the correct version of Python. +build --action_env=VIRTUAL_ENV +build --action_env=PYENV_VIRTUAL_ENV +build --action_env=PYENV_VERSION +build --action_env=PYENV_SHELL +# This is needed for some core tests to run correctly +build:windows --enable_runfiles +build:linux --per_file_copt="-\\.(asm|S)$@-Werror" +build:macos --per_file_copt="-\\.(asm|S)$@-Werror" +build:clang-cl --per_file_copt="-\\.(asm|S)$@-Werror" +build:msvc-cl --per_file_copt="-\\.(asm|S)$@-WX" +# Ignore warnings for protobuf generated files and external projects. +build --per_file_copt="\\.pb\\.cc$@-w" +build --per_file_copt="-\\.(asm|S)$,external/.*@-w" +#build --per_file_copt="external/.*@-Wno-unused-result" +# Ignore minor warnings for host tools, which we generally can't control +build:clang-cl --host_copt="-Wno-inconsistent-missing-override" +build:clang-cl --host_copt="-Wno-microsoft-unqualified-friend" +# This workaround is needed due to https://github.com/bazelbuild/bazel/issues/4341 +build --per_file_copt="-\\.(asm|S)$,external/com_github_grpc_grpc/.*@-DGRPC_BAZEL_BUILD" +# Don't generate warnings about kernel features we don't need https://github.com/ray-project/ray/issues/6832 +build:linux --per_file_copt="-\\.(asm|S)$,external/com_github_grpc_grpc/.*@-DGPR_MANYLINUX1" +# Ignore wchar_t -> char conversion warning on MSVC +build:msvc-cl --per_file_copt="external/boost/libs/regex/src/wc_regex_traits\\.cpp@-wd4244" +build --http_timeout_scaling=5.0 +build --verbose_failures + diff --git a/BUILD.bazel b/BUILD.bazel index 85eda49d9..34759bac1 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -2,6 +2,13 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") package(default_visibility = ["//visibility:public"]) +YA_BIN_COPT = [ + "-fcoroutines", + "-fno-tree-slp-vectorize", # -ftree-slp-vectorize with coroutine cause link error. disable it util gcc fix. + "-Wno-unused-but-set-variable", + "-Wno-unused-value", +] + cc_library( name = "ylt", srcs = glob([ @@ -34,12 +41,35 @@ cc_test( cc_binary( name = "coro_http_example", srcs = ["src/coro_http/examples/example.cpp"], - copts = [ - "-fcoroutines", - "-fno-tree-slp-vectorize", # -ftree-slp-vectorize with coroutine cause link error. disable it util gcc fix. - "-Wno-unused-but-set-variable", - "-Wno-unused-value", + copts = YA_BIN_COPT, + includes = [ + "include", + "include/ylt", + "include/ylt/thirdparty", + "src/include", + ], + linkopts = ["-lpthread"], + deps = [":ylt"], +) + +cc_binary( + name = "coro_http_channel", + srcs = ["src/coro_http/examples/channel.cpp"], + copts = YA_BIN_COPT, + includes = [ + "include", + "include/ylt", + "include/ylt/thirdparty", + "src/include", ], + linkopts = ["-lpthread"], + deps = [":ylt"], +) + +cc_binary( + name = "coro_http_chat_room", + srcs = ["src/coro_http/examples/chat_room.cpp"], + copts = YA_BIN_COPT, includes = [ "include", "include/ylt",