class BoostMpi < Formula desc "C++ library for C++/MPI interoperability" homepage "https://www.boost.org/" url "https://github.com/boostorg/boost/releases/download/boost-1.90.0/boost-1.90.0-b2-nodocs.tar.xz" sha256 "9e6bee9ab529fb2b0733049692d57d10a72202af085e553539a05b4204211a6f" license "BSL-1.0" head "https://github.com/boostorg/boost.git", branch: "master" livecheck do formula "boost" end bottle do sha256 arm64_tahoe: "670dd9f317690572c55e29b35f850fdb2a9bf6173b24659b7386195129c6fee2" sha256 arm64_sequoia: "59b9a8df7461cff1219fe857551d02ec37dbd783e2d3b173987665846fed8719" sha256 arm64_sonoma: "1ba24fd1729bf2d4fa74087d4d98db902d17bcd0d618dd6f4fff6ef49bec6abc" sha256 sonoma: "1f4b7c4cc2fd1ee4a5553385d5885162e11779d969ad949e8ddb59f1f2e8930d" sha256 cellar: :any_skip_relocation, arm64_linux: "68372159bf8d129e7212b757272a6b114637444382d9c246a170a2d7d5178c37" sha256 cellar: :any_skip_relocation, x86_64_linux: "d6b807df695489d80a4e89f0299941e10e733a4c1adc260bf31f425a3994db4f" end # Test with cmake to avoid issues like: # https://github.com/Homebrew/homebrew-core/issues/67285 depends_on "cmake" => :test depends_on "boost" depends_on "open-mpi" def install # "layout" should be synchronized with boost args = %W[ -d2 -j#{ENV.make_jobs} --layout=system --user-config=user-config.jam install threading=multi link=shared,static ] # Trunk starts using "clang++ -x c" to select C compiler which breaks C++11 # handling using ENV.cxx11. Using "cxxflags" and "linkflags" still works. args << "cxxflags=-std=c++11" args << "cxxflags=-stdlib=libc++" << "linkflags=-stdlib=libc++" if ENV.compiler == :clang # Avoid linkage to boost container and graph modules # Issue ref: https://github.com/boostorg/boost/issues/985 args << "linkflags=-Wl,-dead_strip_dylibs" if OS.mac? open("user-config.jam", "a") do |file| if OS.mac? file.write "using darwin : : #{ENV.cxx} ;\n" else file.write "using gcc : : #{ENV.cxx} ;\n" end file.write "using mpi ;\n" end system "./bootstrap.sh", "--prefix=#{prefix}", "--libdir=#{lib}", "--with-libraries=mpi" system "./b2", "--prefix=install-mpi", "--libdir=install-mpi/lib", *args lib.install Dir["install-mpi/lib/*mpi*"] (lib/"cmake").install Dir["install-mpi/lib/cmake/*mpi*"] if OS.mac? # libboost_mpi links to libboost_serialization, which comes from the main boost formula boost = Formula["boost"] MachO::Tools.change_install_name("#{lib}/libboost_mpi.dylib", "libboost_serialization.dylib", "#{boost.lib}/libboost_serialization.dylib") end end test do (testpath/"test.cpp").write <<~CPP #include #include #include namespace mpi = boost::mpi; int main(int argc, char* argv[]) { mpi::environment env(argc, argv); mpi::communicator world; if (world.rank() == 0) { world.send(1, 0, std::string("Hello")); std::string msg; world.recv(1, 1, msg); std::cout << msg << "!" << std::endl; } else { std::string msg; world.recv(0, 0, msg); std::cout << msg << ", "; std::cout.flush(); world.send(0, 1, std::string("world")); } return 0; } CPP boost = Formula["boost"] args = ["-L#{lib}", "-L#{boost.lib}", "-lboost_mpi", "-lboost_serialization", "-std=c++14"] if OS.linux? args << "-Wl,-rpath,#{lib}" args << "-Wl,-rpath,#{boost.lib}" end system "mpic++", "test.cpp", *args, "-o", "test" system "mpirun", "-np", "2", "./test" (testpath/"CMakeLists.txt").write <<~CMAKE cmake_minimum_required(VERSION 4.0) find_package(Boost COMPONENTS mpi REQUIRED) CMAKE system "cmake", ".", "-Wno-dev" end end