17c7be274SAlexandra# Bazel* build support 261640445SVertexwahn 37c7be274SAlexandraThe main build system of oneTBB is CMake*. 47c7be274SAlexandra[Bazel*](https://bazel.build/) support is community-based. 501a68ed7SVertexwahnThe Bazel configuration may not include recommended compiler and/or linker flags used in the official CMake configuration. 661640445SVertexwahn 77c7be274SAlexandra--- 87c7be274SAlexandra**NOTE** 961640445SVertexwahn 107c7be274SAlexandraBazel is not recommended for use by oneTBB maintainers. Thus, it is not used internally. 117c7be274SAlexandra 127c7be274SAlexandra--- 137c7be274SAlexandra 147c7be274SAlexandra 157c7be274SAlexandraThe Bazel oneTBB build is currently only intended for a subset of oneTBB that suffices restricted use cases. 167c7be274SAlexandraPull requests to improve the Bazel build experience are welcome. 177c7be274SAlexandra 187c7be274SAlexandraThe standard Bazel approach to handling third-party libraries is static linking. It is the best practice within the Bazel ecosystem. 1961640445SVertexwahn 2001a68ed7SVertexwahn## Using oneTBB as a dependency 2161640445SVertexwahn 227c7be274SAlexandraThis example demonstrates how to use oneTBB as a dependency within a Bazel project. 2361640445SVertexwahn 2401a68ed7SVertexwahnThe following file structure is assumed: 2501a68ed7SVertexwahn 2601a68ed7SVertexwahn``` 2701a68ed7SVertexwahnexample 2801a68ed7SVertexwahn├── .bazelrc 2901a68ed7SVertexwahn├── BUILD.bazel 3001a68ed7SVertexwahn├── main.cpp 3101a68ed7SVertexwahn└── WORKSPACE.bazel 3201a68ed7SVertexwahn``` 3361640445SVertexwahn 3461640445SVertexwahn_WORKSPACE.bazel_: 3501a68ed7SVertexwahn```python 36*e6104c95SVertexwahnload("@platforms//tools/build_defs/repo:git.bzl", "git_repository") 3761640445SVertexwahn 3861640445SVertexwahngit_repository( 3961640445SVertexwahn name = "oneTBB", 4061640445SVertexwahn branch = "master", 4161640445SVertexwahn remote = "https://github.com/oneapi-src/oneTBB/", 4261640445SVertexwahn) 4361640445SVertexwahn``` 4461640445SVertexwahn 457c7be274SAlexandraIn the *WORKSPACE* file, the oneTBB GitHub* repository is fetched. 4601a68ed7SVertexwahn 4701a68ed7SVertexwahn_BUILD.bazel_: 4801a68ed7SVertexwahn 4901a68ed7SVertexwahn```python 5061640445SVertexwahncc_binary( 5161640445SVertexwahn name = "Demo", 5261640445SVertexwahn srcs = ["main.cpp"], 5361640445SVertexwahn deps = ["@oneTBB//:tbb"], 5461640445SVertexwahn) 5561640445SVertexwahn``` 5661640445SVertexwahn 5701a68ed7SVertexwahnThe *BUILD* file defines a binary named `Demo` that has a dependency to oneTBB. 5801a68ed7SVertexwahn 5961640445SVertexwahn_main.cpp_: 6001a68ed7SVertexwahn 6101a68ed7SVertexwahn```c++ 6261640445SVertexwahn#include "oneapi/tbb/version.h" 6361640445SVertexwahn 6461640445SVertexwahn#include <iostream> 6561640445SVertexwahn 6661640445SVertexwahnint main() { 6761640445SVertexwahn std::cout << "Hello from oneTBB " 6861640445SVertexwahn << TBB_VERSION_MAJOR << "." 6961640445SVertexwahn << TBB_VERSION_MINOR << "." 7061640445SVertexwahn << TBB_VERSION_PATCH 7161640445SVertexwahn << "!" << std::endl; 7261640445SVertexwahn 7361640445SVertexwahn return 0; 7461640445SVertexwahn} 7561640445SVertexwahn``` 7661640445SVertexwahn 777c7be274SAlexandraThe expected output of this program is the current version of oneTBB. 7861640445SVertexwahn 797c7be274SAlexandraSwitch to the folder with the files created earlier and run the binary with `bazel run //:Demo`. 8001a68ed7SVertexwahn 8101a68ed7SVertexwahn## Build oneTBB using Bazel 8201a68ed7SVertexwahn 837c7be274SAlexandraRun ```bazel build //...``` in the oneTBB root directory. 8401a68ed7SVertexwahn 8501a68ed7SVertexwahn## Compiler support 8601a68ed7SVertexwahn 877c7be274SAlexandraThe Bazel build uses the compiler flag `-mwaitpkg` in non-Windows* builds. 887c7be274SAlexandraThis flag is supported by the GNU* Compiler Collection (GCC) version 9.3, Clang* 12, and newer versions of those tools. 897c7be274SAlexandra 907c7be274SAlexandra 917c7be274SAlexandra--- 927c7be274SAlexandra**NOTE** 937c7be274SAlexandra 947c7be274SAlexandraTo use the Bazel build with earlier versions of GCC, remove `-mwaitpkg` flag as it leads to errors during compilation. 957c7be274SAlexandra 967c7be274SAlexandra--- 97