Google helps developers bind C++ to Python
Fans of C++ praise its power and speed, but even they admit its complexity can be daunting. That’s true when you’re writing libraries in the language, and it’s doubly true when you want to make C++-authored libraries useful to other languages. Writing wrappers for C++ libraries is tough work. CLIF, an open source project developed at Google (but not an official Google product), is a framework for automatically generating C++ library bindings for multiple languages. It’s written in Python, and so far the only included language binding is for Python, both versions 2 and 3, but the plan is to allow other language parsers to be written for it. CLIF uses the LLVM compiler framework and its Clang C/C++ front end to parse out the type information from a C++ API description. The resulting information is used to generate a wrapper, and any type conversions that need to be performed to or from the target language are done with a runtime C++ library. Aside from LLVM/Clang, CLIF uses a few other elements, but nothing outlandishGoogle’s protobuf(“for inter-process communication between the CLIF front end and back end”), and the CMake build system. Interestingly, it does not use Google’s custom build system, Bazel, but that may be to reduce dependencies not found in common C++ toolchains, as CMake is far more common than Bazel. Long-standing projects already exist for generating language wrappers for C/C++ libraries. SWIG, among the best known and most commonly used, is able to generate wrappers for a broad variety of languages. But SWIG is also a legacy projectits original version debuted in 1995and it has long been regarded, even by its creator, core Python developer David Beazley, as having flaky support for C++. “Almost all of these bugs [for C++ support in SWIG] were due to the fact that SWIG started out as a hack and didn’t really have any kind of solid conceptual foundation for how it should be put together,” wrote Beazley. In CLIF’s case, the project tries to avoid some of the problems with parsing C++ by leaving that job to LLVM, rather than trying to reinvent the wheel. Some of the other issues that arise with C++, like how to handle C++ templates via a wrapper, are dealt with in CLIF by way of its C++ runtime. Some advanced C++ features, like inheritance, aren’t exposed by default, but can be if needed.
Read Full Article at http://www.infoworld.com/article/3194051/development-tools/google-helps-developers-bind-c-to-python.html