All Projects → google → Clif

google / Clif

Licence: apache-2.0
Binding generator to wrap C++ for Python using LLVM.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Clif

Pfr
std::tuple like methods for user defined types without any macro or boilerplate code
Stars: ✭ 896 (+6.04%)
Mutual labels:  clang
Randomix
🎲 An open source app to choose randomly between numbers, answers, options and so on.
Stars: ✭ 24 (-97.16%)
Mutual labels:  generator
Woboq codebrowser
Woboq CodeBrowser
Stars: ✭ 837 (-0.95%)
Mutual labels:  clang
Go Git Cmd Wrapper
A simple wrapper around git command in Go.
Stars: ✭ 22 (-97.4%)
Mutual labels:  wrapper
Swaddle
Automagically create API clients/wrappers in JavaScript
Stars: ✭ 23 (-97.28%)
Mutual labels:  wrapper
Cxxhttp
Asynchronous, Header-only C++ HTTP-over-(TCP|UNIX Socket|STDIO) Library
Stars: ✭ 24 (-97.16%)
Mutual labels:  clang
Wykop Es6
Wykop.pl API library
Stars: ✭ 17 (-97.99%)
Mutual labels:  wrapper
Objc Uti
Objective-C wrapper for Uniform Type Identifiers (UTIs)
Stars: ✭ 7 (-99.17%)
Mutual labels:  wrapper
Generator Modular Angular
A truly modular yeoman generator for AngularJS all device apps.
Stars: ✭ 23 (-97.28%)
Mutual labels:  generator
Graphqlphpgenerator
GraphQL PHP types generator...
Stars: ✭ 25 (-97.04%)
Mutual labels:  generator
Td Angular Barcode
Barcode Generator for Angular 1 (Supports 90+ barcode types: qr, aztec, code128, ean, isbn, interleaved2of5, ...)
Stars: ✭ 22 (-97.4%)
Mutual labels:  generator
Forge Server Utils
Tools for accessing Autodesk Forge APIs from modern Node.js apps.
Stars: ✭ 23 (-97.28%)
Mutual labels:  generator
Headercollapsiblelayout
A wrapper layout that can easily split your current layout into header and body, and provides smooth header collapsing action with related event callbacks.
Stars: ✭ 24 (-97.16%)
Mutual labels:  wrapper
Mvvmcodegenerator
Mvvm generator C#
Stars: ✭ 19 (-97.75%)
Mutual labels:  generator
Vim Clang Format
Vim plugin for clang-format, a formatter for C, C++, Obj-C, Java, JavaScript, TypeScript and ProtoBuf.
Stars: ✭ 837 (-0.95%)
Mutual labels:  clang
Grpc Gateway Generator
A script to generate a ready to use grpc-gateway with swagger, by just providing the path to the protos and a simple configuration file.
Stars: ✭ 18 (-97.87%)
Mutual labels:  generator
Agots
Anomaly Generator on Time Series
Stars: ✭ 24 (-97.16%)
Mutual labels:  generator
Color coded
A vim plugin for libclang-based highlighting of C, C++, ObjC
Stars: ✭ 841 (-0.47%)
Mutual labels:  clang
Jocs.github.io
💯Jocs 的个人博客,所有的文章都在 issues 里面
Stars: ✭ 840 (-0.59%)
Mutual labels:  generator
Simple Bigtable
Stars: ✭ 24 (-97.16%)
Mutual labels:  wrapper

C++ Language Interface Foundation (CLIF)

CI

PyCLIF defines a C++ API to be wrapped via a concise What You See Is What You Get interface file (example), with a syntax derived from pytypedecl.

About the name of this repo: CLIF was started as a common foundation for creating C++ wrapper generators for various languages. However, currently Python is the only target language, and there is no development activity for other target languages.

Overview

PyCLIF consists of four parts:

  1. Parser
  2. Matcher
  3. Generator
  4. Runtime

Parser

The parser converts a language-friendly C++ API description to the language-agnostic internal format and passes it to the Matcher.

Matcher

The matcher parses selected C++ headers with Clang (LLVM's C++ compiler) and collects type information. That info is passed to the Generator.

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.

Runtime

The runtime C++ library holds type conversion routines that are specific to each target language but are the same for every generated wrapper.

Python CLIF

See complete implementation of a Python wrapper generator in the /python/ subdirectory. Both Python 2 and 3 are supported.

Installation

Prerequisites

  1. We use CMake, so make sure CMake version 3.5 or later is available. (For example, Debian 8 only has version 3.0, so in that case you'll need to install an up-to-date CMake.)

  2. We use Google protobuf for inter-process communication between the CLIF frontend and backend. Version 3.8.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.

  3. You must have virtualenv installed.

  4. You must have pyparsing installed, so we can build protobuf. Use pip install 'pyparsing==2.2.0' to fetch the correct version.

  5. Make sure pkg-config --libs python works (e.g. install python-dev and pkg-config).

  6. We use Clang (LLVM's C++ compiler) to parse C++ headers, so make sure Clang and LLVM version 11 is available. On Ubuntu and Debian, you can install the prebuilt version from https://apt.llvm.org.

  7. You must have abseil-cpp installed.

  8. We use googletest for unit testing C++ libraries.

For references, there is a Dockerfile running an Ubuntu image with all the prerequisites already installed. See the instructions at the top of the file.

Building

To build and install CLIF to a virtualenv, run:

virtualenv --python=python3.x clif-venv
./INSTALL.sh clif-venv/bin/python

The following outlines the steps in INSTALL.sh for clarification.

  1. Build and install the CLIF backend. If you use Ninja instead of make your build will go significantly faster. It is used by Chromium, LLVM et al. Look at INSTALL.sh for the directory setup and proper ...flags... to supply the cmake command here:

    mkdir build
    cd build
    cmake ...flags... $CLIFSRC_DIR
    make clif-matcher
    make install
    

    Replace the cmake and make commands with these to use Ninja:

    cmake -G Ninja ...flags... $CLIFSRC_DIR
    ninja clif-matcher
    ninja -j 2 install
    

    If you have more than one Python version installed (eg. python3.6 and python3.7) cmake may have problems finding python libraries for the Python you specified as INSTALL.sh argument and uses the default Python instead. To help cmake use the correct Python add the following options to the cmake command (substitute the correct path for your system):

    cmake ... \
      -DPYTHON_INCLUDE_DIR="/usr/include/python3.6" \
      -DPYTHON_LIBRARY="/usr/lib/x86_64-linux-gnu/libpython3.6m.so" \
      -DPYTHON_EXECUTABLE="/usr/bin/python3.6" \
      "${CMAKE_G_FLAGS[@]}" "$CLIFSRC_DIR"
    
  2. Get back to your CLIF python checkout and install it using pip.

    cd "$CLIFSRC_DIR"
    cp "$BUILD_DIR/clif/protos/ast_pb2.py" clif/protos/
    cp "$BUILD_DIR/clif/python/utils/proto_util.cc" clif/python/utils/
    cp "$BUILD_DIR/clif/python/utils/proto_util_clif.h" clif/python/utils/
    cp "$BUILD_DIR/clif/python/utils/proto_util.init.cc" clif/python/utils/
    pip install .
    

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-matcher to CMake install directory and CLIF for Python to the given Python (virtual) environment.

To run Python CLIF use pyclif.

Using your newly built pyclif

First, try some examples:

cd examples
less README.md

Next, read the Python CLIF User Manual.

For more details please refer to:

  1. CLIF Python Primer
  2. CLIF FAQ

Disclaimer

This is not an official Google product.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].