using zig with allyourcodebase/cpython to cross compile and ship binaries that run python scripts? #15
Replies: 1 comment
-
|
no experience with this exact package, but i have some with trying to embed python; there might be some ways to do this (and having zig do the heavy lifting of compiling cpython statically is a big advantage): method 1: use the freezing mechanism provided by cpython itself to freeze your scripts (and he standard python libraries) at compile time and link them, then have a look at how the python binary sets up the interpreter environment and modify it to call your freezed entrypoint method 2: do some deep research to make nuitka use zig as a build system or compile most of cpython as a statically linkable library and make nuitka link it both require deep diving into complex code bases, but both suffer from one of python's biggest problems when it comes to embedding: if you have a library that uses a c python package (look at, for example, zstd) you also have to ship it (either compile and link it statically or ship it as an .so/.dll); you also have to ship additional artifacts, such as the list of certificate authorities trusted by certipy (a dependency of requests) or you have to patch things to bypass that; lastly, there are some packages (such as pycryptodome) that do some very stupid things such as forcefully loading binaries at runtime and calling them with ctypes overall, have to figure out how to do things and what to patch on a case by case basis, if you want an quick and easy solution you can use pyinstaller, py2exe or nuitka out of the box, all have their drawbacks, depends on you if they are deal breakers |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am very curious if its possible to write a
build.zigthat leverageshttps://github.com/allyourcodebase/cpythonand compiles/embeds python scripts which then get run on the users machine when they execute the binary?The whole purpose of this thought is because python is notoriously bad at porting across operating systems, and very annoying when you leverage too many pypi packages too. Given that the cpython interpreter is already ported to build with zig, i'm trying to understand how much of an extra leap it would be to start building and distributing python scripts/packages from the zig build chain (through compiled binaries)
In my head it seems as easy as "embed the python files into the binary with the same structure as the source code structure, and invoke cpython on execution with the "file" path of the main entry point"
But obviously I have no idea if it really is that easy, and even if it WAS, how you would even do that. I would love some advice or some examples of related problems like this that have been solved elsewhere in the zig ecosystem!
Beta Was this translation helpful? Give feedback.
All reactions