Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix binary build #7949

Merged
merged 3 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 101 additions & 70 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
"""
This file includes the build configuration for the Tribler executable using CX Freeze.
The exports of this file are used in setup.py to build the executable.
This file includes the build configuration for the Tribler.
The exports of this file are used in setup.py to build the executable or wheel package.

To create a build:
There are two build options:
1) setuptools is used to build the wheel package.

To create a wheel package:
python setup.py bdist_wheel

2) Building executable is done using cx_Freeze.

To build an executable:
python setup.py build

To create a distributable package:
Expand All @@ -11,72 +19,95 @@
To create a distributable package for a specific platform:
python setup.py bdist_mac
python setup.py bdist_win

Building wheel and building executable had to be separated because cx_Freeze does not
support building wheels. Therefore, the build options are separated into two functions
and the appropriate function is called based on the command line arguments.
"""
import os
import re
import shutil
import sys
from pathlib import Path

from setuptools import find_packages
from cx_Freeze import setup, Executable

app_name = "Tribler" if sys.platform != "linux" else "tribler"
app_script = "src/tribler/run.py"
app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns"
app_executable = Executable(
target_name=app_name,
script=app_script,
base="Win32GUI" if sys.platform == "win32" else None,
icon=app_icon_path,
)

# These packages will be included in the build
sys.path.insert(0, 'src')
included_packages = [
"aiohttp_apispec",
"sentry_sdk",
"ipv8",
"PIL",
"pkg_resources",
"pydantic",
"pyqtgraph",
"PyQt5.QtTest",
"requests",
"tribler.core",
"tribler.gui",
"faker"
]

# These files will be included in the build
included_files = [
("src/tribler/gui/qt_resources", "qt_resources"),
("src/tribler/gui/images", "images"),
("src/tribler/gui/i18n", "i18n"),
("src/tribler/core", "tribler_source/tribler/core"),
("src/tribler/gui", "tribler_source/tribler/gui"),
("build/win/resources", "tribler_source/resources"),
]

# These packages will be excluded from the build
excluded_packages = [
'wx',
'PyQt4',
'FixTk',
'tcl',
'tk',
'_tkinter',
'tkinter',
'Tkinter',
'matplotlib'
]

build_exe_options = {
"packages": included_packages,
"excludes": excluded_packages,
"include_files": included_files,
"include_msvcr": True,
'build_exe': 'dist/tribler'
}

__all__ = ["setup", "app_executable", "build_exe_options"]


def get_wheel_build_options():
from setuptools import setup
setup_options = {"build_exe": {}}
setup_executables = None
return setup, setup_options, setup_executables


def get_freeze_build_options():
from cx_Freeze import setup, Executable

# These packages will be included in the build
sys.path.insert(0, 'src')
included_packages = [
"aiohttp_apispec",
"sentry_sdk",
"ipv8",
"PIL",
"pkg_resources",
"pydantic",
"pyqtgraph",
"PyQt5.QtTest",
"requests",
"tribler.core",
"tribler.gui",
"faker",
"libtorrent",
"ssl",
]

# These files will be included in the build
included_files = [
("src/tribler/gui/qt_resources", "qt_resources"),
("src/tribler/gui/images", "images"),
("src/tribler/gui/i18n", "i18n"),
("src/tribler/core", "tribler_source/tribler/core"),
("src/tribler/gui", "tribler_source/tribler/gui"),
("build/win/resources", "tribler_source/resources"),
]

# These packages will be excluded from the build
excluded_packages = [
'wx',
'PyQt4',
'FixTk',
'tcl',
'tk',
'_tkinter',
'tkinter',
'Tkinter',
'matplotlib'
]

setup_options = {
"build_exe": {
"packages": included_packages,
"excludes": excluded_packages,
"include_files": included_files,
"include_msvcr": True,
'build_exe': 'dist/tribler'
}
}

app_name = "Tribler" if sys.platform != "linux" else "tribler"
app_script = "src/tribler/run.py"
app_icon_path = "build/win/resources/tribler.ico" if sys.platform == "win32" else "build/mac/resources/tribler.icns"
setup_executables = [
Executable(
target_name=app_name,
script=app_script,
base="Win32GUI" if sys.platform == "win32" else None,
icon=app_icon_path,
)
]
return setup, setup_options, setup_executables


# Based on the command line arguments, get the build options.
# If the command line arguments include 'setup.py' and 'bdist_wheel',
# then the options are for building a wheel package.
# Otherwise, the options are for building an executable (any other).
if {'setup.py', 'bdist_wheel'}.issubset(sys.argv):
setup, setup_options, setup_executables = get_wheel_build_options()
else:
setup, setup_options, setup_executables = get_freeze_build_options()
6 changes: 3 additions & 3 deletions build/win/makedist_win.bat
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ REM copy C:\build\vc_redist_110.exe dist\tribler
copy C:\build\vc_redist_140.exe dist\tribler

REM Copy various libraries required on runtime (libsodium and openssl)
copy C:\build\libsodium.dll dist\tribler
REM Sandip, 2019-10-24: No need to copy openssl dlls separately
REM copy C:\build\openssl\*.dll dist\tribler
copy C:\build\libsodium.dll dist\tribler\lib
REM Sandip, 2024-03-26: Some openssl dlls are missing so need to be copied manually.
copy C:\build\openssl\*.dll dist\tribler\lib


@echo Running NSIS
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from setuptools import find_packages

from build import app_executable, build_exe_options, setup
from build import setup, setup_options, setup_executables


def read_version_from_file(file_path):
Expand Down Expand Up @@ -86,6 +86,6 @@ def read_requirements(file_name, directory='.'):
"Topic :: Security :: Cryptography",
"Operating System :: OS Independent",
],
options={"build_exe": build_exe_options},
executables=[app_executable]
options=setup_options,
executables=setup_executables
)
Loading