diff --git a/Tools/defines.py b/Tools/defines.py index 39466cc2..f5d54235 100644 --- a/Tools/defines.py +++ b/Tools/defines.py @@ -25,10 +25,11 @@ QT_VERSION = "6.6.0" QT_BIN_PATH = QT_PATH.joinpath(f"{QT_VERSION}/{QT_PLATFORM}/bin") QT_TOOLS_PATH = QT_PATH.joinpath("Tools/") QT_IFW_VERSION = "4.6" -# 02.06.2023 https://gitlab.com/kelteseth/screenplay-vcpkg : -VCPKG_VERSION = "f06975f46d8c7a1dad916e1e997584f77ae0c34a" +# 25.11.2023 https://gitlab.com/kelteseth/screenplay-vcpkg : +VCPKG_VERSION = "cd5e746ec203c8c3c61647e0886a8df8c1e78e41" VCPKG_BASE_PACKAGES = [ "curl", + "openssl", "cpp-httplib", "libarchive", "fmt", diff --git a/Tools/macos_make_universal.py b/Tools/macos_make_universal.py new file mode 100644 index 00000000..b3817a4a --- /dev/null +++ b/Tools/macos_make_universal.py @@ -0,0 +1,95 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only +from distutils.dir_util import mkpath +import os +import subprocess +from pathlib import Path +import util +from util import run, run_and_capture_output +from sys import stdout + +stdout.reconfigure(encoding='utf-8') + + +def listfiles(path): + files = [] + ignored = ('.DS_Store',) # Ignored files + print(f"WALK: {path}") + + for dirName, _, fileList in os.walk(path): + for fname in fileList: + if fname in ignored: + continue # Skip ignored files + + file_path = os.path.join(dirName, fname) + if os.path.isfile(file_path) and (fname.endswith('.a')): + files.append(file_path) + if os.path.islink(file_path): + print(f"Warning: file {file_path} is a symlink!") + print("Symlink target: ", os.readlink(file_path)) + return files + +def is_mach_o_binary(file_path): + """ + Check if a file is a Mach-O binary using the file command. + """ + try: + result = subprocess.run(["file", file_path], capture_output=True, text=True) + return 'Mach-O' in result.stdout + except Exception as e: + print(f"Error checking file type of {file_path}: {e}") + return False + +# Merges x64 and arm64 vcpkg build into universal +def run_lipo(): + workspace_path = util.workspace_path() + vcpkg_installed_path = str(Path(workspace_path).joinpath("vcpkg/installed/").absolute()) + arm64_dir = f"{vcpkg_installed_path}/arm64-osx" + x64_dir = f"{vcpkg_installed_path}/x64-osx" + universal_dir = f"{vcpkg_installed_path}/64-osx-universal" + # Ensure the universal directory is created and empty + run(f"rm -rf {universal_dir}", workspace_path) + # Copy the x64 build as a base for the universal build + run(f"cp -a {arm64_dir} {universal_dir}", workspace_path) + + files = listfiles(str(universal_dir)) + + for file in files: + # Extract the relative path for file + rel_path = os.path.relpath(file, universal_dir) + + # Construct the corresponding arm64 and x64 file paths + arm64_file = os.path.join(arm64_dir, rel_path) + x64_file = os.path.join(x64_dir, rel_path) + universal_file = file # file is already in universal_dir + + #and is_mach_o_binary(arm64_file) + if os.path.exists(x64_file) : + run(f"lipo -create {arm64_file} {x64_file} -output {universal_file}") + print(f"Processing binary file: {universal_file}") + run(f"lipo -info {universal_file}") + else: + print(f"Skipping non-binary file: {universal_file}") + +def check_fat_binary(): + # Ensure the script starts from the correct directory + workspace_path = Path(util.workspace_path()) + + dir = 'vcpkg/installed/64-osx-universal' + universal_dir = str(workspace_path.joinpath(dir)) + print(f"check_fat_binary {universal_dir}") + files = listfiles(universal_dir) + + for file in files: + out = run_and_capture_output(f"lipo -info {file}") + if out.startswith('Non-fat'): + out = out.replace("\n","") + print(f"❌ {out}") + else: + print(f"✅ {file}") +def execute(): + run_lipo() + check_fat_binary() + +if __name__ == "__main__": + execute() diff --git a/Tools/setup.py b/Tools/setup.py index ef3163e0..a21446bb 100755 --- a/Tools/setup.py +++ b/Tools/setup.py @@ -7,6 +7,7 @@ import download_ffmpeg import defines import argparse import util +import macos_make_universal import datetime import setup_godot from sys import stdout @@ -62,9 +63,7 @@ def download(aqt_path: Path, qt_platform: Path): # Tools can only be installed one at the time: # see: python -m aqt list-tool windows desktop - tools = ["tools_ifw", "tools_qtcreator", "tools_ninja", "tools_cmake"] - if system() == "Windows": - tools += ["tools_opensslv3_x64"] + tools = ["tools_ifw"] for tool in tools: execute( f"{defines.PYTHON_EXECUTABLE} -m aqt install-tool -O {aqt_path} {os} desktop {tool}") @@ -138,7 +137,7 @@ def main(): platform_command.add("chmod +x bootstrap-vcpkg.sh", vcpkg_path) platform_command.add("./bootstrap-vcpkg.sh", vcpkg_path, False) platform_command.add("chmod +x vcpkg", vcpkg_path) - vcpkg_triplet = ["64-osx-universal"] + vcpkg_triplet = ["x64-osx","arm64-osx"] elif system() == "Linux": vcpkg_command = "./vcpkg" # vcpkg_packages_list.append("infoware[opengl]") @@ -151,7 +150,7 @@ def main(): raise NotImplementedError("Unknown system: {}".format(system())) print(f"Clone into {vcpkg_path}") - execute("git clone https://gitlab.com/kelteseth/screenplay-vcpkg vcpkg", + execute("git clone https://github.com/microsoft/vcpkg vcpkg", project_source_parent_path, True) execute("git fetch", vcpkg_path) execute(f"git checkout {defines.VCPKG_VERSION}", vcpkg_path) @@ -165,9 +164,15 @@ def main(): vcpkg_packages = " ".join(vcpkg_packages_list) execute( f"{vcpkg_command} install {vcpkg_packages} --triplet {triplet} --recurse", vcpkg_path, False) + + # Combine x64 and arm + if system() == "Darwin": + macos_make_universal.execute() if not args.skip_aqt: setup_qt() + + if __name__ == "__main__": main()