forked from COVESA/vsomeip
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Bazel build and adapt CMake for our CI
- Loading branch information
Milan Ziegler
committed
Jan 12, 2024
1 parent
02c199d
commit a495be4
Showing
14 changed files
with
482 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
build --experimental_cc_shared_library | ||
build --experimental_cc_implementation_deps | ||
build --cxxopt "-std=c++17" | ||
|
||
# Enable new platform resolution for C/+++ | ||
build --incompatible_enable_cc_toolchain_resolution | ||
|
||
# Be strict on environment variables passed | ||
build --incompatible_strict_action_env | ||
|
||
## Address sanitizer | ||
build:asan --define SANITIZERS_ASAN_ON=true | ||
build:asan --copt="-fsanitize=address" | ||
build:asan --copt="-no-canonical-prefixes" | ||
build:asan --copt="-fno-omit-frame-pointer" | ||
build:asan --copt="-fno-sanitize-recover" | ||
build:asan --copt="-DADDRESS_SANITIZER" | ||
build:asan --linkopt="-fsanitize=address" | ||
build:asan --strip=never | ||
build:asan --action_env=ASAN_OPTIONS=detect_leaks=1:color=always | ||
build:asan --action_env=LSAN_OPTIONS="report_objects=1" | ||
build:asan --cc_output_directory_tag=asan | ||
|
||
## Thread sanitizer | ||
build:tsan --define SANITIZERS_TSAN_ON=true | ||
build:tsan --copt="-fsanitize=thread" | ||
build:tsan --copt="-fno-omit-frame-pointer" | ||
build:tsan --copt="-fno-sanitize-recover" | ||
build:tsan --copt="-DTHREAD_SANITIZER" | ||
build:tsan --linkopt="-fsanitize=thread" | ||
build:tsan --strip=never | ||
build:tsan --action_env=TSAN_OPTIONS="report_objects=1" | ||
build:tsan --cc_output_directory_tag=tsan | ||
|
||
## UndefinedBehavior sanitizer | ||
build:ubsan --define SANITIZERS_UBSAN_ON=true | ||
build:ubsan --copt="-fsanitize=undefined" | ||
build:ubsan --copt="-fno-omit-frame-pointer" | ||
build:ubsan --copt="-fno-sanitize-recover" | ||
build:ubsan --copt="-DUNDEFINED_BEHAVIOR_SANITIZER" | ||
build:ubsan --linkopt="-fsanitize=undefined" | ||
build:ubsan --linkopt="-lubsan" | ||
build:ubsan --strip=never | ||
build:ubsan --action_env=UBSAN_OPTIONS="halt_on_error=1:print_stacktrace=1" | ||
build:ubsan --cc_output_directory_tag=ubsan |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
cc_shared_library( | ||
name = "vsomeip3_shared", | ||
shared_lib_name = "libvsomeip3.so", | ||
tags = ["same-ros-pkg-as: vsomeip3"], | ||
# Disabled due to linking problem when used as an external repository with sanitizers enabled. | ||
#user_link_flags = [ | ||
# "-Wl,--no-undefined", | ||
#], | ||
deps = [ | ||
"//implementation", | ||
], | ||
) | ||
|
||
cc_shared_library( | ||
name = "vsomeip3_config_plugin", | ||
dynamic_deps = [ | ||
":vsomeip3_shared", | ||
], | ||
shared_lib_name = "libvsomeip3-cfg.so.3", | ||
tags = ["same-ros-pkg-as: vsomeip3"], | ||
# Disabled due to linking problem when used as an external repository with sanitizers enabled. | ||
#user_link_flags = [ | ||
# "-Wl,--no-undefined", | ||
#], | ||
deps = [ | ||
"//implementation:configuration", | ||
], | ||
) | ||
|
||
cc_shared_library( | ||
name = "vsomeip3_sd_plugin", | ||
dynamic_deps = [ | ||
":vsomeip3_shared", | ||
], | ||
shared_lib_name = "libvsomeip3-sd.so.3", | ||
tags = ["same-ros-pkg-as: vsomeip3"], | ||
# Disabled due to linking problem when used as an external repository with sanitizers enabled. | ||
#user_link_flags = [ | ||
# "-Wl,--no-undefined", | ||
#], | ||
deps = [ | ||
"//implementation:service_discovery", | ||
], | ||
) | ||
|
||
cc_import( | ||
name = "vsomeip3_import", | ||
shared_library = ":vsomeip3_shared", | ||
tags = ["same-ros-pkg-as: vsomeip3"], | ||
deps = [ | ||
"//interface", | ||
], | ||
) | ||
|
||
# interface library, use this target to depend on vsomeip | ||
cc_library( | ||
name = "vsomeip3", | ||
data = [ | ||
":vsomeip3_config_plugin", | ||
":vsomeip3_sd_plugin", | ||
], | ||
linkstatic = True, # no object files | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
":vsomeip3_import", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
workspace(name = "vsomeip") | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
|
||
BOOST_VERSION = "1.81.0" | ||
|
||
BOOST_VERSION_us = BOOST_VERSION.replace(".", "_") | ||
|
||
http_archive( | ||
name = "boost", | ||
build_file = "@//:boost.BUILD", | ||
sha256 = "71feeed900fbccca04a3b4f2f84a7c217186f28a940ed8b7ed4725986baf99fa", | ||
strip_prefix = "boost_{version_underscore}".format(version_underscore = BOOST_VERSION_us), | ||
urls = ["https://boostorg.jfrog.io/artifactory/main/release/{version}/source/boost_{version_underscore}.tar.bz2".format( | ||
version = BOOST_VERSION, | ||
version_underscore = BOOST_VERSION_us, | ||
)], | ||
) | ||
|
||
GOOGLETEST_VERSION = "1.11.0" | ||
|
||
http_archive( | ||
name = "googletest", | ||
sha256 = "353571c2440176ded91c2de6d6cd88ddd41401d14692ec1f99e35d013feda55a", | ||
strip_prefix = "googletest-release-{version}".format(version = GOOGLETEST_VERSION), | ||
urls = ["https://github.com/google/googletest/archive/refs/tags/release-{version}.zip".format(version = GOOGLETEST_VERSION)], | ||
) | ||
|
||
# GOOGLETEST dependencies, taken from: https://raw.githubusercontent.com/google/googletest/release-1.11.0/WORKSPACE | ||
http_archive( | ||
name = "com_google_absl", | ||
sha256 = "aeba534f7307e36fe084b452299e49b97420667a8d28102cf9a0daeed340b859", | ||
strip_prefix = "abseil-cpp-7971fb358ae376e016d2d4fc9327aad95659b25e", | ||
urls = ["https://github.com/abseil/abseil-cpp/archive/7971fb358ae376e016d2d4fc9327aad95659b25e.zip"], # 2021-05-20T02:59:16Z | ||
) | ||
|
||
http_archive( | ||
name = "rules_cc", | ||
sha256 = "1e19e9a3bc3d4ee91d7fcad00653485ee6c798efbbf9588d40b34cbfbded143d", | ||
strip_prefix = "rules_cc-68cb652a71e7e7e2858c50593e5a9e3b94e5b9a9", | ||
urls = ["https://github.com/bazelbuild/rules_cc/archive/68cb652a71e7e7e2858c50593e5a9e3b94e5b9a9.zip"], # 2021-05-14T14:51:14Z | ||
) | ||
|
||
http_archive( | ||
name = "rules_python", | ||
sha256 = "98b3c592faea9636ac8444bfd9de7f3fb4c60590932d6e6ac5946e3f8dbd5ff6", | ||
strip_prefix = "rules_python-ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2", | ||
urls = ["https://github.com/bazelbuild/rules_python/archive/ed6cc8f2c3692a6a7f013ff8bc185ba77eb9b4d2.zip"], # 2021-05-17T00:24:16Z | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
""" | ||
The configure_file rule imitates the similar CMake function for generating code: https://cmake.org/cmake/help/latest/command/configure_file.html | ||
""" | ||
|
||
def _cmake_like_configure_file_impl(ctx): | ||
ctx.actions.expand_template( | ||
template = ctx.file.src, | ||
output = ctx.outputs.out, | ||
substitutions = { | ||
"@" + k + "@": v | ||
for k, v in ctx.attr.config.items() | ||
}, | ||
) | ||
files = depset(direct = [ctx.outputs.out]) | ||
runfiles = ctx.runfiles(files = [ctx.outputs.out]) | ||
return [DefaultInfo(files = files, runfiles = runfiles)] | ||
|
||
cmake_like_configure_file = rule( | ||
implementation = _cmake_like_configure_file_impl, | ||
provides = [DefaultInfo], | ||
attrs = { | ||
"src": attr.label(mandatory = True, allow_single_file = True), | ||
"out": attr.output(mandatory = True), | ||
"config": attr.string_dict(mandatory = True), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
||
cc_library( | ||
name = "headers", | ||
hdrs = glob( | ||
[ | ||
"boost/**", | ||
], | ||
), | ||
local_defines = ["BOOST_ALL_NO_LIB"], | ||
include_prefix = ".", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "_thread_detail", | ||
hdrs = select({ | ||
"@platforms//os:linux": ["libs/thread/src/pthread/once_atomic.cpp"], | ||
"//conditions:default": [], | ||
}), | ||
strip_include_prefix = "libs/thread/src/pthread", | ||
) | ||
|
||
cc_library( | ||
name = "thread", | ||
srcs = glob( | ||
[ | ||
"libs/thread/src/*.cpp", | ||
], | ||
) + select({ | ||
"@platforms//os:linux": [ | ||
"libs/thread/src/pthread/once.cpp", | ||
"libs/thread/src/pthread/thread.cpp", | ||
], | ||
"//conditions:default": [], | ||
}), | ||
implementation_deps = [ | ||
":_thread_detail", | ||
], | ||
linkopts = select({ | ||
"@platforms//os:linux": ["-lpthread"], | ||
"//conditions:default": [], | ||
}), | ||
deps = [ | ||
":headers", | ||
], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
cc_library( | ||
name = "filesystem", | ||
srcs = glob( | ||
[ | ||
"libs/filesystem/src/**", | ||
], | ||
), | ||
defines = [ | ||
"BOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF" | ||
], | ||
deps = [ | ||
":headers", | ||
], | ||
visibility = ["//visibility:public"], | ||
) |
Oops, something went wrong.
a495be4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@milan Ziegler why not add this to the main repository of vsomeip?