From fd4f45e670de41eb789c69acb6889af0de9465ba Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Sun, 13 Dec 2020 00:46:23 +0100 Subject: [PATCH] Use NuGet packages for engine natives. Fixes #1434 This means that adding support for new architectures (e.g. ARM) is MUCH easier. It removes download_natives.py which simplifies the build process. It's also way less painful to maintain. --- MSBuild/Robust.Engine.targets | 10 - Robust.Client/Robust.Client.csproj | 11 +- Robust.UnitTesting/Robust.UnitTesting.csproj | 1 - Tools/download_natives.py | 304 ------------------- Tools/package_client_build.py | 5 +- 5 files changed, 7 insertions(+), 324 deletions(-) delete mode 100755 Tools/download_natives.py diff --git a/MSBuild/Robust.Engine.targets b/MSBuild/Robust.Engine.targets index 881ba33dac..a64fc74c71 100644 --- a/MSBuild/Robust.Engine.targets +++ b/MSBuild/Robust.Engine.targets @@ -1,12 +1,2 @@ - - $(MSBuildThisFileDirectory)/../Tools/ - - - - - - - - diff --git a/Robust.Client/Robust.Client.csproj b/Robust.Client/Robust.Client.csproj index f1295d9a60..93eaee73a8 100644 --- a/Robust.Client/Robust.Client.csproj +++ b/Robust.Client/Robust.Client.csproj @@ -21,6 +21,12 @@ + + @@ -44,9 +50,4 @@ - - - ../Tools - - diff --git a/Robust.UnitTesting/Robust.UnitTesting.csproj b/Robust.UnitTesting/Robust.UnitTesting.csproj index ab36e38122..6aaa86f109 100644 --- a/Robust.UnitTesting/Robust.UnitTesting.csproj +++ b/Robust.UnitTesting/Robust.UnitTesting.csproj @@ -36,5 +36,4 @@ - diff --git a/Tools/download_natives.py b/Tools/download_natives.py deleted file mode 100755 index 1106e87c43..0000000000 --- a/Tools/download_natives.py +++ /dev/null @@ -1,304 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os -import shutil -import urllib.request - -from typing import List - -OS_WINDOWS = "Windows" -OS_LINUX = "Linux" -OS_MACOS = "MacOS" - -# BIG NOTE: -# If you add natives here, make SURE to edit package_release_build.py in content, -# so that the native gets copied there too. - - -class NativeDependency: - def __init__(self): - self.name = None - self.version = None - - def run(self, dep_dir: str, targetOS: str, output_dir: str): - pass - - def check_version(self, dep_dir: str) -> bool: - version_file = os.path.join(dep_dir, "VERSION") - os.makedirs(dep_dir, exist_ok=True) - - existing_version = None - try: - with open(version_file, "r") as f: - existing_version = f.read().strip() - except FileNotFoundError: - pass - - if existing_version != self.version: - for x in os.listdir(dep_dir): - r = os.path.join(dep_dir, x) - if os.path.isdir(r): - shutil.rmtree(r) - else: - os.remove(r) - - with open(version_file, "w") as f: - f.write(self.version) - - return True - - return False - - -class SimpleDependency(NativeDependency): - def __init__(self): - super().__init__() - - self.windows_target_filename = None - self.linux_target_filename = None - self.macos_target_filename = None - - self.windows_download_url = None - self.linux_download_url = None - self.macos_download_url = None - - def run(self, dep_dir: str, targetOS: str, output_dir: str): - # Figure out download URL & target filename based on platform. - download_url = None - target_filename = None - - if targetOS == OS_WINDOWS: - download_url = self.windows_download_url - target_filename = self.windows_target_filename - - elif targetOS == OS_LINUX: - download_url = self.linux_download_url - target_filename = self.linux_target_filename - - elif targetOS == OS_MACOS: - download_url = self.macos_download_url - target_filename = self.macos_target_filename - - if download_url is None or target_filename is None: - # Skip if platform has no dependencies set. - return - - # Check version of existing dependencies and update if necessary. - self.check_version(dep_dir) - - dependency_path = os.path.join(dep_dir, target_filename) - # Download if necessary. - if not os.path.exists(dependency_path): - urllib.request.urlretrieve(download_url, dependency_path) - - target_file_path = os.path.join(output_dir, target_filename) - - # Copy if necessary. - if not os.path.exists(target_file_path) or \ - os.stat(dependency_path).st_mtime > os.stat(target_file_path).st_mtime: - shutil.copy2(dependency_path, target_file_path) - - -class DepGlfw(SimpleDependency): - def __init__(self): - super().__init__() - - self.version = "3.3.2" - self.name = "glfw" - - base_url = "https://github.com/space-wizards/build-dependencies" \ - f"/raw/master/natives/glfw/{self.version}/{{0}}" - - self.windows_target_filename = "glfw3.dll" - self.macos_target_filename = "libglfw.3.dylib" - self.linux_target_filename = "libglfw.so.3" - - self.windows_download_url = str.format(base_url, self.windows_target_filename) - self.macos_download_url = str.format(base_url, self.macos_target_filename) - self.linux_download_url = str.format(base_url, self.linux_target_filename) - - -class DepSwnfd(SimpleDependency): - def __init__(self): - super().__init__() - - self.version = "robust_v0.1.0" - self.name = "swnfd" - - base_url = "https://github.com/space-wizards/nativefiledialog/releases/download/" \ - f"{self.version}/{{0}}" - - self.windows_target_filename = "swnfd.dll" - self.macos_target_filename = "libswnfd.dylib" - self.linux_target_filename = "libswnfd.so" - - self.windows_download_url = str.format(base_url, self.windows_target_filename) - self.macos_download_url = str.format(base_url, self.macos_target_filename) - self.linux_download_url = str.format(base_url, self.linux_target_filename) - - -class DepFreetype(SimpleDependency): - def __init__(self): - super().__init__() - - self.version = "2.10.1" - self.name = "freetype" - - self.windows_target_filename = "freetype6.dll" - self.macos_target_filename = "libfreetype.6.dylib" - - self.windows_download_url = "https://github.com/space-wizards/SharpFont.Dependencies/" \ - "blob/b1baace7f6259f77162247291c970709650029c6/freetype2/2.10/" \ - "msvc14/x64/freetype6.dll?raw=true" - self.macos_download_url = "https://github.com/space-wizards/build-dependencies/raw/" \ - "master/natives/freetype/2.10.1/libfreetype.6.dylib" - - -class DepOpenAL(SimpleDependency): - def __init__(self): - super().__init__() - - self.version = "1.20.1" - self.name = "openal" - - self.windows_target_filename = "openal32.dll" - self.linux_target_filename = "libopenal.so.1" - - base_url = "https://github.com/space-wizards/build-dependencies" \ - f"/raw/master/natives/openal/{self.version}/{{0}}" - - self.windows_download_url = str.format(base_url, self.windows_target_filename) - self.linux_download_url = str.format(base_url, "libopenal.so") - - -class DepFluidsynth(NativeDependency): - BASE_URL = "https://github.com/space-wizards/build-dependencies/blob/ccf2cf448883dd9b2d999ff9fb5c4533229231bd" \ - "/natives/fluidsynth/2.1.0/" - - FILES = [ - "fluidsynth.dll", - "libglib-2.0-0.dll", - "libgobject-2.0-0.dll", - "libgthread-2.0-0.dll", - "libinstpatch-2.dll", - "libintl-8.dll", - "libsndfile-1.dll" - ] - - def __init__(self): - super().__init__() - - self.name = "fluidsynth" - self.version = "6aea18bef458595e9580e8bc7612aff439001303" - - def run(self, dep_dir: str, targetOS: str, output_dir: str): - if targetOS != OS_WINDOWS: - return - - #print("FLUIDSYNTH FOR WINDOWS") - os_dep_dir = os.path.join(dep_dir, targetOS) - - if self.check_version(dep_dir): - #print("MUST UPDATE") - os.makedirs(os_dep_dir, exist_ok=True) - # Download new version - - for filename in DepFluidsynth.FILES: - url = DepFluidsynth.BASE_URL + filename + "?raw=true" - urllib.request.urlretrieve(url, os.path.join(os_dep_dir, filename)) - - #print("COPYING") - for file in os.listdir(os_dep_dir): - source_file_path = os.path.join(os_dep_dir, file) - target_file_path = os.path.join(output_dir, file) - - #print(file, source_file_path, target_file_path) - - if not os.path.exists(target_file_path) or \ - os.stat(source_file_path).st_mtime > os.stat(target_file_path).st_mtime: - #print("COPY") - shutil.copy2(source_file_path, target_file_path) - -class DepAngle(NativeDependency): - BASE_URL = "https://github.com/space-wizards/build-dependencies/blob/master/natives/ANGLE/2020-05-15-1/" - - FILES = [ - "libGLESv2.dll", - "libEGL.dll" - ] - - def __init__(self): - super().__init__() - - self.name = "ANGLE" - self.version = "2020-05-15-1-fix" - - def run(self, dep_dir: str, targetOS: str, output_dir: str): - if targetOS != OS_WINDOWS: - return - - print("ANGLE FOR WINDOWS") - os_dep_dir = os.path.join(dep_dir, targetOS) - - if self.check_version(dep_dir): - os.makedirs(os_dep_dir, exist_ok=True) - # Download new version - - for filename in DepAngle.FILES: - url = DepAngle.BASE_URL + filename + "?raw=true" - urllib.request.urlretrieve(url, os.path.join(os_dep_dir, filename)) - - #print("COPYING") - for file in os.listdir(os_dep_dir): - source_file_path = os.path.join(os_dep_dir, file) - target_file_path = os.path.join(output_dir, file) - - #print(file, source_file_path, target_file_path) - - if not os.path.exists(target_file_path) or \ - os.stat(source_file_path).st_mtime > os.stat(target_file_path).st_mtime: - #print("COPY") - shutil.copy2(source_file_path, target_file_path) - - -NATIVES: List[SimpleDependency] = [ - DepGlfw(), - DepSwnfd(), - DepFreetype(), - DepOpenAL(), - DepFluidsynth(), - DepAngle() -] - - -def main(): - parser = argparse.ArgumentParser() - - parser.add_argument("platform") - parser.add_argument("targetOS") - parser.add_argument("natives") # Ignored for now, since only client needs natives. - parser.add_argument("outputDir") - - args = parser.parse_args() - - #if args.platform != "x64": - # return - - print("Copying dependencies") - print(args.targetOS, args.outputDir) - - # Path to the RobustToolbox repo. - repo_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - - for dep in NATIVES: - assert dep.version is not None - assert dep.name is not None - - dep_dir = os.path.join(repo_dir, "Dependencies", dep.name) - - dep.run(dep_dir, args.targetOS, args.outputDir) - - -if __name__ == "__main__": - main() diff --git a/Tools/package_client_build.py b/Tools/package_client_build.py index cad865675b..ef2bf878dc 100755 --- a/Tools/package_client_build.py +++ b/Tools/package_client_build.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python3 # Packages a full release build of the client that can be unzipped and you'll have your client engine redistributable. import os @@ -100,7 +100,6 @@ def build_windows(skip_build: bool) -> None: if not skip_build: publish_client("win-x64", "Windows") - subprocess.run(["Tools/download_natives.py", "x64", "Windows", "_", p("bin", "Client", "win-x64")]) if sys.platform != "win32": subprocess.run(["Tools/exe_set_subsystem.py", p("bin", "Client", "win-x64", "publish", "Robust.Client"), "2"]) @@ -121,7 +120,6 @@ def build_macos(skip_build: bool) -> None: if not skip_build: publish_client("osx-x64", "MacOS") - subprocess.run(["Tools/download_natives.py", "x64", "MacOS", "_", p("bin", "Client", "osx-x64")]) print(Fore.GREEN + "Packaging macOS x64 client..." + Style.RESET_ALL) # Client has to go in an app bundle. @@ -141,7 +139,6 @@ def build_linux(skip_build: bool) -> None: if not skip_build: publish_client("linux-x64", "Linux") - subprocess.run(["Tools/download_natives.py", "x64", "Linux", "_", p("bin", "Client", "linux-x64")]) print(Fore.GREEN + "Packaging Linux x64 client..." + Style.RESET_ALL)