Last active
August 26, 2020 18:33
-
-
Save m4ce/b484bac8a5381d0722e420f396801220 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Pybind11 < Formula | |
desc "Seamless operability between C++11 and Python" | |
homepage "https://github.com/pybind/pybind11" | |
version "9b8cb02030e45443a8a4c5526cdb8093caa481eb" | |
url "https://github.com/pybind/pybind11/archive/9b8cb02030e45443a8a4c5526cdb8093caa481eb.tar.gz" | |
sha256 "c77cb0fbff78e6c6d527054de6bc28707f0d7855e486bef24dfb73342d297015" | |
depends_on "cmake" => :build | |
depends_on "[email protected]" | |
def install | |
system "cmake", ".", "-DPYBIND11_TEST=OFF", *std_cmake_args | |
system "make", "install" | |
end | |
test do | |
(testpath/"example.cpp").write <<~EOS | |
#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 | |
import example | |
example.add(1,2) | |
EOS | |
python_flags = `#{Formula["[email protected]"].opt_bin}/python3-config --cflags --ldflags --embed`.split(" ") | |
system ENV.cxx, "-O3", "-shared", "-std=c++11", *python_flags, "example.cpp", "-o", "example.so" | |
system Formula["[email protected]"].opt_bin/"python3", "example.py" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment