Skip to content

Instantly share code, notes, and snippets.

@chromedays
Last active May 27, 2020 16:27
Show Gist options
  • Save chromedays/afd3d3415971762bfa5ea97675238cdf to your computer and use it in GitHub Desktop.
Save chromedays/afd3d3415971762bfa5ea97675238cdf to your computer and use it in GitHub Desktop.
Build TheForge framework
import urllib.request
from zipfile import ZipFile
import os
import subprocess
# Download archived TF repo
print('Downloading The Forge...')
url = 'https://github.com/ConfettiFX/The-Forge/archive/master.zip'
forge_zip_path = './forge.zip'
if not os.path.exists(forge_zip_path):
with urllib.request.urlopen(url) as input:
with open(forge_zip_path, 'wb') as output:
chunk_size = 1024
total_length = 576262 * 1024 # The size is about 576mb
prog_bar_length = 30
cut = total_length // prog_bar_length
dl = 0
progress = 0
while True:
data = input.read(chunk_size);
dl += len(data)
new_progress = dl // cut
if new_progress != progress:
progress = new_progress
print('.', end='', flush=True)
output.write(data)
if len(data) < chunk_size:
break
print('')
print('Done.')
forge_root = 'The-Forge-master'
# Extract the downloaded archive
print('Extracting The Forge...')
if not os.path.exists(forge_root):
with ZipFile(forge_zip_path, 'r') as zip:
zip.extractall()
print('Done.')
# NOTE: We don't execute PRE_BUILD because PRE_BUILD simply
# installs a visual studio extension and art assets.
# We don't need them for building The Forge.
# pre_build = f'.\{forge_root}\PRE_BUILD.bat'
# subprocess.call(pre_build)
# Find msbuild
proc = subprocess.Popen(['C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe', '-version', '[15.0,16.0)', '-requires' ,'Microsoft.Component.MSBuild', '-property', 'installationPath'], stdout=subprocess.PIPE,stderr = subprocess.STDOUT, encoding='utf8')
ls_output = proc.communicate()[0]
ls_output = ls_output.split('\n')[0]
msbuild_path = ls_output.strip() + '/MSBuild/15.0/Bin/MSBuild.exe'
project_root = './The-Forge-master/Examples_3/Unit_Tests/PC Visual Studio 2017/Libraries'
solution_dir = os.path.abspath('./The-Forge-master/Examples_3/Unit_Tests/PC Visual Studio 2017/')
solution_path = './The-Forge-master/Examples_3/Unit_Tests/PC Visual Studio 2017/Unit_Tests.sln'
msbuild_procs = []
def do_msbuild(project, configurations, platforms, use_project_root=True):
for configuration in configurations:
for platform in platforms:
print(f'Building {project}-{configuration}-{platform}...')
project_path = ''
if use_project_root:
project_path = f'{project_root}/{project}/{project}.vcxproj'
else:
project_path = project
output_dir = os.path.abspath(f'./output/{configuration}')
msbuild_command = [msbuild_path, project_path,
f'/p:SolutionDir={solution_dir}\\',
f'/p:Configuration={configuration}',
f'/p:Platform={platform}',
f'/p:OutDir={output_dir}\\',
'/p:BuildInParallel=true',
'/m:16', '/nr:false', '/nologo', '/verbosity:minimal',
'/clp:ErrorsOnly;WarningsOnly',
'/t:Rebuild']
msbuild_procs.append(subprocess.Popen(msbuild_command))
# Build library projects for all configurations and platforms
print('Building all projects. It will take a while.')
do_msbuild('RendererVulkan', ['DebugVk', 'ReleaseVk'], ['x64'])
do_msbuild('RendererDX12', ['DebugDx', 'ReleaseDx'], ['x64'])
do_msbuild('RendererDX11', ['DebugDx11', 'ReleaseDx11'], ['x64'])
do_msbuild('OS', ['DebugDx', 'ReleaseDx', 'DebugVk', 'ReleaseVk', 'DebugDx11', 'ReleaseDx11'], ['x64'])
do_msbuild('./The-Forge-master/Common_3/ThirdParty/OpenSource/gainput/Win64/lib/gainputstatic.vcxproj', ['DebugDx', 'ReleaseDx', 'DebugVk', 'ReleaseVk', 'DebugDx11', 'ReleaseDx11'], ['x64'], use_project_root=False)
for p in msbuild_procs:
p.wait()
print('Done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment