homebrew-core/Formula/tbb.rb

122 lines
4.4 KiB
Ruby

class Tbb < Formula
desc "Rich and complete approach to parallelism in C++"
homepage "https://github.com/oneapi-src/oneTBB"
url "https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.5.0.tar.gz"
sha256 "e5b57537c741400cf6134b428fc1689a649d7d38d9bb9c1b6d64f092ea28178a"
license "Apache-2.0"
revision 2
bottle do
rebuild 1
sha256 cellar: :any, arm64_monterey: "21c39944a3efe3edd84db35f4b7eb930d5e728742e96b4944489b09c85f485e0"
sha256 cellar: :any, arm64_big_sur: "57a1754dd59fbbe2179a5747ad4dc27bc7f1a6b51fdc47d3d2dbd65c1fcf0719"
sha256 cellar: :any, monterey: "241a6095398bad1f24343da0eedb746abce5818bebcccc7bb2d82cedde7eb454"
sha256 cellar: :any, big_sur: "6af7f19d5dac6d86e98e29db077a76b26c18d5a187e45cdfe6f5a4b4be1006ae"
sha256 cellar: :any, catalina: "4ddc6c91e43721325d44fd8aca57e30763cf546fba204420e797f9a6a091e225"
sha256 cellar: :any_skip_relocation, x86_64_linux: "a3f6717ebecbcaf078ebf4166f02a09e8908e89a1425370ebd4f60ea101d26af"
end
depends_on "cmake" => :build
depends_on "python@3.10" => [:build, :test]
depends_on "swig" => :build
# Fix installation of Python components
# See https://github.com/oneapi-src/oneTBB/issues/343
patch :DATA
# Fix thread creation under heavy load.
# https://github.com/oneapi-src/oneTBB/pull/824
# Needed for mold: https://github.com/rui314/mold/releases/tag/v1.4.0
patch do
url "https://github.com/oneapi-src/oneTBB/commit/f12c93efd04991bc982a27e2fa6142538c33ca82.patch?full_index=1"
sha256 "637a65cca11c81fa696112aca714879a2202a20e426eff2be8d2318e344ae15c"
end
def install
args = %w[
-DTBB_TEST=OFF
-DTBB4PY_BUILD=ON
]
system "cmake", "-S", ".", "-B", "build/shared",
"-DBUILD_SHARED_LIBS=ON",
"-DCMAKE_INSTALL_RPATH=#{rpath}",
*args, *std_cmake_args
system "cmake", "--build", "build/shared"
system "cmake", "--install", "build/shared"
system "cmake", "-S", ".", "-B", "build/static",
"-DBUILD_SHARED_LIBS=OFF",
*args, *std_cmake_args
system "cmake", "--build", "build/static"
lib.install buildpath.glob("build/static/*/libtbb*.a")
cd "python" do
ENV.append_path "CMAKE_PREFIX_PATH", prefix.to_s
python = Formula["python@3.10"].opt_bin/"python3.10"
tbb_site_packages = prefix/Language::Python.site_packages(python)/"tbb"
ENV.append "LDFLAGS", "-Wl,-rpath,#{rpath(source: tbb_site_packages)}"
ENV["TBBROOT"] = prefix
system python, *Language::Python.setup_install_args(prefix, python)
end
return unless OS.linux?
inreplace_files = prefix.glob("rml/CMakeFiles/irml.dir/{flags.make,build.make,link.txt}")
inreplace inreplace_files, Superenv.shims_path/ENV.cxx, ENV.cxx
end
test do
# The glob that installs these might fail,
# so let's check their existence.
assert_path_exists lib/"libtbb.a"
assert_path_exists lib/"libtbbmalloc.a"
(testpath/"sum1-100.cpp").write <<~EOS
#include <iostream>
#include <tbb/blocked_range.h>
#include <tbb/parallel_reduce.h>
int main()
{
auto total = tbb::parallel_reduce(
tbb::blocked_range<int>(0, 100),
0.0,
[&](tbb::blocked_range<int> r, int running_total)
{
for (int i=r.begin(); i < r.end(); ++i) {
running_total += i + 1;
}
return running_total;
}, std::plus<int>()
);
std::cout << total << std::endl;
return 0;
}
EOS
system ENV.cxx, "sum1-100.cpp", "--std=c++14", "-L#{lib}", "-ltbb", "-o", "sum1-100"
assert_equal "5050", shell_output("./sum1-100").chomp
system Formula["python@3.10"].opt_bin/"python3.10", "-c", "import tbb"
end
end
__END__
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt
index 1d2b05f..81ba8de 100644
--- a/python/CMakeLists.txt
+++ b/python/CMakeLists.txt
@@ -49,7 +49,7 @@ add_test(NAME python_test
-DPYTHON_MODULE_BUILD_PATH=${PYTHON_BUILD_WORK_DIR}/build
-P ${PROJECT_SOURCE_DIR}/cmake/python/test_launcher.cmake)
-install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PYTHON_BUILD_WORK_DIR}/build/
+install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PYTHON_BUILD_WORK_DIR}/
DESTINATION .
COMPONENT tbb4py)