From e0bb4890e21decbaed8f0702f4ea5429af8831cc Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Fri, 22 Mar 2024 16:24:16 +0100 Subject: [PATCH 1/3] Update build.py to build wheel package as well --- build.py | 145 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 61 deletions(-) diff --git a/build.py b/build.py index 19e99fdeee1..728f9e5d7ca 100644 --- a/build.py +++ b/build.py @@ -1,6 +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. + +Building executable depends on cx_Freeze. + +1) If cx_Freeze is not installed, +setuptools is used to build the wheel package. + +To create a wheel package: +python setup.py bdist_wheel + +2) If cx_Freeze is installed, To create a build: python setup.py build @@ -19,64 +29,77 @@ 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' -} + +try: + import cx_Freeze +except ImportError: + cx_Freeze = None + +if cx_Freeze is None: + # If cx_Freeze is not installed, use setuptools to build the wheel package + from setuptools import setup + app_executable = None + build_exe_options = {} + +else: + 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"] From b29dec22fc9b0b20937fcf8cc8fb9e07d367f31a Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Mon, 25 Mar 2024 14:38:18 +0100 Subject: [PATCH 2/3] Add libtorrent and ssl as additional explicit packages to include on binary build Add OpenSSL DLLs during build Move added DLLs to lib directory --- build.py | 4 +++- build/win/makedist_win.bat | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/build.py b/build.py index 728f9e5d7ca..c8a9268efa9 100644 --- a/build.py +++ b/build.py @@ -68,7 +68,9 @@ "requests", "tribler.core", "tribler.gui", - "faker" + "faker", + "libtorrent", + "ssl", ] # These files will be included in the build 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 From d21806f6c3305823579f2df4d90fbddfc1064296 Mon Sep 17 00:00:00 2001 From: Sandip Pandey Date: Wed, 27 Mar 2024 12:00:55 +0100 Subject: [PATCH 3/3] Fix building wheel and binaries using setup.py --- build.py | 82 ++++++++++++++++++++++++++++++-------------------------- setup.py | 6 ++--- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/build.py b/build.py index c8a9268efa9..70563df6898 100644 --- a/build.py +++ b/build.py @@ -2,17 +2,15 @@ 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. -Building executable depends on cx_Freeze. - -1) If cx_Freeze is not installed, -setuptools is used to build the wheel package. +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) If cx_Freeze is installed, +2) Building executable is done using cx_Freeze. -To create a build: +To build an executable: python setup.py build To create a distributable package: @@ -21,38 +19,23 @@ 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 -try: - import cx_Freeze -except ImportError: - cx_Freeze = None - -if cx_Freeze is None: - # If cx_Freeze is not installed, use setuptools to build the wheel package +def get_wheel_build_options(): from setuptools import setup - app_executable = None - build_exe_options = {} + setup_options = {"build_exe": {}} + setup_executables = None + return setup, setup_options, setup_executables -else: - 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, - ) +def get_freeze_build_options(): + from cx_Freeze import setup, Executable # These packages will be included in the build sys.path.insert(0, 'src') @@ -96,12 +79,35 @@ 'matplotlib' ] - build_exe_options = { - "packages": included_packages, - "excludes": excluded_packages, - "include_files": included_files, - "include_msvcr": True, - 'build_exe': 'dist/tribler' + setup_options = { + "build_exe": { + "packages": included_packages, + "excludes": excluded_packages, + "include_files": included_files, + "include_msvcr": True, + 'build_exe': 'dist/tribler' + } } -__all__ = ["setup", "app_executable", "build_exe_options"] + 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/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 )