Skip to content

alexelias/cpp2c

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPP2C

This is a tool used to generate a C interface from C++ source code using clang libtooling. The tool only supports a subset of C++ features.

Very important note: This tool is not supposed to be run in isolation as is right now but is designed to be cloned in a specific location under an Android repo to work (under development/vndk/tools/cpp2c in the Android open source project).

Building and Installation

# Create and sync repo
repo init --depth=1 -u persistent-https://googleplex-android.git.corp.google.com/platform/manifest -b master
repo sync -j16

# Move tool to correct location
mv cpp2c development/vndk/tools/

# Build
source build/envsetup.sh
source development/vndk/tools/header-checker/android/envsetup.sh
lunch aosp_arm64-userdebug
croot
cd development/vndk/tools/cpp2c
mm

The development/vndk/tools/header-checker/android/envsetup.sh just exports some environment variables, you can also do this manually by running:

export LLVM_BUILD_HOST_TOOLS=true
export LLVM_PREBUILTS_VERSION=clang-r370808
export LLVM_RELEASE_VERSION=10.0.1

Running it

git clone https://github.com/samanbarghi/uThreads
cd uThreads
cpp2c include/uThreads.h -- -I./src -I/usr/include/x86_64-linux-gnu/c++/5/ -I/usr/include/c++/5.4.0 -std=c++11

An example usage would be:

cpp2c MyClassesHeader.h -wrap listOfClasses.txt -o /outputDir/ -- -I/usr/include/c++/v1/ -I/usr/local/lib/clang/10.0.0/include/ -std=c++17

Or more concretely, to run one of the generators from the test.py script:

cd development/vndk/tools/CPP2C/test
../../../../../out/host/linux-x86/bin/cpp2c MyClassesHeader.h -wrap listOfClasses.txt -o /outputDir/ -- -I/usr/include/c++/v1/ -I/usr/local/lib/clang/10.0.0/include/ -std=c++17

Output

The output will be two files (a header and a source file), located in the given directory, with the names generated by taking the given header name (MyClassesHeader in this example) and appending the word Wrapper and the necessary extension.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published