Git Product home page Git Product logo

tolc's Introduction

Tolc aims to make it trivial to use C++ from other languages. It does not require you to change any code, and it's integrable in any project. Make C++ libraries feel natural to use in any language!

Design goals:

  • No, or minimal overhead - You are using C++ for a reason
  • Cross platform/compiler - Works in the same way on Linux, MacOS, and Windows, across compilers
  • No vendor-lockin - Generated bindings are readable, start writing them manually at any time

Usage

Tolc provides easy to use abstractions to create a bindings library directly from CMake:

tolc_create_bindings(
  TARGET MyLib
  LANGUAGE python
  OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/python-bindings
)

This will extract the public API from the target MyLib, give it to Tolc to create bindings, and expose it to CMake as the target MyLib_python. To see all options available for tolc_create_bindings, please see the the documentation.

In this example you will find the built CPython library under <build_directory>/tolc, so you can use it straight away with:

$ cd build/tolc
$ python3
>>> import MyLib
>>> MyLib.myCppFunction()

Installing

The prebuilt binaries are available under the releases tab in this repository. You may simply install them directly from there, or use CMake to download the binary for your platform directly:

# Can be ["latest", "v0.2.0", ...]
set(tolc_version latest)
include(FetchContent)
FetchContent_Declare(
  tolc_entry
  URL https://github.com/Tolc-Software/tolc/releases/download/${tolc_version}/tolc-${CMAKE_HOST_SYSTEM_NAME}.tar.xz
)
FetchContent_Populate(tolc_entry)

set(tolc_DIR ${tolc_entry_SOURCE_DIR}/lib/cmake/tolc)
find_package(
  tolc
  CONFIG
  REQUIRED
)

This will download the Tolc binary locally for Linux, MacOS, or Windows, depending on the expansion of ${CMAKE_HOST_SYSTEM_NAME}. After the call to find_package, you can use any CMake function provided by Tolc.

Building

Tolc can be built on Linux, MacOS, and Windows. See the CI pipelines for more platform specific information.

Here is a general overview:

Requirements:

  • CMake
  • python3
  • conan
  • clang

Configure the project:

$ cmake -S. -Bbuild -G Ninja -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_C_COMPILER="clang" -DCMAKE_BUILD_TYPE="Debug" -DENABLE_TESTING=ON -DENABLE_PACKAGING=ON

Build tolc:

cmake --build build

Test with ctest:

cd build
ctest

Create install package with CPack:

$ cpack -G TGZ --config build/CPackConfig.cmake

This repository holds the command line interface for tolc, see the Parser for how the C++ to be translated is parsed, or one of the language modules to see how the output is written.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.