2023-07-07 16:25:49 +00:00
|
|
|
import argparse
|
2023-07-08 22:21:01 +00:00
|
|
|
from datetime import datetime
|
2023-07-08 14:22:29 +00:00
|
|
|
import glob
|
2023-07-07 16:25:49 +00:00
|
|
|
import os
|
|
|
|
import platform
|
2023-07-08 14:22:29 +00:00
|
|
|
import urllib.request
|
|
|
|
import shutil
|
2023-07-07 16:25:49 +00:00
|
|
|
import subprocess
|
2023-07-08 14:22:29 +00:00
|
|
|
from zipfile import ZipFile
|
2023-07-07 16:25:49 +00:00
|
|
|
|
2023-07-07 23:22:13 +00:00
|
|
|
import checksum
|
2023-07-19 23:35:07 +00:00
|
|
|
from bindgen import bindgen
|
|
|
|
from bindgen2 import bindgen2
|
2023-07-07 23:22:13 +00:00
|
|
|
from log import *
|
|
|
|
from utils import pushd, removeall
|
|
|
|
|
|
|
|
|
2023-07-16 00:00:34 +00:00
|
|
|
ANGLE_VERSION = "2023-07-05"
|
2023-07-07 16:25:49 +00:00
|
|
|
|
|
|
|
|
2023-07-29 19:03:44 +00:00
|
|
|
def attach_dev_commands(subparsers):
|
|
|
|
dev_cmd = subparsers.add_parser("dev", help="Commands for building Orca itself. Must be run from the root of an Orca source checkout.")
|
2023-07-27 02:28:39 +00:00
|
|
|
|
2023-07-29 19:03:44 +00:00
|
|
|
try:
|
|
|
|
os.stat(".orcaroot")
|
|
|
|
except FileNotFoundError:
|
|
|
|
dev_cmd.set_defaults(func=orca_root_only)
|
|
|
|
return
|
|
|
|
|
|
|
|
dev_sub = dev_cmd.add_subparsers(required=True, title='commands')
|
|
|
|
|
|
|
|
build_cmd = dev_sub.add_parser("build-runtime", help="Build the Orca runtime from source.")
|
2023-07-23 17:01:06 +00:00
|
|
|
build_cmd.add_argument("--release", action="store_true", help="compile Orca in release mode (default is debug)")
|
|
|
|
build_cmd.set_defaults(func=shellish(build_runtime))
|
|
|
|
|
2023-07-29 19:03:44 +00:00
|
|
|
clean_cmd = dev_sub.add_parser("clean", help="Delete all build artifacts and start fresh.")
|
2023-07-23 17:01:06 +00:00
|
|
|
clean_cmd.set_defaults(func=shellish(clean))
|
2023-07-07 16:25:49 +00:00
|
|
|
|
|
|
|
|
2023-07-29 19:03:44 +00:00
|
|
|
def orca_root_only(args):
|
|
|
|
print("The Orca dev commands can only be run from an Orca source checkout.")
|
|
|
|
print()
|
|
|
|
print("If you want to build Orca yourself, download the source here:")
|
|
|
|
print("https://git.handmade.network/hmn/orca")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
2023-07-07 16:25:49 +00:00
|
|
|
def build_runtime(args):
|
2023-07-07 23:22:13 +00:00
|
|
|
ensure_programs()
|
|
|
|
ensure_angle()
|
2023-07-07 16:25:49 +00:00
|
|
|
|
|
|
|
build_milepost("lib", args.release)
|
2023-07-19 23:14:27 +00:00
|
|
|
build_wasm3(args.release)
|
2023-07-19 23:35:07 +00:00
|
|
|
build_orca(args.release)
|
2023-07-07 16:25:49 +00:00
|
|
|
|
2023-07-07 23:22:13 +00:00
|
|
|
|
2023-07-23 17:01:06 +00:00
|
|
|
def clean(args):
|
|
|
|
def yeet(path):
|
|
|
|
os.makedirs(path, exist_ok=True)
|
|
|
|
shutil.rmtree(path)
|
|
|
|
yeet("build")
|
|
|
|
yeet("milepost/build")
|
|
|
|
yeet("scripts/files")
|
|
|
|
yeet("scripts/__pycache__")
|
|
|
|
|
|
|
|
|
2023-07-07 16:25:49 +00:00
|
|
|
def build_milepost(target, release):
|
|
|
|
print("Building milepost...")
|
|
|
|
with pushd("milepost"):
|
2023-07-23 17:01:06 +00:00
|
|
|
os.makedirs("build/bin", exist_ok=True)
|
|
|
|
os.makedirs("build/lib", exist_ok=True)
|
2023-07-07 16:25:49 +00:00
|
|
|
os.makedirs("resources", exist_ok=True)
|
|
|
|
|
|
|
|
if target == "lib":
|
2023-07-08 22:21:01 +00:00
|
|
|
if platform.system() == "Windows":
|
|
|
|
build_milepost_lib_win(release)
|
|
|
|
elif platform.system() == "Darwin":
|
2023-07-07 16:25:49 +00:00
|
|
|
build_milepost_lib_mac(release)
|
|
|
|
else:
|
2023-07-07 23:22:13 +00:00
|
|
|
log_error(f"can't build milepost for unknown platform '{platform.system()}'")
|
|
|
|
exit(1)
|
2023-07-07 16:25:49 +00:00
|
|
|
elif target == "test":
|
|
|
|
with pushd("examples/test_app"):
|
|
|
|
# TODO?
|
|
|
|
subprocess.run(["./build.sh"])
|
|
|
|
elif target == "clean":
|
|
|
|
removeall("bin")
|
|
|
|
else:
|
2023-07-07 23:22:13 +00:00
|
|
|
log_error(f"unrecognized milepost target '{target}'")
|
2023-07-07 16:25:49 +00:00
|
|
|
exit(1)
|
|
|
|
|
2023-07-07 23:22:13 +00:00
|
|
|
|
2023-07-08 22:21:01 +00:00
|
|
|
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",
|
|
|
|
]
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
2023-07-07 16:25:49 +00:00
|
|
|
def build_milepost_lib_mac(release):
|
|
|
|
sdk_dir = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
|
|
|
|
|
|
|
|
flags = ["-mmacos-version-min=10.15.4", "-maes"]
|
|
|
|
cflags = ["-std=c11"]
|
|
|
|
debug_flags = ["-O3"] if release else ["-g", "-DDEBUG", "-DLOG_COMPILE_DEBUG"]
|
|
|
|
ldflags = [f"-L{sdk_dir}/usr/lib", f"-F{sdk_dir}/System/Library/Frameworks/"]
|
|
|
|
includes = ["-Isrc", "-Isrc/util", "-Isrc/platform", "-Iext", "-Iext/angle_headers"]
|
|
|
|
|
|
|
|
# compile metal shader
|
|
|
|
subprocess.run([
|
|
|
|
"xcrun", "-sdk", "macosx", "metal",
|
|
|
|
# TODO: shaderFlagParam
|
|
|
|
"-fno-fast-math", "-c",
|
2023-07-23 17:01:06 +00:00
|
|
|
"-o", "build/mtl_renderer.air",
|
2023-07-07 16:25:49 +00:00
|
|
|
"src/mtl_renderer.metal",
|
|
|
|
], check=True)
|
|
|
|
subprocess.run([
|
|
|
|
"xcrun", "-sdk", "macosx", "metallib",
|
2023-07-23 17:01:06 +00:00
|
|
|
"-o", "build/bin/mtl_renderer.metallib",
|
|
|
|
"build/mtl_renderer.air",
|
2023-07-07 16:25:49 +00:00
|
|
|
], check=True)
|
|
|
|
|
|
|
|
# compile milepost. We use one compilation unit for all C code, and one
|
|
|
|
# compilation unit for all Objective-C code
|
|
|
|
subprocess.run([
|
|
|
|
"clang",
|
|
|
|
*debug_flags, "-c",
|
2023-07-23 17:01:06 +00:00
|
|
|
"-o", "build/milepost_c.o",
|
2023-07-07 16:25:49 +00:00
|
|
|
*cflags, *flags, *includes,
|
|
|
|
"src/milepost.c"
|
|
|
|
], check=True)
|
|
|
|
subprocess.run([
|
|
|
|
"clang",
|
|
|
|
*debug_flags, "-c",
|
2023-07-23 17:01:06 +00:00
|
|
|
"-o", "build/milepost_objc.o",
|
2023-07-07 16:25:49 +00:00
|
|
|
*flags, *includes,
|
|
|
|
"src/milepost.m"
|
|
|
|
], check=True)
|
|
|
|
|
|
|
|
# build dynamic library
|
|
|
|
subprocess.run([
|
|
|
|
"ld",
|
|
|
|
*ldflags, "-dylib",
|
2023-07-23 17:01:06 +00:00
|
|
|
"-o", "build/bin/libmilepost.dylib",
|
|
|
|
"build/milepost_c.o", "build/milepost_objc.o",
|
|
|
|
"-Lbuild/bin", "-lc",
|
2023-07-07 16:25:49 +00:00
|
|
|
"-framework", "Carbon", "-framework", "Cocoa", "-framework", "Metal", "-framework", "QuartzCore",
|
|
|
|
"-weak-lEGL", "-weak-lGLESv2",
|
|
|
|
], check=True)
|
|
|
|
|
|
|
|
# change dependent libs path to @rpath
|
|
|
|
subprocess.run([
|
|
|
|
"install_name_tool",
|
|
|
|
"-change", "./libEGL.dylib", "@rpath/libEGL.dylib",
|
2023-07-23 17:01:06 +00:00
|
|
|
"build/bin/libmilepost.dylib",
|
2023-07-07 16:25:49 +00:00
|
|
|
], check=True)
|
|
|
|
subprocess.run([
|
|
|
|
"install_name_tool",
|
|
|
|
"-change", "./libGLESv2.dylib", "@rpath/libGLESv2.dylib",
|
2023-07-23 17:01:06 +00:00
|
|
|
"build/bin/libmilepost.dylib",
|
2023-07-07 16:25:49 +00:00
|
|
|
], check=True)
|
|
|
|
|
|
|
|
# add executable path to rpath. Client executable can still add its own
|
|
|
|
# rpaths if needed, e.g. @executable_path/libs/ etc.
|
|
|
|
subprocess.run([
|
|
|
|
"install_name_tool",
|
|
|
|
"-id", "@rpath/libmilepost.dylib",
|
2023-07-23 17:01:06 +00:00
|
|
|
"build/bin/libmilepost.dylib",
|
2023-07-07 16:25:49 +00:00
|
|
|
], check=True)
|
2023-07-07 23:22:13 +00:00
|
|
|
|
|
|
|
|
2023-07-19 23:14:27 +00:00
|
|
|
def build_wasm3(release):
|
|
|
|
print("Building wasm3...")
|
|
|
|
|
2023-07-23 17:01:06 +00:00
|
|
|
os.makedirs("build/bin", exist_ok=True)
|
|
|
|
os.makedirs("build/lib", exist_ok=True)
|
|
|
|
os.makedirs("build/obj", exist_ok=True)
|
2023-07-19 23:14:27 +00:00
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
build_wasm3_lib_win(release)
|
|
|
|
elif platform.system() == "Darwin":
|
2023-07-23 15:18:25 +00:00
|
|
|
build_wasm3_lib_mac(release)
|
2023-07-19 23:14:27 +00:00
|
|
|
else:
|
|
|
|
log_error(f"can't build wasm3 for unknown platform '{platform.system()}'")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def build_wasm3_lib_win(release):
|
|
|
|
for f in glob.iglob(".\\ext\\wasm3\\source\\*.c"):
|
|
|
|
name = os.path.splitext(os.path.basename(f))[0]
|
|
|
|
subprocess.run([
|
|
|
|
"cl", "/nologo",
|
|
|
|
"/Zi", "/Zc:preprocessor", "/c",
|
|
|
|
*(["/O2"] if release else []),
|
|
|
|
f"/Fo:bin\\obj\\{name}.obj",
|
|
|
|
"/I", ".\\ext\\wasm3\\source",
|
|
|
|
f,
|
|
|
|
], check=True)
|
|
|
|
subprocess.run([
|
|
|
|
"lib", "/nologo", "/out:bin\\wasm3.lib",
|
|
|
|
"bin\\obj\\*.obj",
|
|
|
|
], check=True)
|
|
|
|
|
|
|
|
|
2023-07-23 15:18:25 +00:00
|
|
|
def build_wasm3_lib_mac(release):
|
2023-07-23 17:01:06 +00:00
|
|
|
includes = ["-Iext/wasm3/source"]
|
|
|
|
debug_flags = ["-g", "-O2"]
|
2023-07-23 15:58:08 +00:00
|
|
|
flags = [
|
|
|
|
*debug_flags,
|
|
|
|
"-foptimize-sibling-calls",
|
|
|
|
"-Wno-extern-initializer",
|
|
|
|
"-Dd_m3VerboseErrorMessages",
|
|
|
|
]
|
|
|
|
|
2023-07-23 17:01:06 +00:00
|
|
|
for f in glob.iglob("ext/wasm3/source/*.c"):
|
2023-07-23 15:18:25 +00:00
|
|
|
name = os.path.splitext(os.path.basename(f))[0] + ".o"
|
|
|
|
subprocess.run([
|
2023-07-23 15:58:08 +00:00
|
|
|
"clang", "-c", *flags, *includes,
|
2023-07-23 17:01:06 +00:00
|
|
|
"-o", f"build/obj/{name}",
|
2023-07-23 15:18:25 +00:00
|
|
|
f,
|
|
|
|
], check=True)
|
2023-07-23 17:01:06 +00:00
|
|
|
subprocess.run(["ar", "-rcs", "build/lib/libwasm3.a", *glob.glob("build/obj/*.o")], check=True)
|
|
|
|
subprocess.run(["rm", "-rf", "build/obj"], check=True)
|
2023-07-23 15:18:25 +00:00
|
|
|
|
|
|
|
|
2023-07-19 23:35:07 +00:00
|
|
|
def build_orca(release):
|
|
|
|
print("Building Orca...")
|
|
|
|
|
2023-07-23 17:01:06 +00:00
|
|
|
os.makedirs("build/bin", exist_ok=True)
|
|
|
|
os.makedirs("build/lib", exist_ok=True)
|
2023-07-19 23:35:07 +00:00
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
build_orca_win(release)
|
|
|
|
elif platform.system() == "Darwin":
|
2023-07-23 15:58:08 +00:00
|
|
|
build_orca_mac(release)
|
2023-07-19 23:35:07 +00:00
|
|
|
else:
|
|
|
|
log_error(f"can't build Orca for unknown platform '{platform.system()}'")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def build_orca_win(release):
|
|
|
|
pthread_dir = "..\\vcpkg\\packages\\pthreads_x64-windows"
|
|
|
|
|
|
|
|
# copy libraries
|
|
|
|
shutil.copy("milepost\\bin\\milepost.dll", "bin")
|
|
|
|
shutil.copy("milepost\\bin\\milepost.dll.lib", "bin")
|
|
|
|
shutil.copy(os.path.join(pthread_dir, "bin\\pthreadVC3.dll"), "bin")
|
|
|
|
|
2023-07-23 15:58:08 +00:00
|
|
|
gen_all_bindings()
|
2023-07-19 23:35:07 +00:00
|
|
|
|
|
|
|
# compile orca
|
|
|
|
pthread_include = os.path.join(pthread_dir, "include")
|
|
|
|
includes = [
|
|
|
|
"/I", "src",
|
|
|
|
"/I", "sdk",
|
|
|
|
"/I", "ext\wasm3\source",
|
|
|
|
"/I", "milepost\src",
|
|
|
|
"/I", "milepost\ext",
|
|
|
|
"/I", pthread_include,
|
|
|
|
]
|
|
|
|
pthread_lib = os.path.join(pthread_dir, "lib")
|
|
|
|
libs = [
|
|
|
|
"/LIBPATH:bin",
|
|
|
|
f"/LIBPATH:{pthread_lib}",
|
|
|
|
"milepost.dll.lib",
|
|
|
|
"wasm3.lib",
|
|
|
|
"pthreadVC3.lib",
|
|
|
|
]
|
|
|
|
|
|
|
|
subprocess.run([
|
|
|
|
"cl",
|
|
|
|
"/Zi", "/Zc:preprocessor", "/std:c11",
|
|
|
|
*includes,
|
|
|
|
"src\\main.c",
|
|
|
|
"/link", *libs,
|
|
|
|
"/out:bin\\orca.exe",
|
|
|
|
], check=True)
|
|
|
|
|
|
|
|
|
2023-07-23 15:58:08 +00:00
|
|
|
def build_orca_mac(release):
|
|
|
|
# copy libraries
|
2023-07-23 17:01:06 +00:00
|
|
|
shutil.copy("milepost/build/bin/mtl_renderer.metallib", "build/bin/")
|
|
|
|
shutil.copy("milepost/build/bin/libmilepost.dylib", "build/bin/")
|
|
|
|
shutil.copy("milepost/build/bin/libGLESv2.dylib", "build/bin/")
|
|
|
|
shutil.copy("milepost/build/bin/libEGL.dylib", "build/bin/")
|
2023-07-23 15:58:08 +00:00
|
|
|
|
|
|
|
includes = [
|
|
|
|
"-Isrc",
|
|
|
|
"-Isdk",
|
|
|
|
"-Imilepost/src",
|
|
|
|
"-Imilepost/src/util",
|
|
|
|
"-Imilepost/src/platform",
|
|
|
|
"-Iext/wasm3/source",
|
|
|
|
"-Imilepost/ext/",
|
|
|
|
]
|
2023-07-23 17:01:06 +00:00
|
|
|
libs = ["-Lbuild/bin", "-Lbuild/lib", "-lmilepost", "-lwasm3"]
|
2023-07-23 15:58:08 +00:00
|
|
|
debug_flags = ["-O2"] if release else ["-g", "-DLOG_COMPILE_DEBUG"]
|
|
|
|
flags = [
|
|
|
|
*debug_flags,
|
|
|
|
"-mmacos-version-min=10.15.4",
|
|
|
|
"-maes",
|
|
|
|
]
|
|
|
|
|
|
|
|
gen_all_bindings()
|
|
|
|
|
|
|
|
# compile orca
|
|
|
|
subprocess.run([
|
|
|
|
"clang", *flags, *includes, *libs,
|
2023-07-23 17:01:06 +00:00
|
|
|
"-o", "build/bin/orca",
|
2023-07-23 15:58:08 +00:00
|
|
|
"src/main.c",
|
|
|
|
], check=True)
|
|
|
|
|
|
|
|
# fix libs imports
|
|
|
|
subprocess.run([
|
2023-07-23 17:01:06 +00:00
|
|
|
"install_name_tool",
|
|
|
|
"-change", "build/bin/libmilepost.dylib", "@rpath/libmilepost.dylib",
|
|
|
|
"build/bin/orca",
|
2023-07-23 15:58:08 +00:00
|
|
|
], check=True)
|
|
|
|
subprocess.run([
|
2023-07-23 17:01:06 +00:00
|
|
|
"install_name_tool",
|
|
|
|
"-add_rpath", "@executable_path/",
|
|
|
|
"build/bin/orca",
|
2023-07-23 15:58:08 +00:00
|
|
|
], check=True)
|
|
|
|
|
|
|
|
|
|
|
|
def gen_all_bindings():
|
|
|
|
bindgen("core", "src")
|
|
|
|
bindgen("gles", "src")
|
|
|
|
|
|
|
|
bindgen2("canvas", "src/canvas_api.json",
|
|
|
|
guest_stubs="sdk/orca_surface.c",
|
|
|
|
guest_include="graphics.h",
|
|
|
|
wasm3_bindings="src/canvas_api_bind_gen.c",
|
|
|
|
)
|
|
|
|
bindgen2("clock", "src/clock_api.json",
|
|
|
|
guest_stubs="sdk/orca_clock.c",
|
|
|
|
guest_include="platform_clock.h",
|
|
|
|
wasm3_bindings="src/clock_api_bind_gen.c",
|
|
|
|
)
|
|
|
|
bindgen2("io", "src/io_api.json",
|
|
|
|
guest_stubs="sdk/io_stubs.c",
|
|
|
|
wasm3_bindings="src/io_api_bind_gen.c",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-07-07 23:22:13 +00:00
|
|
|
def ensure_programs():
|
2023-07-15 21:23:05 +00:00
|
|
|
if platform.system() == "Windows":
|
|
|
|
try:
|
|
|
|
subprocess.run(["cl"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
except FileNotFoundError:
|
|
|
|
msg = log_error("MSVC was not found on your system.")
|
|
|
|
msg.more("If you have already installed Visual Studio, make sure you are running in a")
|
|
|
|
msg.more("Visual Studio command prompt or you have run vcvarsall.bat. Otherwise, download")
|
|
|
|
msg.more("and install Visual Studio: https://visualstudio.microsoft.com/")
|
|
|
|
exit(1)
|
|
|
|
|
2023-07-07 23:22:13 +00:00
|
|
|
try:
|
|
|
|
subprocess.run(["clang", "-v"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
|
|
except FileNotFoundError:
|
|
|
|
msg = log_error("clang was not found on your system.")
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
msg.more("We recommend installing clang via the Visual Studio installer.")
|
|
|
|
elif platform.system() == "Darwin":
|
|
|
|
msg.more("Run the following to install it:")
|
|
|
|
msg.more()
|
|
|
|
msg.more(" brew install llvm")
|
|
|
|
msg.more()
|
|
|
|
exit(1)
|
|
|
|
# TODO(ben): Check for xcode command line tools
|
|
|
|
|
|
|
|
|
|
|
|
def ensure_angle():
|
2023-07-16 00:00:34 +00:00
|
|
|
if not verify_angle():
|
|
|
|
download_angle()
|
|
|
|
print("Verifying ANGLE download...")
|
|
|
|
if not verify_angle():
|
|
|
|
log_error("automatic ANGLE download failed")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
def verify_angle():
|
2023-07-07 23:22:13 +00:00
|
|
|
checkfiles = None
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
checkfiles = [
|
2023-07-08 22:21:01 +00:00
|
|
|
"milepost/lib/libEGL.dll",
|
2023-07-15 23:39:44 +00:00
|
|
|
"milepost/lib/libEGL.dll.lib",
|
2023-07-08 22:21:01 +00:00
|
|
|
"milepost/lib/libGLESv2.dll",
|
2023-07-15 23:39:44 +00:00
|
|
|
"milepost/lib/libGLESv2.dll.lib",
|
2023-07-07 23:22:13 +00:00
|
|
|
]
|
|
|
|
elif platform.system() == "Darwin":
|
2023-07-08 22:21:01 +00:00
|
|
|
checkfiles = [
|
2023-07-23 17:01:06 +00:00
|
|
|
"milepost/build/bin/libEGL.dylib",
|
|
|
|
"milepost/build/bin/libGLESv2.dylib",
|
2023-07-08 22:21:01 +00:00
|
|
|
]
|
2023-07-07 23:22:13 +00:00
|
|
|
|
|
|
|
if checkfiles is None:
|
2023-07-16 00:00:34 +00:00
|
|
|
log_warning("could not verify if the correct version of ANGLE is present")
|
|
|
|
return False
|
2023-07-07 23:22:13 +00:00
|
|
|
|
2023-07-16 00:00:34 +00:00
|
|
|
ok = True
|
2023-07-07 23:22:13 +00:00
|
|
|
for file in checkfiles:
|
2023-07-15 21:23:05 +00:00
|
|
|
if not os.path.isfile(file):
|
2023-07-16 00:00:34 +00:00
|
|
|
ok = False
|
|
|
|
continue
|
2023-07-15 21:23:05 +00:00
|
|
|
if not checksum.checkfile(file):
|
2023-07-16 00:00:34 +00:00
|
|
|
ok = False
|
|
|
|
continue
|
2023-07-07 23:22:13 +00:00
|
|
|
|
2023-07-16 00:00:34 +00:00
|
|
|
return ok
|
2023-07-08 14:22:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def download_angle():
|
|
|
|
print("Downloading ANGLE...")
|
|
|
|
if platform.system() == "Windows":
|
2023-07-15 21:23:05 +00:00
|
|
|
build = "windows-2019"
|
2023-07-23 17:01:06 +00:00
|
|
|
extensions = [
|
|
|
|
("dll", "milepost/build/bin/"),
|
|
|
|
("lib", "milepost/build/lib/"),
|
|
|
|
]
|
2023-07-08 14:22:29 +00:00
|
|
|
elif platform.system() == "Darwin":
|
2023-07-22 23:16:31 +00:00
|
|
|
build = "macos-jank"
|
2023-07-23 17:01:06 +00:00
|
|
|
extensions = [
|
|
|
|
("dylib", "milepost/build/bin/"),
|
|
|
|
]
|
2023-07-08 14:22:29 +00:00
|
|
|
else:
|
|
|
|
log_error(f"could not automatically download ANGLE for unknown platform {platform.system()}")
|
|
|
|
return
|
|
|
|
|
2023-07-08 22:21:01 +00:00
|
|
|
os.makedirs("scripts/files", exist_ok=True)
|
|
|
|
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}"
|
2023-07-08 14:22:29 +00:00
|
|
|
with urllib.request.urlopen(url) as response:
|
2023-07-08 22:21:01 +00:00
|
|
|
with open(filepath, "wb") as out:
|
2023-07-08 14:22:29 +00:00
|
|
|
shutil.copyfileobj(response, out)
|
|
|
|
|
2023-07-08 22:21:01 +00:00
|
|
|
if not checksum.checkfile(filepath):
|
2023-07-08 14:22:29 +00:00
|
|
|
log_error(f"ANGLE download did not match checksum")
|
|
|
|
exit(1)
|
|
|
|
|
2023-07-15 21:23:05 +00:00
|
|
|
print("Extracting ANGLE...")
|
2023-07-08 22:21:01 +00:00
|
|
|
with ZipFile(filepath, "r") as anglezip:
|
2023-07-08 14:22:29 +00:00
|
|
|
anglezip.extractall(path="scripts/files")
|
|
|
|
|
2023-07-23 17:01:06 +00:00
|
|
|
os.makedirs("milepost/build/bin", exist_ok=True)
|
|
|
|
os.makedirs("milepost/build/lib", exist_ok=True)
|
2023-07-15 23:39:44 +00:00
|
|
|
for angleDir in ["bin", "lib"]:
|
2023-07-23 17:01:06 +00:00
|
|
|
for (ext, dest) in extensions:
|
2023-07-15 23:39:44 +00:00
|
|
|
for filepath in glob.glob(f"scripts/files/angle/{angleDir}/*.{ext}"):
|
2023-07-23 17:01:06 +00:00
|
|
|
shutil.copy(filepath, dest)
|
2023-07-08 22:21:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|