Add Windows stuff (untested)

This commit is contained in:
Ben Visness 2023-07-08 17:21:01 -05:00
parent fbba6330e9
commit 92529ba7c1
4 changed files with 131 additions and 44 deletions

View File

@ -1,4 +1,5 @@
import argparse import argparse
from datetime import datetime
import glob import glob
import os import os
import platform import platform
@ -36,7 +37,9 @@ def build_milepost(target, release):
os.makedirs("resources", exist_ok=True) os.makedirs("resources", exist_ok=True)
if target == "lib": if target == "lib":
if platform.system() == "Darwin": if platform.system() == "Windows":
build_milepost_lib_win(release)
elif platform.system() == "Darwin":
build_milepost_lib_mac(release) build_milepost_lib_mac(release)
else: else:
log_error(f"can't build milepost for unknown platform '{platform.system()}'") log_error(f"can't build milepost for unknown platform '{platform.system()}'")
@ -52,6 +55,60 @@ def build_milepost(target, release):
exit(1) exit(1)
def build_milepost_lib_win(release):
# TODO(ben): delete embed_text.py
embed_text_glsl("src\\glsl_shaders.h", "glsl_", [
"src\\glsl_shaders\\common.glsl",
"src\\glsl_shaders\\blit_vertex.glsl",
"src\\glsl_shaders\\blit_fragment.glsl",
"src\\glsl_shaders\\path_setup.glsl",
"src\\glsl_shaders\\segment_setup.glsl",
"src\\glsl_shaders\\backprop.glsl",
"src\\glsl_shaders\\merge.glsl",
"src\\glsl_shaders\\raster.glsl",
])
includes = [
"/I", "src",
"/I", "src/util",
"/I", "src/platform",
"/I", "ext",
"/I", "ext/angle_headers",
]
libs = [
"user32.lib",
"opengl32.lib",
"gdi32.lib",
"shcore.lib",
"delayimp.lib",
"dwmapi.lib",
"comctl32.lib",
"ole32.lib",
"shell32.lib",
"shlwapi.lib",
"/LIBPATH:./bin",
"libEGL.dll.lib",
"libGLESv2.dll.lib",
"/DELAYLOAD:libEGL.dll",
"/DELAYLOAD:libGLESv2.dll",
]
# TODO(ben): check for cl
subprocess.run([
"cl",
"/we4013", "/Zi", "/Zc:preprocessor",
"/DMP_BUILD_DLL",
"/std:c11",
*includes,
"src/milepost.c", "/Fo:bin/milepost.o",
"/LD", "/link",
"/MANIFEST:EMBED", "/MANIFESTINPUT:src/win32_manifest.xml",
*libs,
"/OUT:bin/milepost.dll",
"/IMPLIB:bin/milepost.dll.lib",
], check=True)
def build_milepost_lib_mac(release): def build_milepost_lib_mac(release):
sdk_dir = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk" sdk_dir = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
@ -145,20 +202,16 @@ def ensure_angle():
checkfiles = None checkfiles = None
if platform.system() == "Windows": if platform.system() == "Windows":
checkfiles = [ checkfiles = [
["libEGL-win", "milepost/lib/libEGL.dll"], "milepost/lib/libEGL.dll",
["libGLESv2-win", "milepost/lib/libGLESv2.dll"], "milepost/lib/libGLESv2.dll",
] ]
elif platform.system() == "Darwin": elif platform.system() == "Darwin":
# TODO(ben): Do we need specific builds of ANGLE for each macOS version?
if platform.machine() == "arm64": if platform.machine() == "arm64":
log_warning(f"automated ANGLE builds are not yet available for Apple silicon")
return
checkfiles = [ checkfiles = [
["libEGL-mac-arm64", "milepost/lib/libEGL.dylib"], "milepost/lib/libEGL.dylib",
["libGLESv2-mac-arm64", "milepost/lib/libGLESv2.dylib"], "milepost/lib/libGLESv2.dylib",
]
else:
checkfiles = [
["libEGL-mac-x64", "milepost/lib/libEGL.dylib"],
["libGLESv2-mac-x64", "milepost/lib/libGLESv2.dylib"],
] ]
if checkfiles is None: if checkfiles is None:
@ -173,8 +226,9 @@ def ensure_angle():
angle_exists = False angle_exists = False
break break
if not checksum.checkfile(key, filepath): if not checksum.checkfile(key, filepath):
log_error("wrong version of ANGLE libraries installed") angle_exists = False
exit(1) log_warning("wrong version of ANGLE libraries installed")
break
if not angle_exists: if not angle_exists:
download_angle() download_angle()
@ -184,33 +238,65 @@ def download_angle():
print("Downloading ANGLE...") print("Downloading ANGLE...")
if platform.system() == "Windows": if platform.system() == "Windows":
build = "win" build = "win"
checksumkey = "angle.zip-win"
extension = "dll" extension = "dll"
elif platform.system() == "Darwin": elif platform.system() == "Darwin":
extension = "dylib"
build = "macos-12"
checksumkey = "angle.zip-mac"
# TODO(ben): make universal dylibs # TODO(ben): make universal dylibs
if platform.machine() == "arm64": build = "macos-12"
log_error(f"automated ANGLE builds are not yet available for Apple silicon") extension = "dylib"
return
else: else:
log_error(f"could not automatically download ANGLE for unknown platform {platform.system()}") log_error(f"could not automatically download ANGLE for unknown platform {platform.system()}")
return return
url = f"https://github.com/HandmadeNetwork/build-angle/releases/download/{ANGLE_VERSION}/angle-{build}-{ANGLE_VERSION}.zip"
with urllib.request.urlopen(url) as response:
os.makedirs("scripts/files", exist_ok=True) os.makedirs("scripts/files", exist_ok=True)
with open("scripts/files/angle.zip", "wb") as out: filename = f"angle-{build}-{ANGLE_VERSION}.zip"
filepath = f"scripts/files/{filename}"
url = f"https://github.com/HandmadeNetwork/build-angle/releases/download/{ANGLE_VERSION}/{filename}"
with urllib.request.urlopen(url) as response:
with open(filepath, "wb") as out:
shutil.copyfileobj(response, out) shutil.copyfileobj(response, out)
if not checksum.checkfile(checksumkey, "scripts/files/angle.zip"): if not checksum.checkfile(filepath):
log_error(f"ANGLE download did not match checksum") log_error(f"ANGLE download did not match checksum")
exit(1) exit(1)
with ZipFile("scripts/files/angle.zip", "r") as anglezip: with ZipFile(filepath, "r") as anglezip:
anglezip.extractall(path="scripts/files") anglezip.extractall(path="scripts/files")
for filepath in glob.glob(f"scripts/files/angle/bin/*.{extension}"): for filepath in glob.glob(f"scripts/files/angle/bin/*.{extension}"):
shutil.copy(filepath, "milepost/lib") shutil.copy(filepath, "milepost/lib")
def embed_text_glsl(outputpath, prefix, shaders):
output = open(outputpath, "w")
output.write("/*********************************************************************\n")
output.write("*\n")
output.write("*\tfile: %s\n" % os.path.basename(outputpath))
output.write("*\tnote: string literals auto-generated by build_runtime.py\n")
output.write("*\tdate: %s\n" % datetime.now().strftime("%d/%m%Y"))
output.write("*\n")
output.write("**********************************************************************/\n")
outSymbol = (os.path.splitext(os.path.basename(outputpath))[0]).upper()
output.write("#ifndef __%s_H__\n" % outSymbol)
output.write("#define __%s_H__\n" % outSymbol)
output.write("\n\n")
for fileName in shaders:
f = open(fileName, "r")
lines = f.read().splitlines()
output.write("//NOTE: string imported from %s\n" % fileName)
stringName = os.path.splitext(os.path.basename(fileName))[0]
output.write(f"const char* {prefix}{stringName} = ")
for line in lines:
output.write("\n\"%s\\n\"" % line)
output.write(";\n\n")
f.close()
output.write("#endif // __%s_H__\n" % outSymbol)
output.close()

View File

@ -4,17 +4,17 @@ import json
from log import * from log import *
def checkfile(key, filepath): def checkfile(filepath):
newsum = filesum(filepath) newsum = filesum(filepath)
sums = {} sums = {}
with open("scripts/checksums.json", "r") as sumsfile: with open("scripts/checksums.json", "r") as sumsfile:
sums = json.loads(sumsfile.read()) sums = json.loads(sumsfile.read())
if key not in sums: if filepath not in sums:
msg = log_warning(f"no checksum saved for {key}") msg = log_warning(f"no checksum saved for file {filepath}")
msg.more(f"file had checksum: {newsum}") msg.more(f"file had checksum: {newsum}")
return False return False
sum = sums[key] sum = sums[filepath]
if sum != newsum: if sum != newsum:
msg = log_warning(f"checksums did not match for {filepath}:") msg = log_warning(f"checksums did not match for {filepath}:")

View File

@ -1,8 +1,8 @@
{ {
"angle.zip-win": "pizza", "scripts/files/angle-win-2023-07-05": "pizza",
"angle.zip-mac-x64": "a3422c456278ff037ef89a7808e0ba256d972d4832d5272fc3d4aa4f7912c1e0", "scripts/files/angle-mac-2023-07-05": "a3422c456278ff037ef89a7808e0ba256d972d4832d5272fc3d4aa4f7912c1e0",
"libEGL-win": "3c8b22317664650deba704dd40bbd56447c579ee3a3de18a9c114449a883a36d", "milepost/lib/libEGL.dll": "3c8b22317664650deba704dd40bbd56447c579ee3a3de18a9c114449a883a36d",
"libGLESv2-win": "a10e0ce850a981b11d3d0f01a7efbf8ce46ac74e5fa763b5c43a80c4238da389", "milepost/lib/libGLESv2.dll": "a10e0ce850a981b11d3d0f01a7efbf8ce46ac74e5fa763b5c43a80c4238da389",
"libEGL-mac": "227445d896047207d1dcef91a8182d886692bc470f402033a6f0831eacb82592", "milepost/lib/libEGL.dylib": "227445d896047207d1dcef91a8182d886692bc470f402033a6f0831eacb82592",
"libGLESv2-mac": "c814948060494796cda4a3febd8652e1bbf0787a69c2f7e9afd41fc666dc91fe" "milepost/lib/libGLESv2.dylib": "c814948060494796cda4a3febd8652e1bbf0787a69c2f7e9afd41fc666dc91fe"
} }

View File

@ -34,28 +34,29 @@ def log_warning(msg):
return entry return entry
def log_finish(): def log_finish(success):
if len(errors) + len(warnings) == 0: if success and len(errors) + len(warnings) == 0:
print("Task completed successfully.") print("Task completed successfully.")
return return
print() print()
result_str = "succeeded" if success else "failed"
errors_str = "1 error" if len(errors) == 1 else f"{len(errors)} errors" errors_str = "1 error" if len(errors) == 1 else f"{len(errors)} errors"
warnings_str = "1 warning" if len(warnings) == 1 else f"{len(warnings)} warnings" warnings_str = "1 warning" if len(warnings) == 1 else f"{len(warnings)} warnings"
if len(errors) > 0 and len(warnings) > 0: if len(errors) > 0 and len(warnings) > 0:
print(f"Task failed with {errors_str} and {warnings_str}:") print(f"Task {result_str} with {errors_str} and {warnings_str}:")
for entry in warnings: for entry in warnings:
print("\n".join(entry.msgs)) print("\n".join(entry.msgs))
for entry in errors: for entry in errors:
print("\n".join(entry.msgs)) print("\n".join(entry.msgs))
elif len(errors) > 0: elif len(errors) > 0:
print(f"Task failed with {errors_str}:") print(f"Task {result_str} with {errors_str}:")
for entry in errors: for entry in errors:
print("\n".join(entry.msgs)) print("\n".join(entry.msgs))
elif len(warnings) > 0: elif len(warnings) > 0:
print(f"Task failed with {warnings_str}:") print(f"Task {result_str} with {warnings_str}:")
for entry in warnings: for entry in warnings:
print("\n".join(entry.msgs)) print("\n".join(entry.msgs))
@ -75,6 +76,6 @@ def shellish(func):
log_error(sys.exception()) log_error(sys.exception())
exitcode = 1 exitcode = 1
finally: finally:
log_finish() log_finish(exitcode == 0)
exit(exitcode) exit(exitcode)
return shellfunc return shellfunc