bazel build support (#613)
This commit is contained in:
parent
6aa85d5240
commit
14d1323fa6
|
@ -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
|
||||||
|
# FIXME(lingxuan.zlx) TEST CASE: test wide string crash since cxx abi off.
|
||||||
|
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:gcc-cl --cxxopt="-std=c++20"
|
||||||
|
build:gcc-cl --cxxopt="-fcoroutines"
|
||||||
|
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:gcc-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"
|
||||||
|
# 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
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name: Bazel
|
name: Bazel-Clang
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
|
@ -22,8 +22,8 @@ jobs:
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
working-directory: ${{github.workspace}}
|
working-directory: ${{github.workspace}}
|
||||||
run: bazel build --action_env=CXX=clang++-17 --action_env=CC=clang-17 ...
|
run: bazel build --config=clang-cl --action_env=CXX=clang++-17 --action_env=CC=clang-17 ...
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
working-directory: ${{github.workspace}}
|
working-directory: ${{github.workspace}}
|
||||||
run: bazel test --action_env=CXX=clang++-17 --action_env=CC=clang-17 --test_output=errors ...
|
run: bazel test --config=clang-cl --action_env=CXX=clang++-17 --action_env=CC=clang-17 --test_output=errors ...
|
|
@ -0,0 +1,24 @@
|
||||||
|
name: Bazel-GCC
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main ]
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
working-directory: ${{github.workspace}}
|
||||||
|
run: bazel build --config=gcc-cl ...
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
working-directory: ${{github.workspace}}
|
||||||
|
run: bazel test --config=gcc-cl --test_output=errors ...
|
90
BUILD.bazel
90
BUILD.bazel
|
@ -1,13 +1,95 @@
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||||
|
load("//bazel:defs.bzl", "YA_BIN_COPT", "YA_LT_COPT")
|
||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "ylt",
|
name = "ylt",
|
||||||
hdrs = glob([
|
srcs = glob([
|
||||||
"include/**",
|
"include/ylt/**/*.hpp",
|
||||||
"src/include/**"
|
"include/ylt/**/*.h",
|
||||||
|
"include/ylt/**/*.ipp",
|
||||||
|
"src/include/*.h",
|
||||||
]),
|
]),
|
||||||
includes = ["include", "include/ylt/thirdparty","src/include"],
|
copts = YA_LT_COPT,
|
||||||
|
includes = [
|
||||||
|
"include",
|
||||||
|
"include/ylt",
|
||||||
|
"include/ylt/thirdparty",
|
||||||
|
"src/include",
|
||||||
|
],
|
||||||
linkopts = ["-lpthread"],
|
linkopts = ["-lpthread"],
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# List one example for ylt tests.
|
||||||
|
cc_test(
|
||||||
|
name = "easylog_test",
|
||||||
|
srcs = [
|
||||||
|
"src/easylog/tests/main.cpp",
|
||||||
|
"src/easylog/tests/test_easylog.cpp",
|
||||||
|
],
|
||||||
|
copts = YA_BIN_COPT,
|
||||||
|
includes = [
|
||||||
|
"include",
|
||||||
|
"include/ylt/thirdparty",
|
||||||
|
"src/include",
|
||||||
|
],
|
||||||
|
deps = [":ylt"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_binary(
|
||||||
|
name = "easylog_benchmark",
|
||||||
|
srcs = [
|
||||||
|
"src/easylog/benchmark/main.cpp",
|
||||||
|
],
|
||||||
|
copts = YA_BIN_COPT,
|
||||||
|
includes = [
|
||||||
|
"include",
|
||||||
|
"include/ylt/thirdparty",
|
||||||
|
"src/include",
|
||||||
|
],
|
||||||
|
deps = [":ylt"],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_binary(
|
||||||
|
name = "coro_http_example",
|
||||||
|
srcs = ["src/coro_http/examples/example.cpp"],
|
||||||
|
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",
|
||||||
|
"include/ylt/thirdparty",
|
||||||
|
"src/include",
|
||||||
|
],
|
||||||
|
linkopts = ["-lpthread"],
|
||||||
|
deps = [":ylt"],
|
||||||
|
)
|
||||||
|
|
|
@ -64,6 +64,15 @@ cd build
|
||||||
cmake ..
|
cmake ..
|
||||||
cmake --build . --config debug # add -j, if you have enough memory to parallel compile
|
cmake --build . --config debug # add -j, if you have enough memory to parallel compile
|
||||||
ctest . # run tests
|
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/`.
|
You can see the test/example/benchmark executable file in `./build/output/`.
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
YA_LT_COPT = [
|
||||||
|
"-fno-tree-slp-vectorize", # -ftree-slp-vectorize with coroutine cause link error. disable it util gcc fix.
|
||||||
|
]
|
||||||
|
|
||||||
|
YA_BIN_COPT = [
|
||||||
|
"-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",
|
||||||
|
"-Wno-unused-variable",
|
||||||
|
"-Wno-sign-compare",
|
||||||
|
"-Wno-reorder",
|
||||||
|
"-Wno-unused-local-typedefs",
|
||||||
|
"-Wno-missing-braces",
|
||||||
|
"-Wno-uninitialized",
|
||||||
|
]
|
|
@ -186,25 +186,36 @@ void string_set_length_hacker(std::string &, std::size_t);
|
||||||
template <typename ch>
|
template <typename ch>
|
||||||
inline void resize(std::basic_string<ch> &raw_str, std::size_t sz) {
|
inline void resize(std::basic_string<ch> &raw_str, std::size_t sz) {
|
||||||
std::string &str = *reinterpret_cast<std::string *>(&raw_str);
|
std::string &str = *reinterpret_cast<std::string *>(&raw_str);
|
||||||
|
#if defined(_GLIBCXX_USE_CXX11_ABI)
|
||||||
|
constexpr bool is_use_cxx11_abi = _GLIBCXX_USE_CXX11_ABI;
|
||||||
|
#else
|
||||||
|
constexpr bool is_use_cxx11_abi = true;
|
||||||
|
#endif
|
||||||
|
if constexpr (std::is_same_v<ch, char> == false &&
|
||||||
|
is_use_cxx11_abi == false) {
|
||||||
|
raw_str.resize(sz);
|
||||||
|
}
|
||||||
|
else {
|
||||||
#if defined(__SANITIZE_ADDRESS__) || \
|
#if defined(__SANITIZE_ADDRESS__) || \
|
||||||
struct_pack_has_feature(address_sanitizer) || \
|
struct_pack_has_feature(address_sanitizer) || \
|
||||||
(!defined(NDEBUG) && defined(_MSVC_STL_VERSION))
|
(!defined(NDEBUG) && defined(_MSVC_STL_VERSION))
|
||||||
raw_str.resize(sz);
|
raw_str.resize(sz);
|
||||||
#elif defined(__GLIBCXX__) || defined(_LIBCPP_VERSION) || \
|
#elif defined(__GLIBCXX__) || defined(_LIBCPP_VERSION) || \
|
||||||
defined(_MSVC_STL_VERSION)
|
defined(_MSVC_STL_VERSION)
|
||||||
if constexpr (is_string_reserve_shrink) {
|
if constexpr (is_string_reserve_shrink) {
|
||||||
if (sz > raw_str.capacity()) {
|
if (sz > raw_str.capacity()) {
|
||||||
|
str.reserve(sz * sizeof(ch));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
str.reserve(sz * sizeof(ch));
|
str.reserve(sz * sizeof(ch));
|
||||||
}
|
}
|
||||||
}
|
string_set_length_hacker(str, sz);
|
||||||
else {
|
for (auto i = sz; i < sz + sizeof(ch); ++i) str[i] = '\0';
|
||||||
str.reserve(sz * sizeof(ch));
|
|
||||||
}
|
|
||||||
string_set_length_hacker(str, sz);
|
|
||||||
for (auto i = sz; i < sz + sizeof(ch); ++i) str[i] = '\0';
|
|
||||||
#else
|
#else
|
||||||
raw_str.resize(sz);
|
raw_str.resize(sz);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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"],
|
|
||||||
)
|
|
|
@ -1,14 +1,15 @@
|
||||||
|
load("//bazel:defs.bzl", "YA_BIN_COPT")
|
||||||
|
|
||||||
cc_binary(
|
cc_binary(
|
||||||
name = "file_client",
|
name = "file_client",
|
||||||
srcs =
|
srcs =
|
||||||
[
|
[
|
||||||
"file_client.cpp",
|
"file_client.cpp",
|
||||||
"rpc_service.h"
|
"rpc_service.h",
|
||||||
],
|
],
|
||||||
copts = [
|
copts = [
|
||||||
"-std=c++20",
|
|
||||||
"-Isrc/coro_rpc/examples/file_transfer",
|
"-Isrc/coro_rpc/examples/file_transfer",
|
||||||
],
|
] + YA_BIN_COPT,
|
||||||
deps = ["//:ylt"],
|
deps = ["//:ylt"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,11 +19,10 @@ cc_binary(
|
||||||
[
|
[
|
||||||
"file_server.cpp",
|
"file_server.cpp",
|
||||||
"rpc_service.cpp",
|
"rpc_service.cpp",
|
||||||
"rpc_service.h"
|
"rpc_service.h",
|
||||||
],
|
],
|
||||||
copts = [
|
copts = [
|
||||||
"-std=c++20",
|
|
||||||
"-Isrc/coro_rpc/examples/file_transfer",
|
"-Isrc/coro_rpc/examples/file_transfer",
|
||||||
],
|
] + YA_BIN_COPT,
|
||||||
deps = ["//:ylt"],
|
deps = ["//:ylt"],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_test")
|
|
||||||
|
|
||||||
cc_test(
|
|
||||||
name = "test_easylog",
|
|
||||||
srcs = [
|
|
||||||
"main.cpp",
|
|
||||||
"test_easylog.cpp"
|
|
||||||
],
|
|
||||||
copts = ["-std=c++20", "-I", "include"],
|
|
||||||
linkopts = ["-lpthread"],
|
|
||||||
deps = [
|
|
||||||
"//:ylt"
|
|
||||||
],
|
|
||||||
)
|
|
|
@ -1,10 +1,18 @@
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
|
||||||
|
load("//bazel:defs.bzl", "YA_BIN_COPT", "YA_LT_COPT")
|
||||||
|
|
||||||
cc_binary(
|
cc_binary(
|
||||||
name = "serialize_example",
|
name = "serialize_example",
|
||||||
srcs = ["basic_usage.cpp","main.cpp","non_aggregated_type.cpp","serialize_config.cpp","user_defined_serialization.cpp","derived_class.cpp"],
|
srcs = [
|
||||||
copts = ["-std=c++20"],
|
"basic_usage.cpp",
|
||||||
|
"derived_class.cpp",
|
||||||
|
"main.cpp",
|
||||||
|
"non_aggregated_type.cpp",
|
||||||
|
"serialize_config.cpp",
|
||||||
|
"user_defined_serialization.cpp",
|
||||||
|
],
|
||||||
|
copts = YA_BIN_COPT,
|
||||||
deps = [
|
deps = [
|
||||||
"//:ylt"
|
"//:ylt",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
load("@rules_cc//cc:defs.bzl", "cc_test")
|
load("@rules_cc//cc:defs.bzl", "cc_test")
|
||||||
|
load("//bazel:defs.bzl", "YA_BIN_COPT")
|
||||||
|
|
||||||
cc_test(
|
cc_test(
|
||||||
name = "test_serialize",
|
name = "test_serialize",
|
||||||
srcs = glob(["*.cpp"]) + ["test_struct.hpp"]+["test_derived.hpp"],
|
srcs = glob(["*.cpp"]) + ["test_struct.hpp"] + ["test_derived.hpp"],
|
||||||
copts = ["-std=c++20"],
|
copts = YA_BIN_COPT,
|
||||||
defines = ["STRUCT_PACK_ENABLE_UNPORTABLE_TYPE"],
|
|
||||||
deps = [
|
|
||||||
"//:ylt"
|
|
||||||
],
|
|
||||||
data = [
|
data = [
|
||||||
"//src/struct_pack/tests/binary_data:test_cross_platform.dat",
|
"//src/struct_pack/tests/binary_data:test_cross_platform.dat",
|
||||||
"//src/struct_pack/tests/binary_data:test_cross_platform_without_debug_info.dat"
|
"//src/struct_pack/tests/binary_data:test_cross_platform_without_debug_info.dat",
|
||||||
|
],
|
||||||
|
defines = ["STRUCT_PACK_ENABLE_UNPORTABLE_TYPE"],
|
||||||
|
deps = [
|
||||||
|
"//:ylt",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue