From 92170628697df3ed80a152d599131c84318e0fd1 Mon Sep 17 00:00:00 2001 From: Yoshitaka Moriwaki Date: Wed, 18 Dec 2024 10:21:45 +0900 Subject: [PATCH] boost-python3@1.87 (new formula) (#1964) --- Formula/boost-python3@1.87.rb | 107 +++++++++++++++++++++++++++ Formula/rdkit4coot.rb | 134 ---------------------------------- 2 files changed, 107 insertions(+), 134 deletions(-) create mode 100644 Formula/boost-python3@1.87.rb delete mode 100644 Formula/rdkit4coot.rb diff --git a/Formula/boost-python3@1.87.rb b/Formula/boost-python3@1.87.rb new file mode 100644 index 000000000..0e9fd285f --- /dev/null +++ b/Formula/boost-python3@1.87.rb @@ -0,0 +1,107 @@ +class BoostPython3AT187 < Formula + desc "C++ library for C++/Python3 interoperability" + homepage "https://www.boost.org/" + url "https://github.com/boostorg/boost/releases/download/boost-1.87.0/boost-1.87.0-b2-nodocs.tar.xz" + sha256 "3abd7a51118a5dd74673b25e0a3f0a4ab1752d8d618f4b8cea84a603aeecc680" + license "BSL-1.0" + head "https://github.com/boostorg/boost.git", branch: "master" + + livecheck do + formula "boost" + end + + keg_only :versioned_formula + + depends_on "numpy" => :build + depends_on "boost" + depends_on "python@3.12" + + def python3 + "python3.12" + end + + 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 + ] + + # Boost is using "clang++ -x c" to select C compiler which breaks C++14 + # handling using ENV.cxx14. Using "cxxflags" and "linkflags" still works. + args << "cxxflags=-std=c++14" + 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? + + # disable python detection in bootstrap.sh; it guesses the wrong include + # directory for Python 3 headers, so we configure python manually in + # user-config.jam below. + inreplace "bootstrap.sh", "using python", "#using python" + + pyver = Language::Python.major_minor_version python3 + py_prefix = if OS.mac? + Formula["python@#{pyver}"].opt_frameworks/"Python.framework/Versions"/pyver + else + Formula["python@#{pyver}"].opt_prefix + end + + # Force boost to compile with the desired compiler + (buildpath/"user-config.jam").write <<~EOS + using #{OS.mac? ? "darwin" : "gcc"} : : #{ENV.cxx} ; + using python : #{pyver} + : #{python3} + : #{py_prefix}/include/python#{pyver} + : #{py_prefix}/lib ; + EOS + + system "./bootstrap.sh", "--prefix=#{prefix}", + "--libdir=#{lib}", + "--with-libraries=python", + "--with-python=#{python3}", + "--with-python-root=#{py_prefix}" + + system "./b2", "--build-dir=build-python3", + "--stagedir=stage-python3", + "--libdir=install-python3/lib", + "--prefix=install-python3", + "python=#{pyver}", + *args + + lib.install buildpath.glob("install-python3/lib/*{python,numpy}*") + (lib/"cmake").install buildpath.glob("install-python3/lib/cmake/*{python,numpy}*") + end + + test do + (testpath/"hello.cpp").write <<~CPP + #include + char const* greet() { + return "Hello, world!"; + } + BOOST_PYTHON_MODULE(hello) + { + boost::python::def("greet", greet); + } + CPP + + pyincludes = shell_output("#{python3}-config --includes").chomp.split + pylib = shell_output("#{python3}-config --ldflags --embed").chomp.split + pyver = Language::Python.major_minor_version(python3).to_s.delete(".") + + system ENV.cxx, "-shared", "-fPIC", "-std=c++14", "hello.cpp", "-L#{lib}", "-lboost_python#{pyver}", + "-o", "hello.so", *pyincludes, *pylib + + output = <<~PYTHON + import hello + print(hello.greet()) + PYTHON + assert_match "Hello, world!", pipe_output(python3, output, 0) + end +end diff --git a/Formula/rdkit4coot.rb b/Formula/rdkit4coot.rb deleted file mode 100644 index e7c6b1f69..000000000 --- a/Formula/rdkit4coot.rb +++ /dev/null @@ -1,134 +0,0 @@ -class Rdkit4coot < Formula - desc "Open-source chemoinformatics library" - homepage "https://rdkit.org/" - # NOTE: Make sure to update RPATHs if any "@rpath-referenced libraries" show up in `brew linkage` - url "https://github.com/rdkit/rdkit/archive/refs/tags/Release_2024_09_1.tar.gz" - sha256 "034c00d6e9de323506834da03400761ed8c3721095114369d06805409747a60f" - license "BSD-3-Clause" - head "https://github.com/rdkit/rdkit.git", branch: "master" - - livecheck do - url :stable - regex(/^Release[._-](\d+(?:[._]\d+)+)$/i) - strategy :git do |tags| - tags.filter_map { |tag| tag[regex, 1]&.tr("_", ".") } - end - end - - bottle do - root_url "https://ghcr.io/v2/brewsci/bio" - sha256 cellar: :any, arm64_sequoia: "8a6943ea5935c2713e05b8a1953e8919c00f23adb7b00a5a156b16cffdcd3316" - sha256 cellar: :any, arm64_sonoma: "ec5602b57e8706efa2a56399eef8e11f39e41efcdea5010370600a6c67d196f4" - sha256 cellar: :any, ventura: "ab56a3f5865d1f7be34b5f313b097ecaab7fe628923b660a77c890c45a5d7a5e" - sha256 cellar: :any_skip_relocation, x86_64_linux: "fc6da5271c27ee4cf3589301d4f61143b1785c6734dfaf7dcd77674feda35218" - end - - keg_only "provided by Homebrew core" - - depends_on "catch2" => :build - depends_on "cmake" => :build - depends_on "pkg-config" => :build - depends_on "postgresql@14" => [:build, :test] - depends_on "postgresql@17" => [:build, :test] - depends_on "boost" - depends_on "boost-python3" - depends_on "cairo" - depends_on "eigen" - depends_on "freetype" - depends_on "inchi" - depends_on "maeparser" - depends_on "numpy" - depends_on "py3cairo" - depends_on "python@3.12" - - conflicts_with "rdkit", because: "both install the same files" - - patch do - url "https://github.com/rdkit/rdkit/commit/3ade0f8cd31be54fc267b9f5e94e8aa755f56f36.patch?full_index=1" - sha256 "09696dc4c26832f5c5126d059ae0d71a12ab404438e55e8f9a90880a1fad6c03" - end - - def python3 - "python3.12" - end - - def postgresqls - deps.filter_map { |f| f.to_formula if f.name.start_with?("postgresql@") } - .sort_by(&:version) - end - - def install - python_rpath = rpath(source: lib/Language::Python.site_packages(python3)) - python_rpaths = [python_rpath, "#{python_rpath}/..", "#{python_rpath}/../.."] - args = %W[ - -DCMAKE_INSTALL_RPATH=#{rpath} - -DCMAKE_MODULE_LINKER_FLAGS=#{python_rpaths.map { |path| "-Wl,-rpath,#{path}" }.join(" ")} - -DCOORDGEN_FORCE_BUILD=ON - -DCMAKE_REQUIRE_FIND_PACKAGE_maeparser=ON - -DCMAKE_REQUIRE_FIND_PACKAGE_Inchi=ON - -DINCHI_INCLUDE_DIR=#{Formula["inchi"].opt_include}/inchi - -DRDK_INSTALL_INTREE=OFF - -DRDK_BUILD_SWIG_WRAPPERS=OFF - -DRDK_BUILD_AVALON_SUPPORT=ON - -DRDK_PGSQL_STATIC=OFF - -DRDK_BUILD_INCHI_SUPPORT=ON - -DRDK_BUILD_CPP_TESTS=OFF - -DRDK_INSTALL_STATIC_LIBS=OFF - -DRDK_BUILD_CAIRO_SUPPORT=ON - -DRDK_BUILD_YAEHMOP_SUPPORT=ON - -DRDK_BUILD_FREESASA_SUPPORT=ON - -DPython3_EXECUTABLE=#{which(python3)} - ] - if build.bottle? && Hardware::CPU.intel? && (!OS.mac? || !MacOS.version.requires_sse42?) - args << "-DRDK_OPTIMIZE_POPCNT=OFF" - end - system "cmake", "-S", ".", "-B", "build", "-DRDK_BUILD_PGSQL=OFF", *args, *std_cmake_args - system "cmake", "--build", "build" - system "cmake", "--install", "build" - - inreplace "Code/PgSQL/rdkit/CMakeLists.txt" do |s| - # Prevent trying to install into pg_config-defined dirs - s.sub! "set(PG_PKGLIBDIR \"${PG_PKGLIBDIR}", "set(PG_PKGLIBDIR \"$ENV{PG_PKGLIBDIR}" - s.sub! "set(PG_EXTENSIONDIR \"${PG_SHAREDIR}", "set(PG_EXTENSIONDIR \"$ENV{PG_SHAREDIR}" - # Re-use installed libraries when building modules for other PostgreSQL versions - s.sub!(/^find_package\(PostgreSQL/, "find_package(Cairo REQUIRED)\nfind_package(rdkit REQUIRED)\n\\0") - s.sub! 'set(pgRDKitLibs "${pgRDKitLibs}${pgRDKitLib}', 'set(pgRDKitLibs "${pgRDKitLibs}RDKit::${pgRDKitLib}' - s.sub! ";${INCHI_LIBRARIES};", ";" - # Add RPATH for PostgreSQL cartridge - s.sub! '"-Wl,-dead_strip_dylibs ', "\\0-Wl,-rpath,#{loader_path}/.. " - end - ENV["DESTDIR"] = "/" # to force creation of non-standard PostgreSQL directories - - postgresqls.each do |postgresql| - ENV["PG_PKGLIBDIR"] = lib/postgresql.name - ENV["PG_SHAREDIR"] = share/postgresql.name - builddir = "build_pg#{postgresql.version.major}" - - system "cmake", "-S", ".", "-B", builddir, - "-DRDK_BUILD_PGSQL=ON", - "-DPostgreSQL_ROOT=#{postgresql.opt_prefix}", - "-DPostgreSQL_ADDITIONAL_VERSIONS=#{postgresql.version.major}", - *args, *std_cmake_args - system "cmake", "--build", "#{builddir}/Code/PgSQL/rdkit" - system "cmake", "--install", builddir, "--component", "pgsql" - end - end - - def caveats - <<~EOS - You may need to add RDBASE to your environment variables, e.g. - #{Utils::Shell.export_value("RDBASE", "#{opt_share}/RDKit")} - EOS - end - - test do - # Test Python module - ENV["PYTHONPATH"] = prefix/Language::Python.site_packages(python3) - - (testpath/"test.py").write <<~EOS - from rdkit import Chem - print(Chem.MolToSmiles(Chem.MolFromSmiles('C1=CC=CN=C1'))) - EOS - assert_equal "c1ccncc1", shell_output("#{python3} test.py 2>&1").chomp - end -end