Skip to content

Commit

Permalink
Add support for Bazel build (#442)
Browse files Browse the repository at this point in the history
Signed-off-by: Vertexwahn <julian.amann@tum.de>
  • Loading branch information
Vertexwahn committed Jul 8, 2021
1 parent 8e7f9e1 commit 6164044
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .bazelrc
@@ -0,0 +1,19 @@
# Copyright (c) 2021 Intel Corporation
#
# 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.

# DISCLAIMER: Bazel support is community-based. The maintainers do not
# use Bazel internally. The Bazel build can have security risks or
# optimization gaps.

build --symlink_prefix=/ # Out of source build
1 change: 1 addition & 0 deletions .bazelversion
@@ -0,0 +1 @@
4.1.0
112 changes: 112 additions & 0 deletions BUILD.bazel
@@ -0,0 +1,112 @@
# Copyright (c) 2021 Intel Corporation
#
# 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.

# DISCLAIMER: Bazel support is community-based. The maintainers do not
# use Bazel internally. The Bazel build can have security risks or
# optimization gaps.

package(
default_visibility = ["//visibility:public"],
)

cc_library(
name = "tbb",
srcs = glob([
"src/tbb/*.cpp",
"src/tbb/*.h",
]) + select({
"@platforms//cpu:x86_64": glob(["src/tbb/tools_api/**/*.h"]),
"//conditions:default": [],
}),
hdrs = glob([
"include/tbb/*.h",
"include/oneapi/*.h",
"include/oneapi/tbb/*.h",
"include/oneapi/tbb/detail/*.h",
]),
copts = [
"-w",
],
defines =
select({
"@platforms//cpu:x86_64": ["__TBB_NO_IMPLICIT_LINKAGE"],
"//conditions:default": [
"USE_PTHREAD",
],
}),
includes = [
"include",
],
linkopts =
select({
"@bazel_tools//platforms:windows": [],
"//conditions:default": [
"-ldl",
"-pthread",
"-lrt",
],
}),
local_defines = select({
"@platforms//cpu:x86_64": [
"__TBB_USE_ITT_NOTIFY",
],
"//conditions:default": [],
}) + [
"__TBB_BUILD",
],
textual_hdrs = select({
"@platforms//cpu:x86_64": [
"src/tbb/tools_api/ittnotify_static.c",
],
"//conditions:default": [],
}),
)

cc_library(
name = "tbbmalloc",
srcs =
glob([
"src/tbbmalloc/*.h",
"src/tbb/*.h",
"src/tbbmalloc_proxy/*.h",
]) + [
"src/tbbmalloc/backend.cpp",
"src/tbbmalloc/backref.cpp",
"src/tbbmalloc/frontend.cpp",
"src/tbbmalloc/large_objects.cpp",
"src/tbbmalloc/tbbmalloc.cpp",
],
hdrs = glob([
"include/tbb/*.h",
"include/oneapi/tbb/detail/*.h",
"include/oneapi/tbb/*.h",
]),
includes = [
"include",
],
local_defines = [
"__TBBMALLOC_BUILD",
],
)

cc_library(
name = "tbbmalloc_proxy",
srcs = [
"src/tbbmalloc_proxy/function_replacement.cpp",
"src/tbbmalloc_proxy/proxy.cpp",
],
deps = [
":tbbmalloc",
],
)
60 changes: 60 additions & 0 deletions Bazel.md
@@ -0,0 +1,60 @@
# Bazel build support

The main build system of oneTBB is CMake.
Bazel support is community-based.
The maintainers do not use Bazel internally.
The Bazel configuration may not include recommended compiler and linker flags used in official CMake configuration.

The Bazel build of oneTBB currently only aims for a subset of oneTBB that suffices restricted use cases of the usage of oneTBB.
Pull requests to improve the Bazel build experience are welcomed.

The standard approach of how Bazel handles third-party libraries is static linking.
Even this is not recommended by the oneTBB maintainers this is chosen since this is considered as the best practice in the Bazel ecosystem.

## Example usage

1. [Install Bazel](https://docs.bazel.build/versions/main/install.html).

2. Create the following files in one folder (this folder will be considered as the workspace folder):

_WORKSPACE.bazel_:
```
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "oneTBB",
branch = "master",
remote = "https://github.com/oneapi-src/oneTBB/",
)
```

_BUILD_:
```
cc_binary(
name = "Demo",
srcs = ["main.cpp"],
deps = ["@oneTBB//:tbb"],
)
```

_main.cpp_:
```
#include "oneapi/tbb/version.h"
#include <iostream>
int main() {
std::cout << "Hello from oneTBB "
<< TBB_VERSION_MAJOR << "."
<< TBB_VERSION_MINOR << "."
<< TBB_VERSION_PATCH
<< "!" << std::endl;
return 0;
}
```

3. Switch to the folder where you create the files.

4. Execute the command `bazel run //:Demo`.
As an expected output, you should see the oneTBB version.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -13,6 +13,7 @@ Here are [Release Notes]( https://software.intel.com/en-us/articles/intel-oneapi
* [oneTBB Developer Guide and Reference](https://software.intel.com/en-us/oneapi-tbb-documentation)
* [Migrating from TBB to oneTBB](https://software.intel.com/content/www/us/en/develop/documentation/onetbb-documentation/top/onetbb-developer-guide/migrating-from-threading-building-blocks-tbb.html)
* README for build system: [cmake/README.md](cmake/README.md)
* [Basic support for the Bazel build system](Bazel.md)

## Support
Please report issues and suggestions via
Expand Down
19 changes: 19 additions & 0 deletions WORKSPACE.bazel
@@ -0,0 +1,19 @@
# Copyright (c) 2021 Intel Corporation
#
# 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.

# DISCLAIMER: Bazel support is community-based. The maintainers do not
# use Bazel internally. The Bazel build can have security risks or
# optimization gaps.

workspace(name = "oneTBB")

0 comments on commit 6164044

Please sign in to comment.