1# Bazel build support
2
3The main build system of oneTBB is CMake.
4Bazel support is community-based.
5The maintainers do not use Bazel internally.
6The Bazel configuration may not include recommended compiler and linker flags used in official CMake configuration.
7
8The Bazel build of oneTBB currently only aims for a subset of oneTBB that suffices restricted use cases of the usage of oneTBB.
9Pull requests to improve the Bazel build experience are welcomed.
10
11The standard approach of how Bazel handles third-party libraries is static linking.
12Even this is not recommended by the oneTBB maintainers this is chosen since this is considered as the best practice in the Bazel ecosystem.
13
14## Example usage
15
161. [Install Bazel](https://docs.bazel.build/versions/main/install.html).
17
182. Create the following files in one folder (this folder will be considered as the workspace folder):
19
20_WORKSPACE.bazel_:
21```
22load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
23
24git_repository(
25    name = "oneTBB",
26    branch = "master",
27    remote = "https://github.com/oneapi-src/oneTBB/",
28)
29```
30
31_BUILD_:
32```
33cc_binary(
34    name = "Demo",
35    srcs = ["main.cpp"],
36    deps = ["@oneTBB//:tbb"],
37)
38```
39
40_main.cpp_:
41```
42#include "oneapi/tbb/version.h"
43
44#include <iostream>
45
46int main() {
47    std::cout << "Hello from oneTBB "
48              << TBB_VERSION_MAJOR << "."
49              << TBB_VERSION_MINOR << "."
50              << TBB_VERSION_PATCH
51              << "!" << std::endl;
52
53    return 0;
54}
55```
56
573. Switch to the folder where you create the files.
58
594. Execute the command `bazel run //:Demo`.
60As an expected output, you should see the oneTBB version.
61