Skip to content

Latest commit

 

History

History
96 lines (64 loc) · 2.28 KB

Bazel.md

File metadata and controls

96 lines (64 loc) · 2.28 KB

Bazel* build support

The main build system of oneTBB is CMake*. Bazel* support is community-based. The Bazel configuration may not include recommended compiler and/or linker flags used in the official CMake configuration.


NOTE

Bazel is not recommended for use by oneTBB maintainers. Thus, it is not used internally.


The Bazel oneTBB build is currently only intended for a subset of oneTBB that suffices restricted use cases. Pull requests to improve the Bazel build experience are welcome.

The standard Bazel approach to handling third-party libraries is static linking. It is the best practice within the Bazel ecosystem.

Using oneTBB as a dependency

This example demonstrates how to use oneTBB as a dependency within a Bazel project.

The following file structure is assumed:

example
├── .bazelrc
├── BUILD.bazel
├── main.cpp
└── WORKSPACE.bazel

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/",
)

In the WORKSPACE file, the oneTBB GitHub* repository is fetched.

BUILD.bazel:

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

The BUILD file defines a binary named Demo that has a dependency to oneTBB.

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;
}

The expected output of this program is the current version of oneTBB.

Switch to the folder with the files created earlier and run the binary with bazel run //:Demo.

Build oneTBB using Bazel

Run bazel build //... in the oneTBB root directory.

Compiler support

The Bazel build uses the compiler flag -mwaitpkg in non-Windows* builds. This flag is supported by the GNU* Compiler Collection (GCC) version 9.3, Clang* 12, and newer versions of those tools.


NOTE

To use the Bazel build with earlier versions of GCC, remove -mwaitpkg flag as it leads to errors during compilation.