qstokkink / TriblerExperimental

GNU General Public License v3.0
6 stars 2 forks source link

Attempt to move building to GitHub Actions #97

Closed qstokkink closed 1 month ago

qstokkink commented 1 month ago

Inspired by other projects it seems that we can downsize our build procedures immensely by moving to GitHub Actions, powered by nuitka (since we have a setup.py, using this).

IF this works as advertised, we can easily create builds on GitHub Actions. However, we would still need all of the fluff like NSIS and Debian metadata to make installers and properly register the executable in the OS.

qstokkink commented 1 month ago

Just to reiterate what was said in #98: Nuitka does not work with PonyORM (one does not supply co_code and the other critically depends on it).

I guess we're going back to cx_Freeze.

qstokkink commented 1 month ago

Going all-in on the recommended cx_Freeze declarative format does work. However, this does not produce the elegant build scripts I wanted, excluding files is (too) hard, and the executable size is huge.

I'm veering toward simply doing what we always did in Jenkins, but using GitHub Actions.

qstokkink commented 1 month ago

Considering the cx_Freeze limitations, it seems easiest to simply remove all files from the source tree that should not be in the build. However, again, this is far from elegant.

Practically, this means checking out the repo with submodules using GitHub Actions as usual and then remove:

The above is somewhat error-prone if we have to do all of this by hand (though I don't think we'll be refactoring the entire directory structure very often). So, I still want to explore using a tool (e.g., Nuitka) to determine what files should be kept in the repository after checkout.

qstokkink commented 1 month ago

For my next attempt, I used nuitka to determine the required .py files:

nuitka --report=compilation-report.xml --onefile --standalone --include-package=tribler --nofollow-import-to="tribler.test_*" src/run_tribler.py

This produces a compilation-report.xml. I convert the report to file names, printing the destination and the source:

import os
import sys
from xml.etree.ElementTree import parse

from nuitka.PythonVersions import getSystemPrefixPath

tree = parse("compilation-report.xml")
root = tree.getroot()

sys_prefix = sys.prefix
real_sys_prefix = getSystemPrefixPath()
cwd = os.getcwd()

library_directories = [
    os.path.abspath("./src") + "/",
    f"{sys_prefix}/lib/python3/dist-packages/",
    f"{sys_prefix}/lib/python3.10/",
    "~/.local/lib/python3.10/site-packages/"
]

for child in root.iter("module"):
    reported_path = child.attrib["source_path"]

    # Undo path shortening in Nuitka
    reported_path = reported_path.replace("${sys.prefix}", sys_prefix)
    reported_path = reported_path.replace("${sys.real_prefix}", real_sys_prefix)
    reported_path = reported_path.replace("${cwd}", cwd)

    # Normalize to local directory
    normalized_path = reported_path
    for libdir in library_directories:
        if normalized_path.startswith(libdir):
            normalized_path = normalized_path[len(libdir):]
            break

    # The new destination path and the path we need to copy it from
    print(normalized_path, reported_path)
    # shutil.copyfile(reported_path, normalized_path)

If we copy only these files, a build using cx_Freeze should both work and include only the strictly necessary files.

qstokkink commented 1 month ago

Using Nuitka to reduce the file size is a nice optimization but, ultimately, I guess we should just port our current scripts (unmodified) to GitHub Actions for now. Optimizations can come later.