diff --git a/build.py b/build.py index 19e99fdeee1..70563df6898 100644 --- a/build.py +++ b/build.py @@ -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: @@ -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() diff --git a/build/win/makedist_win.bat b/build/win/makedist_win.bat index 30bdbbbac8e..77a49b798d5 100644 --- a/build/win/makedist_win.bat +++ b/build/win/makedist_win.bat @@ -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 diff --git a/setup.py b/setup.py index 85e091cb9f3..ccfef951491 100644 --- a/setup.py +++ b/setup.py @@ -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): @@ -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 )