Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #4059. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
- Loading branch information
1 parent
ff4a43f
commit b17405c
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class Pybind11 < Formula | ||
desc "Seamless operability between C++11 and Python" | ||
homepage "https://github.com/pybind/pybind11" | ||
url "https://github.com/pybind/pybind11/archive/v1.8.1.tar.gz" | ||
sha256 "321de8881ff0e113087b9e996d77777417b7db05bc4536b365f648b5fadc27b8" | ||
|
||
depends_on "python3" | ||
depends_on "cmake" => :build | ||
|
||
def install | ||
system "cmake", ".", *std_cmake_args | ||
system "make", "install" | ||
end | ||
|
||
test do | ||
(testpath/"example.cpp").write <<-EOS.undent | ||
#include <pybind11/pybind11.h> | ||
int add(int i, int j) { | ||
return i + j; | ||
} | ||
namespace py = pybind11; | ||
PYBIND11_PLUGIN(example) { | ||
py::module m("example", "pybind11 example plugin"); | ||
m.def("add", &add, "A function which adds two numbers"); | ||
return m.ptr(); | ||
} | ||
EOS | ||
|
||
(testpath/"example.py").write <<-EOS.undent | ||
import example | ||
example.add(1,2) | ||
EOS | ||
|
||
python_flags = `python3-config --cflags --ldflags`.split(" ") | ||
system ENV.cxx, "-O3", "-shared", "-std=c++11", *python_flags, "example.cpp", "-o", "example.so" | ||
system "python3", "example.py" | ||
end | ||
end |