Improve native downloading spaghetti, use own Freetype on macOS

This commit is contained in:
Pieter-Jan Briers
2020-01-30 13:29:19 +01:00
parent 322ac488a1
commit 76933003ad
7 changed files with 178 additions and 242 deletions

View File

@@ -2,26 +2,11 @@
<PropertyGroup>
<RobustToolsPath>$(MSBuildThisFileDirectory)/../Tools/</RobustToolsPath>
</PropertyGroup>
<Target Name="CopySwnfd">
<CombinePath BasePath="$(RobustToolsPath)" Paths="download_swnfd.py">
<Target Name="CopyClientNatives">
<CombinePath BasePath="$(RobustToolsPath)" Paths="download_natives.py">
<Output TaskParameter="CombinedPaths" PropertyName="ScriptPath" />
</CombinePath>
<Exec Condition="'$(Platform)' == 'x64'" Command="$(Python) &quot;$(ScriptPath)&quot; $(Platform) $(TargetOS) $(OutputPath)" CustomErrorRegularExpression="^Error" />
<Warning Condition="'$(Platform)' != 'x64'" Text="Did not download swnfd because the platform is not set to x64. Only use this build for unit testing!" />
<Exec Command="$(Python) &quot;$(ScriptPath)&quot; $(Platform) $(TargetOS) Client $(OutputPath)" CustomErrorRegularExpression="^Error" />
</Target>
<Target Name="CopyGlfw">
<CombinePath BasePath="$(RobustToolsPath)" Paths="download_glfw.py">
<Output TaskParameter="CombinedPaths" PropertyName="ScriptPath" />
</CombinePath>
<Exec Condition="'$(Platform)' == 'x64'" Command="$(Python) &quot;$(ScriptPath)&quot; $(Platform) $(TargetOS) $(OutputPath)" CustomErrorRegularExpression="^Error" />
<Warning Condition="'$(Platform)' != 'x64'" Text="Did not download GLFW because the platform is not set to x64. Only use this build for unit testing!" />
</Target>
<Target Name="CopyMiscDependencies">
<CombinePath BasePath="$(RobustToolsPath)" Paths="download_misc_dependencies.py">
<Output TaskParameter="CombinedPaths" PropertyName="ScriptPath" />
</CombinePath>
<Exec Condition="'$(Platform)' == 'x64'" Command="$(Python) &quot;$(ScriptPath)&quot; $(Platform) $(TargetOS) $(OutputPath)" CustomErrorRegularExpression="^Error" />
<Warning Condition="'$(Platform)' != 'x64'" Text="Did not download misc dependencies because the platform is not set to x64. Only use this build for unit testing!" />
</Target>
<Target Name="ClientAfterBuild" DependsOnTargets="CopyMiscDependencies;CopySwnfd;CopyGlfw" />
<Target Name="ClientAfterBuild" DependsOnTargets="CopyClientNatives" />
</Project>

View File

@@ -27,7 +27,7 @@
<PackageReference Condition="'$(TargetFramework)' == 'net472'" Include="System.Memory" Version="4.5.3" />
<PackageReference Include="YamlDotNet" Version="8.1.0" />
<PackageReference Include="OpenTK" Version="3.1.0" />
<PackageReference Include="SpaceWizards.SharpFont" Version="1.0.0" />
<PackageReference Include="SpaceWizards.SharpFont" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lidgren.Network\Lidgren.Network.csproj" />

View File

@@ -34,5 +34,5 @@
<ProjectReference Include="..\Robust.Server\Robust.Server.csproj" />
</ItemGroup>
<Import Project="..\MSBuild\Robust.Engine.targets" />
<Target Name="RobustAfterBuild" DependsOnTargets="CopyMiscDependencies;CopySwnfd" AfterTargets="Build" />
<Target Name="RobustAfterBuild" DependsOnTargets="ClientAfterBuild" AfterTargets="Build" />
</Project>

View File

@@ -1,76 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import urllib.request
import shutil
CURRENT_VERSION = "3.3"
RELEASES_ROOT = "https://github.com/space-wizards/build-dependencies/raw/master/natives/glfw/3.3/"
WINDOWS_FILENAME = "glfw3.dll"
MACOS_FILENAME = "libglfw.3.dylib"
LINUX_FILENAME = "libglfw.so.3"
WINDOWS_TARGET_FILENAME = "glfw3.dll"
MACOS_TARGET_FILENAME = "libglfw.3.dylib"
LINUX_TARGET_FILENAME = "libglfw.so.3"
def main():
platform = sys.argv[1]
target_os = sys.argv[2]
# Hah good luck passing something containing a space to the Exec MSBuild Task.
target_dir = " ".join(sys.argv[3:])
if platform != "x64":
print("Error: Unable to download GLFW for any platform outside x64. "
"If you REALLY want x86 support for some misguided reason, I'm not providing it.")
exit(1)
repo_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
dependencies_dir = os.path.join(repo_dir, "Dependencies", "glfw")
version_file = os.path.join(dependencies_dir, "VERSION")
os.makedirs(dependencies_dir, exist_ok=True)
existing_version = "?"
if os.path.exists(version_file):
with open(version_file, "r") as f:
existing_version = f.read().strip()
if existing_version != CURRENT_VERSION:
for x in os.listdir(dependencies_dir):
os.remove(x)
with open(version_file, "w") as f:
f.write(CURRENT_VERSION)
filename = None
target_filename = None
if target_os == "Windows":
filename = WINDOWS_FILENAME
target_filename = WINDOWS_TARGET_FILENAME
elif target_os == "Linux":
filename = LINUX_FILENAME
target_filename = LINUX_TARGET_FILENAME
elif target_os == "MacOS":
filename = MACOS_FILENAME
target_filename = MACOS_TARGET_FILENAME
else:
print("Error: Unknown platform target:", target_os)
exit(2)
dependency_path = os.path.join(dependencies_dir, filename)
if not os.path.exists(dependency_path):
urllib.request.urlretrieve(RELEASES_ROOT + filename, dependency_path)
target_file_path = os.path.join(target_dir, target_filename)
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)
if __name__ == '__main__':
main()

View File

@@ -1,67 +0,0 @@
#!/usr/bin/env python3
# This script currently downloads freetyp6.dll and openal32.dll for Windows.
# macOS and Linux both provide those I'm pretty sure so we don't care.
# Well actually I think Linux might not be guaranteed to provide openAL but I don't care yet.
import os
import sys
import urllib.request
import shutil
FILES = [
("FREETYPE", "2", "freetype6.dll", "https://github.com/space-wizards/SharpFont.Dependencies/blob/b1baace7f6259f77162247291c970709650029c6/freetype2/2.10/msvc14/x64/freetype6.dll?raw=true"),
("OPENAL", "1", "openal32.dll", "https://github.com/opentk/opentk-dependencies/blob/9eb4991b871d2d2c0745d2c8c8c0fa6404f56438/x64/openal32.dll?raw=true")
]
def main():
platform = sys.argv[1]
target_os = sys.argv[2]
# Hah good luck passing something containing a space to the Exec MSBuild Task.
target_dir = " ".join(sys.argv[3:])
if platform != "x64":
print("Error: Unable to download misc deps for any platform outside x64. "
"If you REALLY want x86 support for some misguided reason, I'm not providing it.")
exit(1)
if target_os != "Windows":
exit(0)
repo_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
dependencies_dir = os.path.join(repo_dir, "Dependencies", "misc")
os.makedirs(dependencies_dir, exist_ok=True)
for n, v, f, c in FILES:
download_dependency(target_dir, dependencies_dir, n, v, f, c)
def download_dependency(target_dir, dependencies_dir, name, version, filename, currentURL):
version_file = os.path.join(dependencies_dir, name + "_VERSION")
existing_version = "?"
if os.path.exists(version_file):
with open(version_file, "r") as f:
existing_version = f.read().strip()
dependency_path = os.path.join(dependencies_dir, filename)
if existing_version != version and os.path.exists(dependency_path):
os.remove(dependency_path)
with open(version_file, "w") as f:
f.write(version)
if not os.path.exists(dependency_path):
urllib.request.urlretrieve(currentURL, dependency_path)
target_file_path = os.path.join(target_dir, filename)
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)
if __name__ == "__main__":
main()

172
Tools/download_natives.py Executable file
View File

@@ -0,0 +1,172 @@
#!/usr/bin/env python3
import os
import sys
import urllib.request
import shutil
import argparse
class NativeDependency:
def __init__(self):
self.name = None
self.version = None
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
class DepGlfw(NativeDependency):
def __init__(self):
super().__init__()
self.version = "3.3"
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(NativeDependency):
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(NativeDependency):
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(NativeDependency):
def __init__(self):
super().__init__()
self.version = "1"
self.name = "openal"
self.windows_target_filename = "openal32.dll"
self.windows_download_url = "https://github.com/opentk/opentk-dependencies/blob/" \
"9eb4991b871d2d2c0745d2c8c8c0fa6404f56438/x64/openal32.dll?raw=true"
NATIVES = [
DepGlfw(),
DepSwnfd(),
DepFreetype(),
DepOpenAL()
]
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
# 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
# Figure out download URL & target filename based on platform.
download_url = None
target_filename = None
if args.targetOS == "Windows":
download_url = dep.windows_download_url
target_filename = dep.windows_target_filename
elif args.targetOS == "Linux":
download_url = dep.linux_download_url
target_filename = dep.linux_target_filename
elif args.targetOS == "MacOS":
download_url = dep.macos_download_url
target_filename = dep.macos_target_filename
if download_url is None or target_filename is None:
# Skip if platform has no dependencies set.
continue
dep_dir = os.path.join(repo_dir, "Dependencies", dep.name)
# Check version of existing dependencies and update if necessary.
version_file = os.path.join(dep_dir, "VERSION")
os.makedirs(dep_dir, exist_ok=True)
existing_version = "?"
try:
with open(version_file, "r") as f:
existing_version = f.read().strip()
except FileNotFoundError:
pass
if existing_version != dep.version:
for x in os.listdir(dep_dir):
os.remove(x)
with open(version_file, "w") as f:
f.write(dep.version)
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(args.outputDir, 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)
if __name__ == "__main__":
main()

View File

@@ -1,78 +0,0 @@
#!/usr/bin/env python3
import os
import sys
import urllib.request
import shutil
CURRENT_VERSION = "robust_v0.1.0"
RELEASES_ROOT = "https://github.com/space-wizards/nativefiledialog/releases/download/" \
+ CURRENT_VERSION + "/"
WINDOWS_FILENAME = "swnfd.dll"
MACOS_FILENAME = "libswnfd.dylib"
LINUX_FILENAME = "libswnfd.so"
WINDOWS_TARGET_FILENAME = "swnfd.dll"
LINUX_TARGET_FILENAME = "libswnfd.so"
MACOS_TARGET_FILENAME = "libswnfd.dylib"
def main():
platform = sys.argv[1]
target_os = sys.argv[2]
# Hah good luck passing something containing a space to the Exec MSBuild Task.
target_dir = " ".join(sys.argv[3:])
if platform != "x64":
print("Error: Unable to download swnfd for any platform outside x64. "
"If you REALLY want x86 support for some misguided reason, I'm not providing it.")
exit(1)
repo_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
dependencies_dir = os.path.join(repo_dir, "Dependencies", "swnfd")
version_file = os.path.join(dependencies_dir, "VERSION")
os.makedirs(dependencies_dir, exist_ok=True)
existing_version = "?"
if os.path.exists(version_file):
with open(version_file, "r") as f:
existing_version = f.read().strip()
if existing_version != CURRENT_VERSION:
for x in os.listdir(dependencies_dir):
os.remove(x)
with open(version_file, "w") as f:
f.write(CURRENT_VERSION)
filename = None
target_filename = None
if target_os == "Windows":
filename = WINDOWS_FILENAME
target_filename = WINDOWS_TARGET_FILENAME
elif target_os == "Linux":
filename = LINUX_FILENAME
target_filename = LINUX_TARGET_FILENAME
elif target_os == "MacOS":
filename = MACOS_FILENAME
target_filename = MACOS_TARGET_FILENAME
else:
print("Error: Unknown platform target:", target_os)
exit(2)
dependency_path = os.path.join(dependencies_dir, filename)
if not os.path.exists(dependency_path):
urllib.request.urlretrieve(RELEASES_ROOT + filename, dependency_path)
target_file_path = os.path.join(target_dir, target_filename)
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)
if __name__ == '__main__':
main()