Home

Awesome

Component Interface Binder (CIB)

codecov Codacy Badge License: MIT

PlatformCI Status
OSXOSX Build Status
LinuxLinux Build Status

Meeting C++ presentation video

CIB

CIB is an architecture to publish compiler independent and ABI stable C++ SDK

It can be said that CIB architecture is an hourglass design pattern on steroid.

Jargon

  1. ABI Compatibility: Compatibility of binary C++ components even when they are built with different compilers.
  2. ABI Stability: Ability of a binary component to work with newer version of another component without recompiling. Example of ABI stability is the ability of a plugin (in binary form) of an application to seemlessly work with newer application.
  3. Forward Compatibility: It is a specific case of ABI stability where older library can work with newer client.
  4. Backward Compatibility: It is a specific case of ABI stability where newer library can work with older client.

In this document when ABI Stability is mentioned we will mean both forward and backward compatibility.

Overview

CIB is an architecture to publish compiler independent and ABI stable C++ library. This project is also about a tool that implements cib architecture automatically for given library headers. CIB can also be used as a plugin architecture for an application. One of the goal of CIB is to have minimum footprint, i.e. it should not change the way how developers write their program.

Why C++ has ABI stability issues

Actually even C has this problem, C++ has more features and so it is more difficult to achieve it with C++. Things that can cause ABI compatibility and stability issues in C++ are:

  1. Object layout.
  2. Function calling convention.
  3. Allocators and deallocators.
  4. Underlying integer size of enum.
  5. Size of various integer types.
  6. Mangled function name.
  7. Virtual function table.
  8. RTTI.
  9. Exceptions.
  10. Inheritance.

First 5 can be problems in C as well. But techniques are well known and used to circumvent them to achieve ABI stability in C. For C++, problems start with name mangling, that's the first reason of misunderstanding that can happen between 2 components. Layout for C++ objects are far more complex than C. There can be different layout for virtual tables depending upon compiler. Same goes for RTTI and exception. So, ensuring ABI compatibility is hard in C++. Ensuring ABI stability is super hard in general. One thing to note is that maintaining ABI compatibility and stability in C is largely a responsibility of library developers. In C++, CIB can make ABI compatibility and stability achievable, but developers will have to be reponsible in similar way as they need to be when pure C is used.

CIB Architecture

Design principle

Integration architecture produced by CIB

It's basically an hourglass pattern with slightly different implementation than described in CppCon talk, with the aim of:

Architecture Elements

Following are the broad elements of CIB architecture:

The rest of the details of CIB architecture can be understood with examples.

Architecture Detail

Please see Examples to know the details.

Presentation

CIB was presented at meeting C++ conference in 2020.

Demo projects

There are few projects that are meant to demonstrate CIB's capability. Please see Demo for details.

Building CIB

Get the source

git clone https://github.com/satya-das/common.git
git clone https://github.com/satya-das/cppparser.git
git clone https://github.com/satya-das/cib.git

Configure and build

On Unix like platforms, like Linux and MAC

cd cib
mkdir builds
cd builds
cmake ..
make && make test

Alternatively, if you prefer Ninja instead of make:

cd cib
mkdir builds
cd builds
cmake -G Ninja ..
ninja && ninja test

On Windows

Following sequence of commands has been tested and works perfectly:

# Open DOS command window
cd path-to-cib
md builds
cd builds
# The next line is important
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat"
cmake -G Ninja ..
ninja && ninja test

Case Study

cib tool is used to cibify PoDoFo library and the feasibility of CIB architecture and tool got tested. Also, the impact on binary size, runtime performance, and memroy usage measured and compared with original library that didn't use CIB architecture.

See PoDoFo case study for more details.