Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support build efsw in bazel toolchain #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# NOTE(lingxuan.zlx): this bazelrc is partial copy for ray project and remove some unrelated.
# 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++ 17 on all platforms.
build:linux --cxxopt="-std=c++17"
build:macos --cxxopt="-std=c++17"
build:clang-cl --cxxopt="-std=c++17"
build:msvc-cl --cxxopt="/std:c++17"
build:windows --cxxopt="/std:c++17"
build:linux --force_pic
build:macos --force_pic
build:clang-cl --compiler=clang-cl
build:msvc-cl --compiler=msvc-cl
build --action_env=LC_ALL
build --action_env=LANG
# This is needed for some core tests to run correctly
build:windows --enable_runfiles
# Warnings should be errors
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"

# Print relative paths when possible
build:windows --attempt_to_print_relative_paths
# Save disk space by hardlinking cache hits instead of copying
build:windows --experimental_repository_cache_hardlinks
# Clean the environment before building, to make builds more deterministic
build:windows --incompatible_strict_action_env
# For colored output (seems necessary on Windows)
build:windows --color=yes
# For compiler colored output (seems necessary on Windows)
build:clang-cl --per_file_copt="-\\.(asm|S)$@-fansi-escape-codes"
build:clang-cl --per_file_copt="-\\.(asm|S)$@-fcolor-diagnostics"

# LLVM (clang & libc++) build flags common across Linux installations and systems.
# On Ubuntu, the remaining configurations can be generated by running ci/travis/install-llvm-binaries.sh
build:llvm --action_env=CXXFLAGS=-stdlib=libc++
build:llvm --action_env=LDFLAGS=-stdlib=libc++
build:llvm --action_env=BAZEL_CXXOPTS=-stdlib=libc++
build:llvm --action_env=BAZEL_LINKLIBS=-l%:libc++.a:-l%:libc++abi.a
build:llvm --action_env=BAZEL_LINKOPTS=-lm:-pthread
build:llvm --define force_libcpp=enabled

# Thread sanitizer configuration:
build:tsan --strip=never
build:tsan --copt -fsanitize=thread
build:tsan --copt -DTHREAD_SANITIZER
build:tsan --copt -O2
build:tsan --copt -g
build:tsan --copt -fno-omit-frame-pointer
build:tsan --copt -Wno-uninitialized
build:tsan --linkopt -fsanitize=thread
# This config is only for running TSAN with LLVM toolchain on Linux.
build:tsan-clang --config=tsan
build:tsan-clang --config=llvm
test:tsan --test_env=TSAN_OPTIONS="report_atomic_races=0"

# Memory sanitizer configuration
build:asan --strip=never
build:asan --copt -g
build:asan --copt -fsanitize=address
build:asan --copt -DADDRESS_SANITIZER
build:asan --copt -fno-omit-frame-pointer
build:asan --linkopt -fsanitize=address
test:asan --jobs=1
test:asan --test_env=ASAN_OPTIONS="detect_leaks=0"
# This config is only for running ASAN with LLVM toolchain on Linux.
# https://github.com/google/sanitizers/issues/1017
build:asan-clang --config=asan
build:asan-clang --config=llvm
build:asan-clang --copt -mllvm
build:asan-clang --copt -asan-use-private-alias=1

build:asan-build --strip=never
build:asan-build -c dbg
build:asan-build --copt -fsanitize=address
build:asan-build --copt -DADDRESS_SANITIZER
build:asan-build --copt -O1
build:asan-build --copt -g
build:asan-build --copt -fno-omit-frame-pointer
build:asan-build --copt -static-libasan
build:asan-build --linkopt -fsanitize=address
build:asan-build --linkopt -static-libasan
# For example, for Ubuntu 18.04 libasan can be found here:
# test:asan --test_env=LD_PRELOAD="/usr/lib/gcc/x86_64-linux-gnu/7/libasan.so"
test:asan-buildkite --test_env=LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libasan.so.5"

# CI configuration:
aquery:ci --color=no
aquery:ci --noshow_progress
build:ci --color=yes
build:ci --curses=no
build:ci --keep_going
build:ci --progress_report_interval=100
build:ci --show_progress_rate_limit=15
build:ci --show_task_finish
build:ci --ui_actions_shown=1024
build:ci --show_timestamps
test:ci --flaky_test_attempts=3
# Disable test result caching because py_test under Bazel can import from outside of sandbox, but Bazel only looks at
# declared dependencies to determine if a result should be cached. More details at:
# https://github.com/bazelbuild/bazel/issues/7091, https://github.com/bazelbuild/rules_python/issues/382
test:ci --nocache_test_results
test:ci --spawn_strategy=local
test:ci --test_output=errors
test:ci --test_verbose_timeout_warnings
test:ci-debug -c dbg
test:ci-debug --copt="-g"
test:ci-debug --flaky_test_attempts=3
# Disable test result caching for the same reason above.
test:ci-debug --nocache_test_results
test:ci-debug --spawn_strategy=local
test:ci-debug --test_output=errors
test:ci-debug --test_verbose_timeout_warnings

aquery:get-toolchain --include_commandline=false
aquery:get-toolchain --noimplicit_deps

# [Linux] Uncomment this line (or use --config) to print a stack trace on exit.
#test:linux --config=strace
test:strace --run_under="bash -c 'if command -v strace >/dev/null && strace -qq -k -e exit true 2>/dev/null; then strace -qq -k -e exit -e trace=\"!all\" -s 32768 -f -o >(awk \"/^[0-9]+ / { y = \\$3 != \\\"SIGCHLD\\\" && \\$3 != \\\"SIGTERM\\\" && \\$5 != \\\"SIGTERM\\\" && \\$5 != \\\"SIGKILL2\\\"; } y { print; }\" 1>&2 && cat 1>&2) -- \"$@\"; else \"$@\"; fi' -"
# [Linux] Uncomment this line (or use --config) to preload libSegFault.so if available, to print a stack trace on aborts and segfault. (Note: This doesn't always work.)
#test:linux --config=segfault
test:segfault --run_under="bash -c 'unset GREP_OPTIONS && if ! grep -q -o Microsoft /proc/version 2>/dev/null; then libs=\"$(command -v ldconfig >/dev/null && ldconfig -p | grep -F -o -e \"libSegFault.so\" | uniq | tr \"\\\\n\" :)\" && if [ -n \"${libs%:}\" ]; then export SEGFAULT_SIGNALS=\"abrt segv\" LD_PRELOAD=\"${libs}${LD_PRELOAD-}\"; fi; fi && \"$@\"' -"

# Debug build:
build:debug -c dbg
build:debug --copt="-g"
build:debug --strip="never"

# Undefined Behavior Sanitizer
build:ubsan --strip=never
build:ubsan --copt -fsanitize=undefined
build:ubsan --copt -fno-sanitize=vptr
build:ubsan --copt -fno-sanitize-recover=all
build:ubsan --copt -g
build:ubsan --linkopt -fsanitize=undefined
build:ubsan --linkopt -fno-sanitize-recover=all

# Import local specific llvm config options, which can be generated by
# ci/travis/install-llvm-dependencies.sh
try-import %workspace%/.llvm-local.bazelrc
112 changes: 112 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Bazel build
# C/C++ documentation: https://docs.bazel.build/versions/master/be/c-cpp.html
package(
default_visibility = ["//visibility:public"],
)

config_setting(
name = "msvc-cl",
flag_values = {"@bazel_tools//tools/cpp:compiler": "msvc-cl"},
)

config_setting(
name = "clang-cl",
flag_values = {"@bazel_tools//tools/cpp:compiler": "clang-cl"},
)

config_setting(
name = "opt",
values = {"compilation_mode": "opt"},
)

cc_library(
name = "efsw",
srcs = [
"src/efsw/Debug.cpp",
"src/efsw/DirectorySnapshot.cpp",
"src/efsw/DirectorySnapshotDiff.cpp",
"src/efsw/DirWatcherGeneric.cpp",
"src/efsw/FileInfo.cpp",
"src/efsw/FileSystem.cpp",
"src/efsw/FileWatcher.cpp",
"src/efsw/FileWatcherCWrapper.cpp",
"src/efsw/FileWatcherGeneric.cpp",
"src/efsw/FileWatcherImpl.cpp",
"src/efsw/Log.cpp",
"src/efsw/Mutex.cpp",
"src/efsw/String.cpp",
"src/efsw/System.cpp",
"src/efsw/Thread.cpp",
"src/efsw/Watcher.cpp",
"src/efsw/WatcherGeneric.cpp",
"src/efsw/platform/platformimpl.hpp",
"src/efsw/Utf.inl",
] + select({
"@bazel_tools//src/conditions:windows": glob([
"src/efsw/platform/win/*.cpp",
]) + [
"src/efsw/FileWatcherWin32.cpp",
"src/efsw/WatcherWin32.cpp",
],
"//conditions:default": glob([
"src/efsw/platform/posix/*.cpp",
]),
}) +
select({
"@bazel_tools//src/conditions:darwin": [
"src/efsw/FileWatcherFSEvents.cpp",
"src/efsw/FileWatcherKqueue.cpp",
"src/efsw/WatcherFSEvents.cpp",
"src/efsw/WatcherKqueue.cpp",
],
"@bazel_tools//src/conditions:linux_x86_64": [
"src/efsw/FileWatcherInotify.cpp",
"src/efsw/WatcherInotify.cpp",
],
"//conditions:default": [],
}),
hdrs = glob([
"src/efsw/*.h",
"src/efsw/platform/*.hpp",
"src/efsw/platform/posix/*.hpp",
"src/efsw/platform/win/*.hpp",
"src/efsw/*.hpp",
]),
linkopts = [
"-lpthread",
],
includes = [
"src/efsw",
],
linkstatic = True,
strip_include_prefix = "src",
deps = [
":efsw_header",
],
)

cc_library(
name = "efsw_header",
srcs = [
"include/efsw/efsw.h",
"include/efsw/efsw.hpp",
],
hdrs = glob([
"include/*.h",
"include/*.hpp",
]),
includes = [
"include",
],
linkstatic = True,
strip_include_prefix = "include",
)

cc_test(
name = "efsw_test",
srcs = ["src/test/efsw-test.cpp",
],
deps = [
":efsw",
],
)
5 changes: 5 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
workspace(name = "com_github_efsw")

# LOAD WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
# When the bazel version is updated, make sure to update it