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.8.0.tar.gz" sha256 "eee380323bb7ce864355ed9431f85c43955faaae9e9bce35c62b372d7ffd9f8b" license "Apache-2.0" bottle do sha256 cellar: :any, arm64_ventura: "59e5097745fcb230f5ffb58f94c3a4e7186f13b444d9f99011564b6d2a25a5f7" sha256 cellar: :any, arm64_monterey: "744ee4be61f2d9d5639a4223396b335f0c18997aeadec0ec0394cd9c326ad5cc" sha256 cellar: :any, arm64_big_sur: "61ce53905c69e493c55e8dce00875a520565b914238cac13927a91d3541e10a6" sha256 cellar: :any, ventura: "a626b3de9bfa90769416efbf32b8907b43a24264ca00f1227bb3b5406b9bd311" sha256 cellar: :any, monterey: "54b62846d00669a11556f621ef0dbf562ed6c2ac53d6989da85feb24488b4fdf" sha256 cellar: :any, big_sur: "62b5ffa782502dd84e19da73849342cdf2c2fd928f73e6a9c0625a23e5881f35" sha256 cellar: :any_skip_relocation, x86_64_linux: "145cf62f2cb65d54cd4d5747aa3c640ead388fb68501e7013437da85999e294e" end # If adding `hwloc` for TBBBind, you *must* add a test for its functionality. # https://github.com/oneapi-src/oneTBB/blob/690aaf497a78a75ff72cddb084579427ab0a8ffc/CMakeLists.txt#L226-L228 depends_on "cmake" => :build depends_on "python@3.11" => [: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 # Prevent `setup.py` from installing tbb4py directly into HOMEBREW_PREFIX. # We need this due to our `python@3.11` patch. python = Formula["python@3.11"].opt_bin/"python3.11" site_packages = Language::Python.site_packages(python) inreplace "python/CMakeLists.txt", "@@SITE_PACKAGES@@", site_packages tbb_site_packages = prefix/site_packages/"tbb" ENV.append "LDFLAGS", "-Wl,-rpath,#{rpath},-rpath,#{rpath(source: tbb_site_packages)}" 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 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 #include #include int main() { auto total = tbb::parallel_reduce( tbb::blocked_range(0, 100), 0.0, [&](tbb::blocked_range r, int running_total) { for (int i=r.begin(); i < r.end(); ++i) { running_total += i + 1; } return running_total; }, std::plus() ); 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.11"].opt_bin/"python3.11", "-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 @@ -40,7 +40,7 @@ add_custom_target( ${PYTHON_EXECUTABLE} ${PYTHON_BUILD_WORK_DIR}/setup.py build -b${PYTHON_BUILD_WORK_DIR} build_ext ${TBB4PY_INCLUDE_STRING} -L$ - install --prefix ${PYTHON_BUILD_WORK_DIR}/build -f + install --prefix ${PYTHON_BUILD_WORK_DIR}/build --install-lib ${PYTHON_BUILD_WORK_DIR}/build/@@SITE_PACKAGES@@ -f COMMENT "Build and install to work directory the oneTBB Python module" ) @@ -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)