GithubHelp home page GithubHelp logo

mizux / cmake-pybind11 Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 97 KB

Test to build a Native Python 3 package using pybind11

License: Apache License 2.0

CMake 20.88% C++ 42.90% Makefile 8.21% Dockerfile 7.42% Shell 12.61% Python 7.97%
pybind11 python cpp cmake native-library mizux

cmake-pybind11's Introduction

Github-CI:
Build Status Build Status Build Status
Build Status Build Status

Introduction

| Requirement | Codemap | Dependencies | Build | CI | Appendices | License |

This is an example of how to create a Modern CMake C++/Python Project.

This project aim to explain how you build a Python 3.6+ native wheel package using Python3 and a setup.py.
e.g. You have a cross platform C++ library (using a CMake based build) and a Python wrapper on it thanks to Pybind11.
Then you want to provide a cross-platform Python packages to consume it in a Python project...

This project should run on GNU/Linux, MacOS and Windows.

Requirement

You'll need:

  • "CMake >= 3.18".
  • "Python >= 3.6" and python module 'pip' (ed "setuptools" and "wheel" will be auto installed on demand).
  • "Pybind11 >= 2.10".

Codemap

The project layout is as follow:

Dependencies

To complexify a little, the CMake project is composed of three libraries (Foo, Bar and FooBar) with the following dependencies:

Foo:
Bar:
FooBar: PUBLIC Foo PRIVATE Bar

Build Process

To Create a native dependent package which will contains two parts:

  • A bunch of native libraries for the supported platform targeted.
  • The Python code depending on it.

note: Since Pypi.org support multiple packages, we will simply upload one package per supported platform.

Local Package

The pipeline for linux-x86-64 should be as follow:
Local Pipeline Legend

Building local native Package

Thus we have the C++ shared library libFoo.so and the pybind11 Python shared library e.g. pyFoo.so in the same package.

Here some dev-note concerning this setup.py.

  • This package is a native package containing native libraries.

Then you can generate the package and install it locally using:

python3 setup.py bdist_wheel
python3 -m pip install --user --find-links=dist cmakepybind11

If everything good the package (located in <buildir>/python/dist) should have this layout:

{...}/dist/cmakepybind11-X.Y.9999-cp3Z-cp3Z-<platform>.whl:
\- pythonnative
   \- __init__.py
   \- .libs
      \- libFoo.so
      \- ...
   \- foo
      \- __init__.py
      \- pyFoo.so
...

note: <platform> could be manylinux2014_x86_64, macosx_10_9_x86_64 or win-amd64.

tips: since wheel package are just zip archive you can use unzip -l <package>.whl to study their layout.

Appendices

Few links on the subject...

Resources

Project layout:

  • The Pitchfork Layout Revision 1 (cxx-pflR1)

CMake:

Python:

Misc

Image has been generated using plantuml:

plantuml -Tsvg docs/{file}.dot

So you can find the dot source files in docs.

License

Apache 2. See the LICENSE file for details.

Disclaimer

This is not an official Google product, it is just code that happens to be owned by Google.

cmake-pybind11's People

Contributors

mizux avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

quantum-ml-geek

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.