kivy / kivy-ios

Toolchain for compiling Python / Kivy / other libraries for iOS
https://kivy.org/docs/guide/packaging-ios.html
MIT License
758 stars 237 forks source link

how do you init your custom c module at app startup? #848

Closed tcaduser closed 8 months ago

tcaduser commented 10 months ago

Versions

Describe the bug

My custom recipe successfully builds an archive. In addition copying the archive file into the recipes of my environment gets it installed into the image. However, the only way to get the module loaded is for me to add it to the command table in main.m

    NSLog(@"Initializing python");
    PyImport_AppendInittab("devsim_py3", PyInit_devsim_py3);
    Py_Initialize();

where I forward declare my init outside of the main function:

PyObject *PyInit_devsim_py3(void);

To Reproduce

build your own custom recipe which compiles a static archive creating a new module

Expected behavior

Document or make it easy

Logs

// REPLACE ME: Paste the build output containing the error

Screenshots

Additional context Add any other context about the problem here.

tcaduser commented 10 months ago

to clarify what I am asking for. I have a custom recipe which can build my python module. It has the entry point function:

PyInit_devsim_py3

I am trying to understand how to get this imported in my application. Should I explicitly be using PyImport_AppendInittab in main.m? Should I be using a different naming convention for my PyInit function?

tcaduser commented 10 months ago

It looks like that python is patched to override the dlopen on an external shared library with the internal dlsym on the python executable. https://groups.google.com/g/kivy-users/c/poh12uJ5DCM https://discord.com/channels/423249981340778496/713442856190083094/989210942581669929

tcaduser commented 10 months ago

I now understand the last piece of the puzzle. What is needed is to create an empty .so file with the same name as your module. Then, the CustomBuiltinImporter.find_module method defined in main.m will be able to see the module, and call the appropriate PyInit function using dlsym on the application.

github-actions[bot] commented 8 months ago

👋 We use the issue tracker exclusively for bug reports and feature requests. However, this issue appears to be a support request. Please use our support channels to get help with the project.

If you're having trouble installing or using kivy-ios, maybe you could be interested to installation and requirements.

Let us know if this comment was made in error, and we'll be happy to reopen the issue.