homebrew-core/Formula/boost-python3.rb
2018-04-17 03:38:31 -07:00

101 lines
3.6 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"
head "https://github.com/boostorg/boost.git"
bottle do
sha256 "9e6f8d24dea9f09ce5e9a4a13b5af850c60053c459787377449e0f9733cdb274" => :high_sierra
sha256 "5491c58d54ad60d3242d64b620c92b988b0801e1d1945006d823d6559186bb3a" => :sierra
sha256 "76c42589ff0991ab5e7a335e567adedb84c1f4a9d22c86b1e52f95c922e5649b" => :el_capitan
end
depends_on "boost"
depends_on "python"
needs :cxx11
resource "numpy" do
url "https://files.pythonhosted.org/packages/ee/66/7c2690141c520db08b6a6f852fa768f421b0b50683b7bbcd88ef51f33170/numpy-1.14.0.zip"
sha256 "3de643935b212307b420248018323a44ec51987a336d1d747c1322afc3c099fb"
end
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(" ")
system ENV.cxx, "-shared", "hello.cpp", "-L#{lib}", "-lboost_python36", "-o",
"hello.so", *pyincludes, *pylib
output = <<~EOS
import hello
print(hello.greet())
EOS
assert_match "Hello, world!", pipe_output("python3", output, 0)
end
end