Skip to content
This repository has been archived by the owner on Aug 19, 2024. It is now read-only.

Attempt to move building to GitHub Actions #97

Closed
qstokkink opened this issue Jul 29, 2024 · 5 comments · Fixed by #107
Closed

Attempt to move building to GitHub Actions #97

qstokkink opened this issue Jul 29, 2024 · 5 comments · Fixed by #107
Assignees
Labels
enhancement New feature or request

Comments

@qstokkink
Copy link
Owner

qstokkink commented Jul 29, 2024

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 qstokkink added the enhancement New feature or request label Jul 29, 2024
@qstokkink qstokkink self-assigned this Jul 29, 2024
@qstokkink
Copy link
Owner Author

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
Copy link
Owner Author

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
Copy link
Owner Author

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:

  • src/run_unit_tests.py
  • src/tribler/test_integration/
  • src/tribler/test_unit/
  • src/tribler/ui, except for the dist created by npm
  • everything in pyipv8 except ipv8_service.py and the non-test folders in pyipv8/ipv8

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
Copy link
Owner Author

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
Copy link
Owner Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.