Files
TheRock/rocm-systems/projects/rocprofiler-systems/external/onetbb/Bazel.md
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

2.5 KiB

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

Traditional WORKSPACE approach

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("@platforms//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "oneTBB",
    branch = "master",
    remote = "https://github.com/uxlfoundation/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.

Bzlmod

If you use Bzlmod, you can fetch oneTBB with the Bazel Central Registry.

Add the following line to your MODULE.bazel file:

bazel_dep(name = "onetbb", version = "2021.13.0")

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.