104 lines
3.7 KiB
Ruby
104 lines
3.7 KiB
Ruby
class BoostPython3 < Formula
|
|
desc "C++ library for C++/Python3 interoperability"
|
|
homepage "https://www.boost.org/"
|
|
url "https://dl.bintray.com/boostorg/release/1.67.0/source/boost_1_67_0.tar.bz2"
|
|
sha256 "2684c972994ee57fc5632e03bf044746f6eb45d4920c343937a465fd67a5adba"
|
|
revision 1
|
|
head "https://github.com/boostorg/boost.git"
|
|
|
|
bottle do
|
|
sha256 "3a3159573d928cdfcb02aae4071ddcb3010ab971c2d47215e72482082d1c268d" => :mojave
|
|
sha256 "bae03c8db2771e0c2e6ede980f63709933b9aeff3a6c2caa455eddbf0720d7a4" => :high_sierra
|
|
sha256 "f40cf6faac668e9bb6fe21997b71b3ad323e7c6a63320450f2fbaee4cf254e0a" => :sierra
|
|
sha256 "4a021ea3b65eadb5fd799d5a45a837e18981ef12d622f1eaf841d51b95230a7f" => :el_capitan
|
|
end
|
|
|
|
depends_on "boost"
|
|
depends_on "python"
|
|
|
|
resource "numpy" do
|
|
url "https://files.pythonhosted.org/packages/d5/6e/f00492653d0fdf6497a181a1c1d46bbea5a2383e7faf4c8ca6d6f3d2581d/numpy-1.14.5.zip"
|
|
sha256 "a4a433b3a264dbc9aa9c7c241e87c0358a503ea6394f8737df1683c7c9a102ac"
|
|
end
|
|
|
|
needs :cxx11
|
|
|
|
def install
|
|
# "layout" should be synchronized with boost
|
|
args = ["--prefix=#{prefix}",
|
|
"--libdir=#{lib}",
|
|
"-d2",
|
|
"-j#{ENV.make_jobs}",
|
|
"--layout=tagged",
|
|
"--user-config=user-config.jam",
|
|
"threading=multi,single",
|
|
"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"
|
|
if ENV.compiler == :clang
|
|
args << "cxxflags=-stdlib=libc++" << "linkflags=-stdlib=libc++"
|
|
end
|
|
|
|
# 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 = Formula["python3"].opt_frameworks/"Python.framework/Versions/#{pyver}"
|
|
|
|
numpy_site_packages = buildpath/"homebrew-numpy/lib/python#{pyver}/site-packages"
|
|
numpy_site_packages.mkpath
|
|
ENV["PYTHONPATH"] = numpy_site_packages
|
|
resource("numpy").stage do
|
|
system "python3", *Language::Python.setup_install_args(buildpath/"homebrew-numpy")
|
|
end
|
|
|
|
# Force boost to compile with the desired compiler
|
|
(buildpath/"user-config.jam").write <<~EOS
|
|
using darwin : : #{ENV.cxx} ;
|
|
using python : #{pyver}
|
|
: python3
|
|
: #{py_prefix}/include/python#{pyver}m
|
|
: #{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",
|
|
"python=#{pyver}", *args
|
|
|
|
lib.install Dir["stage-python3/lib/*py*"]
|
|
doc.install Dir["libs/python/doc/*"]
|
|
end
|
|
|
|
test do
|
|
(testpath/"hello.cpp").write <<~EOS
|
|
#include <boost/python.hpp>
|
|
char const* greet() {
|
|
return "Hello, world!";
|
|
}
|
|
BOOST_PYTHON_MODULE(hello)
|
|
{
|
|
boost::python::def("greet", greet);
|
|
}
|
|
EOS
|
|
|
|
pyincludes = Utils.popen_read("python3-config --includes").chomp.split(" ")
|
|
pylib = Utils.popen_read("python3-config --ldflags").chomp.split(" ")
|
|
pyver = Language::Python.major_minor_version("python3").to_s.delete(".")
|
|
|
|
system ENV.cxx, "-shared", "hello.cpp", "-L#{lib}", "-lboost_python#{pyver}", "-o",
|
|
"hello.so", *pyincludes, *pylib
|
|
|
|
output = <<~EOS
|
|
import hello
|
|
print(hello.greet())
|
|
EOS
|
|
assert_match "Hello, world!", pipe_output("python3", output, 0)
|
|
end
|
|
end
|