Split out Boost.Python

This commit is contained in:
Tim D. Smith 2014-07-19 15:37:25 -07:00
parent 99abe449d4
commit a6a3bbd288
2 changed files with 136 additions and 66 deletions

127
Formula/boost-python.rb Normal file
View file

@ -0,0 +1,127 @@
require "formula"
class UniversalPython < Requirement
satisfy(:build_env => false) { archs_for_command("python").universal? }
def message; <<-EOS.undent
A universal build was requested, but Python is not a universal build
Boost compiles against the Python it finds in the path; if this Python
is not a universal build then linking will likely fail.
EOS
end
end
class UniversalPython3 < Requirement
satisfy(:build_env => false) { archs_for_command("python3").universal? }
def message; <<-EOS.undent
A universal build was requested, but Python 3 is not a universal build
Boost compiles against the Python 3 it finds in the path; if this Python
is not a universal build then linking will likely fail.
EOS
end
end
class BoostPython < Formula
homepage "http://www.boost.org"
url "https://downloads.sourceforge.net/project/boost/boost/1.56.0/boost_1_56_0.tar.bz2"
sha1 "f94bb008900ed5ba1994a1072140590784b9b5df"
head "https://github.com/boostorg/boost.git"
option :universal
option :cxx11
depends_on :python => :recommended
depends_on :python3 => :optional
depends_on UniversalPython if build.universal? and build.with? "python"
depends_on UniversalPython3 if build.universal? and build.with? "python3"
if build.cxx11?
depends_on "boost" => "c++11"
else
depends_on "boost"
end
fails_with :llvm do
build 2335
cause "Dropped arguments to functions when linking with boost"
end
def install
ENV.universal_binary if build.universal?
# "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"]
args << "address-model=32_64" << "architecture=x86" << "pch=off" if build.universal?
# Build in C++11 mode if boost was built in C++11 mode.
# Trunk starts using "clang++ -x c" to select C compiler which breaks C++11
# handling using ENV.cxx11. Using "cxxflags" and "linkflags" still works.
if build.cxx11?
args << "cxxflags=-std=c++11"
if ENV.compiler == :clang
args << "cxxflags=-stdlib=libc++" << "linkflags=-stdlib=libc++"
end
elsif Tab.for_name("boost").cxx11?
odie "boost was built in C++11 mode so boost-python must be built with --c++11."
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"
Language::Python.each_python(build) do |python, version|
py_prefix = `#{python} -c "from __future__ import print_function; import sys; print(sys.prefix)"`.strip
py_include = `#{python} -c "from __future__ import print_function; import distutils.sysconfig; print(distutils.sysconfig.get_python_inc(True))"`.strip
open("user-config.jam", "w") do |file|
# Force boost to compile with the desired compiler
file.write "using darwin : : #{ENV.cxx} ;\n"
file.write <<-EOS.undent
using python : #{version}
: #{python}
: #{py_include}
: #{py_prefix}/lib ;
EOS
end
system "./bootstrap.sh", "--prefix=#{prefix}", "--libdir=#{lib}", "--with-libraries=python",
"--with-python=#{python}", "--with-python-root=#{py_prefix}"
system "./b2", "--build-dir=build-#{python}", "--stagedir=stage-#{python}",
"python=#{version}", *args
end
lib.install Dir["stage-python3/lib/*py*"] if build.with?("python3")
lib.install Dir["stage-python/lib/*py*"] if build.with?("python")
end
test do
(testpath/"hello.cpp").write <<-EOS.undent
#include <boost/python.hpp>
char const* greet() {
return "Hello, world!";
}
BOOST_PYTHON_MODULE(hello)
{
boost::python::def("greet", greet);
}
EOS
Language::Python.each_python(build) do |python, version|
pycflags = `#{python}-config --includes`.strip
pyldflags = `#{python}-config --ldflags`.strip
system "#{ENV.cxx} -shared hello.cpp #{pycflags} #{pyldflags} -lboost_#{python} -o hello.so"
output = `#{python} -c "from __future__ import print_function; import hello; print(hello.greet())"`
assert output.include?("Hello, world!")
end
end
end

View file

@ -1,29 +1,5 @@
require 'formula'
class UniversalPython < Requirement
satisfy(:build_env => false) { archs_for_command("python").universal? }
def message; <<-EOS.undent
A universal build was requested, but Python is not a universal build
Boost compiles against the Python it finds in the path; if this Python
is not a universal build then linking will likely fail.
EOS
end
end
class UniversalPython3 < Requirement
satisfy(:build_env => false) { archs_for_command("python3").universal? }
def message; <<-EOS.undent
A universal build was requested, but Python 3 is not a universal build
Boost compiles against the Python 3 it finds in the path; if this Python
is not a universal build then linking will likely fail.
EOS
end
end
class Boost < Formula
homepage 'http://www.boost.org'
url 'https://downloads.sourceforge.net/project/boost/boost/1.56.0/boost_1_56_0.tar.bz2'
@ -47,15 +23,6 @@ class Boost < Formula
option 'with-mpi', 'Build with MPI support'
option :cxx11
depends_on :python => :optional
depends_on :python3 => :optional
depends_on UniversalPython if build.universal? and build.with? "python"
depends_on UniversalPython3 if build.universal? and build.with? "python3"
if build.with?("python3") && build.with?("python")
odie "boost: --with-python3 cannot be specified when using --with-python"
end
if build.with? 'icu'
if build.cxx11?
depends_on 'icu4c' => 'c++11'
@ -87,49 +54,26 @@ class Boost < Formula
EOS
end
if build.cxx11? and build.with? 'mpi' and (build.with? 'python' \
or build.with? 'python3')
raise <<-EOS.undent
Building MPI support for Python using C++11 mode results in
failure and hence disabled. Please don't use this combination
of options.
EOS
end
ENV.universal_binary if build.universal?
# Force boost to compile using the appropriate GCC version.
# Force boost to compile with the desired compiler
open("user-config.jam", "a") do |file|
file.write "using darwin : : #{ENV.cxx} ;\n"
file.write "using mpi ;\n" if build.with? 'mpi'
# Link against correct version of Python if python3 build was requested
if build.with? 'python3'
py3executable = `which python3`.strip
py3version = `python3 -c "import sys; print(sys.version[:3])"`.strip
py3prefix = `python3 -c "import sys; print(sys.prefix)"`.strip
file.write <<-EOS.undent
using python : #{py3version}
: #{py3executable}
: #{py3prefix}/include/python#{py3version}m
: #{py3prefix}/lib ;
EOS
end
end
# we specify libdir too because the script is apparently broken
bargs = ["--prefix=#{prefix}", "--libdir=#{lib}"]
# libdir should be set by --prefix but isn't
bootstrap_args = ["--prefix=#{prefix}", "--libdir=#{lib}"]
if build.with? 'icu'
icu4c_prefix = Formula['icu4c'].opt_prefix
bargs << "--with-icu=#{icu4c_prefix}"
bootstrap_args << "--with-icu=#{icu4c_prefix}"
else
bargs << '--without-icu'
bootstrap_args << '--without-icu'
end
# Handle libraries that will not be built.
without_libraries = []
without_libraries = ["python"]
# The context library is implemented as x86_64 ASM, so it
# won't build on PPC or 32-bit builds
@ -143,12 +87,11 @@ class Boost < Formula
# Boost.Log cannot be built using Apple GCC at the moment. Disabled
# on such systems.
without_libraries << "log" if ENV.compiler == :gcc || ENV.compiler == :llvm
without_libraries << "python" if (build.without? 'python' \
and build.without? 'python3')
without_libraries << "mpi" if build.without? 'mpi'
bargs << "--without-libraries=#{without_libraries.join(',')}"
bootstrap_args << "--without-libraries=#{without_libraries.join(',')}"
# layout should be synchronized with boost-python
args = ["--prefix=#{prefix}",
"--libdir=#{lib}",
"-d2",
@ -180,7 +123,7 @@ class Boost < Formula
end
end
system "./bootstrap.sh", *bargs
system "./bootstrap.sh", *bootstrap_args
system "./b2", *args
end