1# Bazel* build support 2 3The main build system of oneTBB is CMake*. 4[Bazel*](https://bazel.build/) support is community-based. 5The Bazel configuration may not include recommended compiler and/or linker flags used in the official CMake configuration. 6 7--- 8**NOTE** 9 10Bazel is not recommended for use by oneTBB maintainers. Thus, it is not used internally. 11 12--- 13 14 15The Bazel oneTBB build is currently only intended for a subset of oneTBB that suffices restricted use cases. 16Pull requests to improve the Bazel build experience are welcome. 17 18The standard Bazel approach to handling third-party libraries is static linking. It is the best practice within the Bazel ecosystem. 19 20## Using oneTBB as a dependency 21 22This example demonstrates how to use oneTBB as a dependency within a Bazel project. 23 24The following file structure is assumed: 25 26``` 27example 28├── .bazelrc 29├── BUILD.bazel 30├── main.cpp 31└── WORKSPACE.bazel 32``` 33 34_WORKSPACE.bazel_: 35```python 36load("@platforms//tools/build_defs/repo:git.bzl", "git_repository") 37 38git_repository( 39 name = "oneTBB", 40 branch = "master", 41 remote = "https://github.com/oneapi-src/oneTBB/", 42) 43``` 44 45In the *WORKSPACE* file, the oneTBB GitHub* repository is fetched. 46 47_BUILD.bazel_: 48 49```python 50cc_binary( 51 name = "Demo", 52 srcs = ["main.cpp"], 53 deps = ["@oneTBB//:tbb"], 54) 55``` 56 57The *BUILD* file defines a binary named `Demo` that has a dependency to oneTBB. 58 59_main.cpp_: 60 61```c++ 62#include "oneapi/tbb/version.h" 63 64#include <iostream> 65 66int main() { 67 std::cout << "Hello from oneTBB " 68 << TBB_VERSION_MAJOR << "." 69 << TBB_VERSION_MINOR << "." 70 << TBB_VERSION_PATCH 71 << "!" << std::endl; 72 73 return 0; 74} 75``` 76 77The expected output of this program is the current version of oneTBB. 78 79Switch to the folder with the files created earlier and run the binary with `bazel run //:Demo`. 80 81## Build oneTBB using Bazel 82 83Run ```bazel build //...``` in the oneTBB root directory. 84 85## Compiler support 86 87The Bazel build uses the compiler flag `-mwaitpkg` in non-Windows* builds. 88This flag is supported by the GNU* Compiler Collection (GCC) version 9.3, Clang* 12, and newer versions of those tools. 89 90 91--- 92**NOTE** 93 94To use the Bazel build with earlier versions of GCC, remove `-mwaitpkg` flag as it leads to errors during compilation. 95 96--- 97