RosettaCommons / binder

Binder, tool for automatic generation of Python bindings
MIT License
321 stars 67 forks source link

binder does not generate bindings #150

Open Thermi opened 3 years ago

Thermi commented 3 years ago

Hi, I'm trying to use binder to generate python bindings for libmdbx by pointing it at its mdbx.h++ file. That doesn't work though. binder does not generate any bindings, except the python module declaration. When the cpp file is built and loaded as a Python module, only the mdbx module is available, but none of functions, classes, or enums declared in mdbx.h++.

binder is in ~/prefix/bin/ and my cmdline is the following (when CWD is ~/prefix): bin/binder -p build --annotate-includes --root-module mdbx --bind mdbx --prefix generated all_includes.hpp -- -DNDEBUG -I /usr/lib/clang/11.0.1/include/ -I/usrinclude --std=c++20

This is with the newest binder version from this repo. clang and llvm version is 11.0.1. It generates the following mdbx.cpp file (mdbx.sources contains "mdbx.cpp" and mdbx.modules is empty):

#include <map>
#include <memory>
#include <stdexcept>
#include <functional>
#include <string>

#include <pybind11/pybind11.h>

typedef std::function< pybind11::module & (std::string const &) > ModuleGetter;

PYBIND11_MODULE(mdbx, root_module) {
        root_module.doc() = "mdbx module";

        std::map <std::string, pybind11::module> modules;
        ModuleGetter M = [&](std::string const &namespace_) -> pybind11::module & {
                auto it = modules.find(namespace_);
                if( it == modules.end() ) throw std::runtime_error("Attempt to access pybind11::module for namespace " + namespace_ + " before it was created!!!");
                return it->second;
        };

        modules[""] = root_module;

        std::vector< std::pair<std::string, std::string> > sub_modules {
        };
        for(auto &p : sub_modules ) modules[p.first.size() ? p.first+"::"+p.second : p.second] = modules[p.first].def_submodule(p.second.c_str(), ("Bindings for " + p.first + "::" + p.second + " namespace").c_str() );

        //pybind11::class_<std::shared_ptr<void>>(M(""), "_encapsulated_data_");

}
lyskov commented 3 years ago

@Thermi looks like Binder was not able to find any object/namespaces to bind. Could you please try to replace --bind mdbx with --bind "" and see if that make any difference? Thanks,

lyskov commented 3 years ago

Also, i briefly looked at mdbx.h++ and looks like there is a lot of low level c-style functions, some of which might not be possible to bind. If above suggestion does not yield more generated code: could you please add something like struct Dummy {int a;}; inside mdbx.h++ and see if that makes any difference? (ie rare chance that none of other objects in mdbx.h++ could be bound)