C++ Language Interface Foundation (CLIF)
CLIF provides a common foundation for creating C++ wrapper generators for various languages.
It consists of four parts:
The parser converts a language-friendly C++ API description to the language-agnostic internal format and passes it to the Matcher.
The matcher parses selected C++ headers with Clang (LLVM's C++ compiler) and collects type information. That info is passed to the Generator.
The generator emits C++ source code for the wrapper.
The generated wrapper needs to be built according with language extension rules. Usually that wrapper will call into the Runtime.
The runtime C++ library holds type conversion routines that are specific to each target language but are the same for every generated wrapper.
See complete implementation of a Python wrapper generator in the
subdirectory. Both Python 2 and 3 are supported.
We use CMake, so make sure CMake version 3.5 or later is available.
We use Google protobuf for inter-process communication between the CLIF frontend and backend. Version 3.2.0 or later is required. Please install protobuf for both C++ and Python from source, as we will need some protobuf source code later on.
You must have virtualenv installed.
The steps below are in
INSTALL.sh but outlined here for clarification.
The install script sets up a Python virtual environment where it installs CLIF.
Checkout LLVM and Clang source trees (the exact SVN version as specified here is required[^ver])
# We keep it separate of the CLIF tree to avoid pip unwanted copying. mkdir $LLVMSRC_DIR cd $LLVMSRC_DIR svn co https://llvm.org/svn/llvm-project/llvm/[email protected] llvm cd llvm/tools svn co https://llvm.org/svn/llvm-project/cfe/[email protected] clang ln -sf "$CLIFSRC_DIR/clif" clif
Build and install the CLIF backend. If you use Ninja instead of
makeyour build will go significantly faster. It is used by Chromium, LLVM et al. Look at
INSTALL.shfor the directory setup and proper ...flags... to supply the
# Builds must be done outside of the LLVM tree. mkdir ../../build_matcher cd ../../build_matcher cmake ...flags... $LLVMSRC_DIR/llvm make clif-matcher make install
Replace the cmake and make commands with these to use Ninja:
cmake -G Ninja ...flags... $LLVMSRC_DIR/llvm ninja clif-matcher ninja install
If the clif-matcher build target is not found, check that you created the correct
llvm/tools/clifsymlink in the previous step. The CLIF backend builds as part of an LLVM build.
Get back to your CLIF python checkout and install it using pip.
cd "$CLIFSRC_DIR" cp "$BUILD_DIR/tools/clif/protos/ast_pb2.py" clif/protos/ pip install .
[^ver]: That version is guaranteed to work. Older versions likely do not work (they lack some APIs); later versions might work, at your own risk.
INSTALL.sh will build and install CLIF for Python (and LLVM Clang as an internal
tool) to your system by default in
To run Python CLIF use
Using your newly built pyclif
First, try some examples:
cd ~/opt/clif/examples less README.md
Next, read the CLIF Python Primer.
This is not an official Google product.