evo-lua / evo-runtime

General-purpose Lua programming platform and developer toolkit
https://evo-lua.github.io
Mozilla Public License 2.0
12 stars 1 forks source link

Re-implement zip apps (standalone bundles) to easily distribute binary releases for Lua apps #217

Closed rdw-software closed 1 year ago

rdw-software commented 1 year ago

Similar to what evo-luvi (and luvi) can do, though I remember there were quite a few kinks that needed to be ironed out.

See also: https://docs.python.org/3/library/zipapp.html

Goals:

Evo-luvi (and luvi itself) have some extra options like setting a different entry point. I'd rather avoid that, at least for now.

rdw-software commented 1 year ago

I remember there were many problems with VFS lookups and path resolution, if trying to load files from the bundle. To avoid that and still enable the most important functionality (loading files from the bundle, without re-architecting the app), I'd consider something like the following to be a decent starting point for further refinements:

This would solve multiple problems at once:

Edit: This would still introduce some complexity and a sort-of "module system", which I'm not a fan of. Maybe it's more sensible to just start with the "always load main.lua from the archive and everything else must be present on disk" approach first?

Also, since main.lua has access to miniz and everything, more complex processing could be implemented as needed (by users).

rdw-software commented 1 year ago

I actually ran into some more problems: The offset computation breaks down for large files (>8MB) in miniz. It seems the Luvit fork modified the code for this in mz_zip_reader_read_central_dir and other parts, which means there are two options:

  1. Copy/paste Luvit's fork and don't benefit from upstream changes to miniz itself (but possibly discover new issues)
  2. Somehow plaster over the original miniz issues (such as the early exit that breaks INFLATE completely) to hack in the changes

I dislike both of these, so I choose option 3: Screw this and revisit it later, maybe. It's not that important right now, anyway.

rdw-software commented 1 year ago

OK, actually I hate giving up... Let's survey first the actual list of changes (diff between Luvit miniz and upstream):

Since using upstream miniz makes it impossible to implement zip apps and using the Luvit fork is putting extra maintenance work on me (or them, if there are bugs in the fork itself or upstream changes need to be integrated), a workaround is needed.

Prototyping some ideas, the following solution might work - but it introduces some extra complexity:

This has been confirmed to work with the current executable size (21MB on Windows, which is beyond the 8MB limit).

Potential advantages:

Now, to the disadvantages:

So overall it seems like a workable solution, albeit not an ideal one. The rest depends on how much should be added on top.