question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a simple example about how to build your own C++ Pyodide package

See original GitHub issue

📚 Documentation

I saw that there is already a page on the Pyodide website titled “Creating a Pyodide package”, but for a C/C++ developer it is not clear how to proceed.

In my conversation here, @JeanChristopherMorinPerso informed me that it is possible to create Pyodide packages from C++ code that has the Pybind11 wrapper and that he made it himself for his project.

My C++ library already has the Pybind11 wrapper, but even so, I’m not finding documentation or a simple example that I can follow and get a valid Pyodide package.

Finally, I tried to understand what was the reasoning behind compiling Pyodide packages which were originally written in C/C++ contained on Github in the ‘packges’ folder, (example: ‘numpy’), but I couldn’t understand the logic of the contents of these folders and how everything is actually working.

So for libraries written in C/C++ I have 2 suggestions:

Suggestion 01: C++ code without Pybind11 wrapper

Adding to the documentation (maybe even in the README) is a simple little example of how to create a Pyodide package from a C++ library. This simple example could be named: Hello World.

Example:

#include <iostream>

class HelloWorld
{
public:
    HelloWorld() {
        std::cout << "Hello" << std::endl;
    }
}

Suggestion 02: Code with Pybind11 wrapper

Add the same type of simple example mentioned above to the documentation but that contains a Pybind11 wrapper

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:4
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
josephroccacommented, Jun 20, 2022

Question 01: Did you mean that I should create a new package inside Pyodide folder containing pure C++ code? As my “Hello World” above? Question 02: If yes, should I write the Pybind11 wrapper too? Or do you prefer the only pure C++ class?

What I had in mind is that you’d create a Python package that uses C++ and Pybind11 like you normally would (I.e. ignore the Pyodide aspect). You’d just create this package in a new Github repo, and then publish the package to PyPi, and then run the commands in this comment sequentially, where <package-name> is the name of the PyPi package that you published.

IIUC, that should work “out of the box” for simple C++/Python packages. If it doesn’t, then we can troubleshoot from there and add extra steps to the “hello world” tutorial that we write.

1reaction
hoodmanecommented, Jun 21, 2022

it is not easy for new contributors to add a package that uses CMake

Nor is it easy for me. My approach is to ask henryiii or ryanking13.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a Pyodide package — Version 0.21.3
Make the resulting file accessible as part of your web applications, and install it with micropip.install by URL. Below is a more complete...
Read more >
Creating a Pyodide package
If the package includes C/C++/Cython extensions: Build the package natively, keeping track of invocations of the native compiler and linker. Rebuild the package...
Read more >
Creating a Pyodide package — Version 0.18.0
Build the package natively, keeping track of invocations of the native compiler and linker. Rebuild the package using emscripten to target WebAssembly. If...
Read more >
Creating a Pyodide package — Version 0.19.1
The package build pipeline#. Pyodide includes a toolchain to make it easier to add new third-party Python libraries to the build. We automate...
Read more >
Getting started — Version 0.21.3 - Pyodide
You can also download a release from GitHub releases or build Pyodide yourself. See Downloading and deploying Pyodide for more details. The pyodide.js...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found