Skip to content

Commit 5d36cb9

Browse files
authored
Unbundle tbb from the project (#384)
* Init implementation * Boh non va * Fix windows * Formatting * Update Readme * Bump version * Missing tbb
1 parent b95f0c9 commit 5d36cb9

File tree

11 files changed

+49
-113
lines changed

11 files changed

+49
-113
lines changed

.github/workflows/benchmark_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Install dependencies
1818
run: |
1919
sudo apt update
20-
sudo apt install -y build-essential cmake libhwloc-dev
20+
sudo apt install -y build-essential cmake libtbb-dev
2121
2222
- name: Build in Release mode with benchmarks
2323
working-directory: ${{ github.workspace }}

.github/workflows/binding.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,24 @@ jobs:
3232
if: matrix.os == 'ubuntu-latest'
3333
run: |
3434
sudo apt update
35-
sudo apt install -y cmake build-essential doxygen
35+
sudo apt install -y cmake build-essential doxygen libtbb-dev
3636
3737
- name: Install system dependencies (macOS)
3838
if: matrix.os == 'macos-latest'
3939
run: |
40-
brew install cmake doxygen
40+
brew install cmake doxygen tbb
4141
4242
- name: Install system dependencies (Windows)
4343
if: matrix.os == 'windows-latest'
4444
run: |
4545
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
4646
choco install doxygen.install
47+
git clone https://github.com/microsoft/vcpkg.git vcpkg
48+
cd vcpkg
49+
.\bootstrap-vcpkg.bat
50+
.\vcpkg install tbb:x64-windows
51+
echo "CMAKE_TOOLCHAIN_FILE=$env:GITHUB_WORKSPACE\vcpkg\scripts\buildsystems\vcpkg.cmake" >> $env:GITHUB_ENV
52+
echo "VCPKG_TARGET_TRIPLET=x64-windows" >> $env:GITHUB_ENV
4753
4854
- name: Upgrade pip and install build dependencies
4955
run: |
@@ -180,7 +186,7 @@ jobs:
180186
- name: Install system dependencies
181187
run: |
182188
sudo apt update
183-
sudo apt install -y cmake build-essential doxygen
189+
sudo apt install -y cmake build-essential doxygen libtbb-dev
184190
185191
- name: Install development dependencies
186192
run: |

.github/workflows/cmake_examples.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ jobs:
2323
run: |
2424
if [ ${{ matrix.os }} == 'ubuntu-latest' ]; then
2525
sudo apt update
26-
sudo apt install binutils
26+
sudo apt install binutils libtbb-dev
27+
elif [ ${{ matrix.os }} == 'macos-latest' ]; then
28+
brew install tbb
2729
fi
2830
2931
- uses: actions/checkout@v4

.github/workflows/cmake_tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ jobs:
2222
if: matrix.os == 'ubuntu-latest'
2323
run: |
2424
sudo apt update
25-
sudo apt install -y lcov gcovr build-essential cmake libhwloc-dev
25+
sudo apt install -y lcov gcovr build-essential cmake libtbb-dev
26+
27+
- name: Install dependencies on macOS
28+
if: matrix.os == 'macos-latest'
29+
run: brew install tbb
2630

2731
- name: Install dependencies on Windows (vcpkg)
2832
if: matrix.os == 'windows-latest'
@@ -31,6 +35,7 @@ jobs:
3135
git clone https://github.com/microsoft/vcpkg.git vcpkg
3236
cd vcpkg
3337
.\bootstrap-vcpkg.bat
38+
.\vcpkg install tbb:x64-windows
3439
echo "VCPKG_ROOT=$env:GITHUB_WORKSPACE\vcpkg" >> $env:GITHUB_ENV
3540
echo "VCPKG_INSTALLED=$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows" >> $env:GITHUB_ENV
3641

.github/workflows/codeql.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
with:
2929
languages: ${{ matrix.language }}
3030

31+
- name: Install dependencies
32+
run: |
33+
sudo apt update
34+
sudo apt install -y libtbb-dev
35+
3136
- name: Build C++
3237
run: |
3338
mkdir -p build && cd build

.github/workflows/pypi.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ jobs:
7979
- name: Install system dependencies
8080
run: |
8181
sudo apt update
82-
sudo apt install -y cmake build-essential doxygen
82+
sudo apt install -y cmake build-essential doxygen libtbb-dev
8383
8484
- name: Install build dependencies
8585
run: |
@@ -127,7 +127,7 @@ jobs:
127127

128128
- name: Install system dependencies
129129
run: |
130-
brew install cmake doxygen
130+
brew install cmake doxygen tbb
131131
132132
- name: Install build dependencies
133133
run: |
@@ -175,6 +175,12 @@ jobs:
175175
run: |
176176
choco install cmake --installargs 'ADD_CMAKE_TO_PATH=System'
177177
choco install doxygen.install
178+
git clone https://github.com/microsoft/vcpkg.git vcpkg
179+
cd vcpkg
180+
.\bootstrap-vcpkg.bat
181+
.\vcpkg install tbb:x64-windows
182+
echo "CMAKE_TOOLCHAIN_FILE=$env:GITHUB_WORKSPACE\vcpkg\scripts\buildsystems\vcpkg.cmake" >> $env:GITHUB_ENV
183+
echo "VCPKG_TARGET_TRIPLET=x64-windows" >> $env:GITHUB_ENV
178184
179185
- name: Install build dependencies
180186
run: |
@@ -208,7 +214,7 @@ jobs:
208214
- name: Install system dependencies
209215
run: |
210216
sudo apt update
211-
sudo apt install -y cmake build-essential doxygen
217+
sudo apt install -y cmake build-essential doxygen libtbb-dev
212218
213219
- name: Install build dependencies
214220
run: |

.github/workflows/pytest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Install dependencies
2525
run: |
2626
sudo apt update
27-
sudo apt install -y cmake build-essential doxygen
27+
sudo apt install -y cmake build-essential doxygen libtbb-dev
2828
python -m pip install --upgrade pip
2929
pip install pytest pytest-cov
3030

CMakeLists.txt

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -129,19 +129,8 @@ FetchContent_GetProperties(simdjson)
129129
if(NOT simdjson_POPULATED)
130130
FetchContent_MakeAvailable(simdjson)
131131
endif()
132-
# Get TBB
133-
set(TBB_TEST OFF CACHE BOOL "Disable TBB tests" FORCE)
134-
set(TBB_EXAMPLES OFF CACHE BOOL "Disable TBB examples" FORCE)
135-
set(TBB_STRICT OFF CACHE BOOL "Disable TBB strict mode" FORCE)
136-
# set(TBB_BUILD_SHARED ON CACHE BOOL "Build TBB as shared library" FORCE)
137-
# set(TBB_BUILD_TBBMALLOC OFF CACHE BOOL "Disable TBB malloc" FORCE)
138-
139-
FetchContent_Declare(
140-
tbb
141-
GIT_REPOSITORY https://github.com/uxlfoundation/oneTBB.git
142-
GIT_TAG v2022.3.0
143-
)
144-
FetchContent_MakeAvailable(tbb)
132+
# Check if the user has TBB installed
133+
find_package(TBB REQUIRED CONFIG)
145134

146135
add_library(dsf STATIC ${SOURCES})
147136
target_compile_definitions(dsf PRIVATE SPDLOG_USE_STD_FORMAT)
@@ -209,29 +198,6 @@ if(BUILD_PYTHON_BINDINGS)
209198
target_include_directories(dsf_python_module
210199
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
211200

212-
if(APPLE)
213-
# Try to detect Homebrew prefix dynamically
214-
execute_process(
215-
COMMAND brew --prefix
216-
OUTPUT_VARIABLE HOMEBREW_PREFIX
217-
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
218-
if(HOMEBREW_PREFIX)
219-
set(HOMEBREW_LIB "${HOMEBREW_PREFIX}/lib")
220-
else()
221-
# Fallback to default Homebrew locations
222-
set(HOMEBREW_LIB "/opt/homebrew/lib;/usr/local/lib")
223-
endif()
224-
set_target_properties(
225-
dsf_python_module
226-
PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE
227-
INSTALL_RPATH "${HOMEBREW_LIB};@loader_path"
228-
INSTALL_RPATH_USE_LINK_PATH TRUE)
229-
elseif(UNIX)
230-
set_target_properties(
231-
dsf_python_module
232-
PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE
233-
INSTALL_RPATH "$ORIGIN")
234-
endif()
235201
endif()
236202

237203
# Tests

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ print(dsf.__version__)
3838
The project requires `C++20` or greater, `cmake`, `tbb` `simdjson`, `spdlog` and `rapidcsv`.
3939
To install requirements on Ubuntu:
4040
```shell
41-
sudo apt install cmake libhwloc-dev
41+
sudo apt install cmake libtbb-dev
4242
```
4343
To install requirements on macOS:
4444
```shell
45-
brew install cmake
45+
brew install cmake tbb
4646
```
4747

4848
Utilities are written in python. To install their dependencies:
@@ -68,7 +68,7 @@ cmake --install build
6868
## Installation (Python)
6969
If you want to use the library from Python, you can build the Python bindings using [pybind11](https://github.com/pybind/pybind11). Make sure you have Doxygen installed to generate the docstrings:
7070
```shell
71-
sudo apt install doxygen
71+
sudo apt install doxygen libtbb-dev
7272
```
7373

7474
Then, the installation is automatic via `pip`:

setup.py

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,26 @@ def build_extension(self, ext: CMakeExtension):
8080

8181
if platform.system() == "Windows":
8282
cmake_args += [f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{cfg.upper()}={extdir}"]
83+
if "CMAKE_TOOLCHAIN_FILE" in os.environ:
84+
cmake_args.append(
85+
f"-DCMAKE_TOOLCHAIN_FILE={os.environ['CMAKE_TOOLCHAIN_FILE']}"
86+
)
87+
if "VCPKG_TARGET_TRIPLET" in os.environ:
88+
cmake_args.append(
89+
f"-DVCPKG_TARGET_TRIPLET={os.environ['VCPKG_TARGET_TRIPLET']}"
90+
)
8391

8492
# Add macOS-specific CMake prefix paths for Homebrew dependencies
8593
if platform.system() == "Darwin": # macOS
8694
try:
87-
tbb_prefix = subprocess.check_output(
88-
["brew", "--prefix", "tbb"], text=True
89-
).strip()
9095
fmt_prefix = subprocess.check_output(
9196
["brew", "--prefix", "fmt"], text=True
9297
).strip()
9398
spdlog_prefix = subprocess.check_output(
9499
["brew", "--prefix", "spdlog"], text=True
95100
).strip()
96101

97-
cmake_prefix_path = f"{tbb_prefix};{fmt_prefix};{spdlog_prefix}"
102+
cmake_prefix_path = f"{fmt_prefix};{spdlog_prefix}"
98103
cmake_args.append(f"-DCMAKE_PREFIX_PATH={cmake_prefix_path}")
99104
print(f"Added macOS Homebrew prefix paths: {cmake_prefix_path}")
100105

@@ -126,65 +131,6 @@ def build_extension(self, ext: CMakeExtension):
126131
cwd=build_temp,
127132
)
128133

129-
# Copy TBB shared library if it exists (Linux and macOS)
130-
if platform.system() == "Linux" or platform.system() == "Darwin":
131-
print(f"Searching for TBB shared libraries in {build_temp}...")
132-
133-
tbb_libs = []
134-
if platform.system() == "Linux":
135-
# Look for libtbb.so* recursively
136-
tbb_libs = list(build_temp.glob("**/libtbb.so*"))
137-
# Also look for libtbb_debug.so* if we are in debug mode or if that's what was built
138-
tbb_libs.extend(list(build_temp.glob("**/libtbb_debug.so*")))
139-
else: # macOS
140-
# Look for libtbb.dylib* recursively
141-
tbb_libs = list(build_temp.glob("**/libtbb*.dylib"))
142-
143-
if tbb_libs:
144-
print(f"Found TBB libraries: {tbb_libs}")
145-
for lib in tbb_libs:
146-
# We only want the real shared object, not symlinks if possible,
147-
# but copying everything matching the pattern is safer to ensure we get the versioned one.
148-
# However, we need to be careful not to overwrite if multiple matches found.
149-
# Usually we want the one that the linker linked against.
150-
# Since we set RPATH to $ORIGIN (Linux) or @loader_path (macOS), we need the library in the same dir as the extension.
151-
152-
# Avoid copying if it's a symlink pointing to something we already copied?
153-
# simpler: just copy all of them.
154-
dest = extdir / lib.name
155-
if not dest.exists():
156-
shutil.copy2(lib, dest)
157-
print(f"Copied {lib} to {dest}")
158-
else:
159-
print("Warning: No TBB shared libraries found to copy.")
160-
161-
elif platform.system() == "Windows":
162-
print(f"Searching for TBB DLLs in {build_temp}...")
163-
# Look for tbb*.dll recursively
164-
tbb_dlls = list(build_temp.glob("**/tbb*.dll"))
165-
166-
if tbb_dlls:
167-
print(f"Found TBB DLLs: {tbb_dlls}")
168-
# We want to copy them to the 'dsf' package directory so we can load them in __init__.py
169-
# extdir is where dsf_cpp.pyd is (site-packages root usually)
170-
# We want site-packages/dsf/
171-
172-
# self.build_lib is usually the root of the build (e.g. build/lib.win...)
173-
# So we can construct the path to dsf package
174-
dsf_pkg_dir = Path(self.build_lib) / "dsf"
175-
dsf_pkg_dir.mkdir(parents=True, exist_ok=True)
176-
177-
# Also copy to source directory for editable installs
178-
source_dsf_dir = Path(__file__).parent / "src" / "dsf"
179-
180-
for dll in tbb_dlls:
181-
print(f"Copying {dll} to {dsf_pkg_dir}")
182-
shutil.copy2(dll, dsf_pkg_dir)
183-
print(f"Copying {dll} to {source_dsf_dir}")
184-
shutil.copy2(dll, source_dsf_dir)
185-
else:
186-
print("Warning: No TBB DLLs found. This might cause import errors.")
187-
188134
def pre_build(self):
189135
"""Extracts doxygen documentation from XML files and creates a C++ unordered_map"""
190136

0 commit comments

Comments
 (0)