This commit will not hard-lock your Mac

This commit is contained in:
Ben Visness 2023-07-23 12:01:06 -05:00
parent 731b5a6bba
commit 8bd12bdd1f
5 changed files with 79 additions and 55 deletions

1
.gitignore vendored
View File

@ -1,6 +1,7 @@
.DS_Store .DS_Store
*.dSYM *.dSYM
bin/* bin/*
build
*.metallib *.metallib
*.pdb *.pdb
*.exe *.exe

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
set -eo pipefail set -exo pipefail
target="$1" target="$1"

View File

@ -19,9 +19,12 @@ ANGLE_VERSION = "2023-07-05"
def attach_build_runtime(subparsers): def attach_build_runtime(subparsers):
build = subparsers.add_parser("build-runtime", help="TODO") build_cmd = subparsers.add_parser("build-runtime", help="TODO")
build.add_argument("--release", action="store_true", help="compile Orca in release mode (default is debug)") build_cmd.add_argument("--release", action="store_true", help="compile Orca in release mode (default is debug)")
build.set_defaults(func=shellish(build_runtime)) build_cmd.set_defaults(func=shellish(build_runtime))
clean_cmd = subparsers.add_parser("clean", help="Delete all build artifacts and start fresh")
clean_cmd.set_defaults(func=shellish(clean))
def build_runtime(args): def build_runtime(args):
@ -33,11 +36,21 @@ def build_runtime(args):
build_orca(args.release) build_orca(args.release)
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__")
def build_milepost(target, release): def build_milepost(target, release):
print("Building milepost...") print("Building milepost...")
with pushd("milepost"): with pushd("milepost"):
os.makedirs("bin", exist_ok=True) os.makedirs("build/bin", exist_ok=True)
os.makedirs("lib", exist_ok=True) os.makedirs("build/lib", exist_ok=True)
os.makedirs("resources", exist_ok=True) os.makedirs("resources", exist_ok=True)
if target == "lib": if target == "lib":
@ -126,13 +139,13 @@ def build_milepost_lib_mac(release):
"xcrun", "-sdk", "macosx", "metal", "xcrun", "-sdk", "macosx", "metal",
# TODO: shaderFlagParam # TODO: shaderFlagParam
"-fno-fast-math", "-c", "-fno-fast-math", "-c",
"-o", "lib/mtl_renderer.air", "-o", "build/mtl_renderer.air",
"src/mtl_renderer.metal", "src/mtl_renderer.metal",
], check=True) ], check=True)
subprocess.run([ subprocess.run([
"xcrun", "-sdk", "macosx", "metallib", "xcrun", "-sdk", "macosx", "metallib",
"-o", "lib/mtl_renderer.metallib", "-o", "build/bin/mtl_renderer.metallib",
"lib/mtl_renderer.air", "build/mtl_renderer.air",
], check=True) ], check=True)
# compile milepost. We use one compilation unit for all C code, and one # compile milepost. We use one compilation unit for all C code, and one
@ -140,14 +153,14 @@ def build_milepost_lib_mac(release):
subprocess.run([ subprocess.run([
"clang", "clang",
*debug_flags, "-c", *debug_flags, "-c",
"-o", "bin/milepost_c.o", "-o", "build/milepost_c.o",
*cflags, *flags, *includes, *cflags, *flags, *includes,
"src/milepost.c" "src/milepost.c"
], check=True) ], check=True)
subprocess.run([ subprocess.run([
"clang", "clang",
*debug_flags, "-c", *debug_flags, "-c",
"-o", "bin/milepost_objc.o", "-o", "build/milepost_objc.o",
*flags, *includes, *flags, *includes,
"src/milepost.m" "src/milepost.m"
], check=True) ], check=True)
@ -156,9 +169,9 @@ def build_milepost_lib_mac(release):
subprocess.run([ subprocess.run([
"ld", "ld",
*ldflags, "-dylib", *ldflags, "-dylib",
"-o", "bin/libmilepost.dylib", "-o", "build/bin/libmilepost.dylib",
"bin/milepost_c.o", "bin/milepost_objc.o", "build/milepost_c.o", "build/milepost_objc.o",
"-Llib", "-lc", "-Lbuild/bin", "-lc",
"-framework", "Carbon", "-framework", "Cocoa", "-framework", "Metal", "-framework", "QuartzCore", "-framework", "Carbon", "-framework", "Cocoa", "-framework", "Metal", "-framework", "QuartzCore",
"-weak-lEGL", "-weak-lGLESv2", "-weak-lEGL", "-weak-lGLESv2",
], check=True) ], check=True)
@ -167,12 +180,12 @@ def build_milepost_lib_mac(release):
subprocess.run([ subprocess.run([
"install_name_tool", "install_name_tool",
"-change", "./libEGL.dylib", "@rpath/libEGL.dylib", "-change", "./libEGL.dylib", "@rpath/libEGL.dylib",
"bin/libmilepost.dylib", "build/bin/libmilepost.dylib",
], check=True) ], check=True)
subprocess.run([ subprocess.run([
"install_name_tool", "install_name_tool",
"-change", "./libGLESv2.dylib", "@rpath/libGLESv2.dylib", "-change", "./libGLESv2.dylib", "@rpath/libGLESv2.dylib",
"bin/libmilepost.dylib", "build/bin/libmilepost.dylib",
], check=True) ], check=True)
# add executable path to rpath. Client executable can still add its own # add executable path to rpath. Client executable can still add its own
@ -180,15 +193,16 @@ def build_milepost_lib_mac(release):
subprocess.run([ subprocess.run([
"install_name_tool", "install_name_tool",
"-id", "@rpath/libmilepost.dylib", "-id", "@rpath/libmilepost.dylib",
"bin/libmilepost.dylib", "build/bin/libmilepost.dylib",
], check=True) ], check=True)
def build_wasm3(release): def build_wasm3(release):
print("Building wasm3...") print("Building wasm3...")
os.makedirs("bin", exist_ok=True) os.makedirs("build/bin", exist_ok=True)
os.makedirs("bin/obj", exist_ok=True) os.makedirs("build/lib", exist_ok=True)
os.makedirs("build/obj", exist_ok=True)
if platform.system() == "Windows": if platform.system() == "Windows":
build_wasm3_lib_win(release) build_wasm3_lib_win(release)
@ -217,8 +231,8 @@ def build_wasm3_lib_win(release):
def build_wasm3_lib_mac(release): def build_wasm3_lib_mac(release):
includes = ["-I./ext/wasm3/source"] includes = ["-Iext/wasm3/source"]
debug_flags = ["-O2"] if release else ["-g"] debug_flags = ["-g", "-O2"]
flags = [ flags = [
*debug_flags, *debug_flags,
"-foptimize-sibling-calls", "-foptimize-sibling-calls",
@ -226,21 +240,22 @@ def build_wasm3_lib_mac(release):
"-Dd_m3VerboseErrorMessages", "-Dd_m3VerboseErrorMessages",
] ]
for f in glob.iglob("./ext/wasm3/source/*.c"): for f in glob.iglob("ext/wasm3/source/*.c"):
name = os.path.splitext(os.path.basename(f))[0] + ".o" name = os.path.splitext(os.path.basename(f))[0] + ".o"
subprocess.run([ subprocess.run([
"clang", "-c", *flags, *includes, "clang", "-c", *flags, *includes,
"-o", f"./bin/obj/{name}", "-o", f"build/obj/{name}",
f, f,
], check=True) ], check=True)
subprocess.run(["ar", "-rcs", "./bin/libwasm3.a", *glob.glob("./bin/obj/*.o")], check=True) subprocess.run(["ar", "-rcs", "build/lib/libwasm3.a", *glob.glob("build/obj/*.o")], check=True)
subprocess.run(["rm", "-rf", "./bin/obj"], check=True) subprocess.run(["rm", "-rf", "build/obj"], check=True)
def build_orca(release): def build_orca(release):
print("Building Orca...") print("Building Orca...")
os.makedirs("bin", exist_ok=True) os.makedirs("build/bin", exist_ok=True)
os.makedirs("build/lib", exist_ok=True)
if platform.system() == "Windows": if platform.system() == "Windows":
build_orca_win(release) build_orca_win(release)
@ -292,10 +307,10 @@ def build_orca_win(release):
def build_orca_mac(release): def build_orca_mac(release):
# copy libraries # copy libraries
shutil.copy("milepost/bin/mtl_renderer.metallib", "bin/") shutil.copy("milepost/build/bin/mtl_renderer.metallib", "build/bin/")
shutil.copy("milepost/bin/libmilepost.dylib", "bin/") shutil.copy("milepost/build/bin/libmilepost.dylib", "build/bin/")
shutil.copy("milepost/bin/libGLESv2.dylib", "bin/") shutil.copy("milepost/build/bin/libGLESv2.dylib", "build/bin/")
shutil.copy("milepost/bin/libEGL.dylib", "bin/") shutil.copy("milepost/build/bin/libEGL.dylib", "build/bin/")
includes = [ includes = [
"-Isrc", "-Isrc",
@ -306,7 +321,7 @@ def build_orca_mac(release):
"-Iext/wasm3/source", "-Iext/wasm3/source",
"-Imilepost/ext/", "-Imilepost/ext/",
] ]
libs = ["-Lbin", "-lmilepost", "-lwasm3"] libs = ["-Lbuild/bin", "-Lbuild/lib", "-lmilepost", "-lwasm3"]
debug_flags = ["-O2"] if release else ["-g", "-DLOG_COMPILE_DEBUG"] debug_flags = ["-O2"] if release else ["-g", "-DLOG_COMPILE_DEBUG"]
flags = [ flags = [
*debug_flags, *debug_flags,
@ -319,18 +334,20 @@ def build_orca_mac(release):
# compile orca # compile orca
subprocess.run([ subprocess.run([
"clang", *flags, *includes, *libs, "clang", *flags, *includes, *libs,
"-o", "bin/orca", "-o", "build/bin/orca",
"src/main.c", "src/main.c",
], check=True) ], check=True)
# fix libs imports # fix libs imports
subprocess.run([ subprocess.run([
"install_name_tool", "-change", "install_name_tool",
"./bin/libmilepost.dylib", "@rpath/libmilepost.dylib", "bin/orca", "-change", "build/bin/libmilepost.dylib", "@rpath/libmilepost.dylib",
"build/bin/orca",
], check=True) ], check=True)
subprocess.run([ subprocess.run([
"install_name_tool", "-add_rpath", "install_name_tool",
"@executable_path/", "bin/orca", "-add_rpath", "@executable_path/",
"build/bin/orca",
], check=True) ], check=True)
@ -400,8 +417,8 @@ def verify_angle():
] ]
elif platform.system() == "Darwin": elif platform.system() == "Darwin":
checkfiles = [ checkfiles = [
"milepost/lib/libEGL.dylib", "milepost/build/bin/libEGL.dylib",
"milepost/lib/libGLESv2.dylib", "milepost/build/bin/libGLESv2.dylib",
] ]
if checkfiles is None: if checkfiles is None:
@ -424,10 +441,15 @@ def download_angle():
print("Downloading ANGLE...") print("Downloading ANGLE...")
if platform.system() == "Windows": if platform.system() == "Windows":
build = "windows-2019" build = "windows-2019"
extensions = ["dll", "lib"] extensions = [
("dll", "milepost/build/bin/"),
("lib", "milepost/build/lib/"),
]
elif platform.system() == "Darwin": elif platform.system() == "Darwin":
build = "macos-jank" build = "macos-jank"
extensions = ["dylib"] extensions = [
("dylib", "milepost/build/bin/"),
]
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
@ -448,11 +470,12 @@ def download_angle():
with ZipFile(filepath, "r") as anglezip: with ZipFile(filepath, "r") as anglezip:
anglezip.extractall(path="scripts/files") anglezip.extractall(path="scripts/files")
os.makedirs("milepost/lib", exist_ok=True) os.makedirs("milepost/build/bin", exist_ok=True)
os.makedirs("milepost/build/lib", exist_ok=True)
for angleDir in ["bin", "lib"]: for angleDir in ["bin", "lib"]:
for ext in extensions: for (ext, dest) in extensions:
for filepath in glob.glob(f"scripts/files/angle/{angleDir}/*.{ext}"): for filepath in glob.glob(f"scripts/files/angle/{angleDir}/*.{ext}"):
shutil.copy(filepath, "milepost/lib") shutil.copy(filepath, dest)
def embed_text_glsl(outputpath, prefix, shaders): def embed_text_glsl(outputpath, prefix, shaders):

View File

@ -5,6 +5,6 @@
"milepost/lib/libEGL.dll.lib": "4cec54c534136da413dea86bd271ccb9c5ae88e40aa91d1de7a01e701be8e1d7", "milepost/lib/libEGL.dll.lib": "4cec54c534136da413dea86bd271ccb9c5ae88e40aa91d1de7a01e701be8e1d7",
"milepost/lib/libGLESv2.dll": "193b53b0a16b702eaa28a73e84527acf7aecfd665e3e3f54a8d9db9ae73111e1", "milepost/lib/libGLESv2.dll": "193b53b0a16b702eaa28a73e84527acf7aecfd665e3e3f54a8d9db9ae73111e1",
"milepost/lib/libGLESv2.dll.lib": "ee87aac129efe8fe871825d181b85da1b1ea6626cb48be52c2e689f2804b953f", "milepost/lib/libGLESv2.dll.lib": "ee87aac129efe8fe871825d181b85da1b1ea6626cb48be52c2e689f2804b953f",
"milepost/lib/libEGL.dylib": "96baea4b1c8578d30738764784d07b509d1153df694c094faba2ee8ccbfde2a9", "milepost/build/bin/libEGL.dylib": "96baea4b1c8578d30738764784d07b509d1153df694c094faba2ee8ccbfde2a9",
"milepost/lib/libGLESv2.dylib": "98ce9f6248a6447ba9199e96b8f6d87df9548d43ce583a2615717aab168ecb71" "milepost/build/bin/libGLESv2.dylib": "98ce9f6248a6447ba9199e96b8f6d87df9548d43ce583a2615717aab168ecb71"
} }

View File

@ -33,11 +33,11 @@ def macos_make_app(args):
#----------------------------------------------------------- #-----------------------------------------------------------
#NOTE: copy orca runtime executable and libraries #NOTE: copy orca runtime executable and libraries
#----------------------------------------------------------- #-----------------------------------------------------------
orca_exe = args.orca_dir + '/bin/orca' orca_exe = args.orca_dir + '/build/bin/orca'
milepost_lib = args.orca_dir + '/bin/libmilepost.dylib' milepost_lib = args.orca_dir + '/build/bin/libmilepost.dylib'
gles_lib = args.orca_dir + '/bin/libGLESv2.dylib' gles_lib = args.orca_dir + '/build/bin/libGLESv2.dylib'
egl_lib = args.orca_dir + '/bin/libEGL.dylib' egl_lib = args.orca_dir + '/build/bin/libEGL.dylib'
renderer_lib = args.orca_dir + '/bin/mtl_renderer.metallib' renderer_lib = args.orca_dir + '/build/bin/mtl_renderer.metallib'
shutil.copy(orca_exe, exe_dir) shutil.copy(orca_exe, exe_dir)
shutil.copy(milepost_lib, exe_dir) shutil.copy(milepost_lib, exe_dir)
@ -169,11 +169,11 @@ def windows_make_app(args):
#----------------------------------------------------------- #-----------------------------------------------------------
#NOTE: copy orca runtime executable and libraries #NOTE: copy orca runtime executable and libraries
#----------------------------------------------------------- #-----------------------------------------------------------
orca_exe = args.orca_dir + '/bin/orca.exe' orca_exe = args.orca_dir + '/build/bin/orca.exe'
milepost_lib = args.orca_dir + '/bin/milepost.dll' milepost_lib = args.orca_dir + '/build/bin/milepost.dll'
gles_lib = args.orca_dir + '/milepost/bin/libGLESv2.dll' gles_lib = args.orca_dir + '/milepost/build/bin/libGLESv2.dll'
egl_lib = args.orca_dir + '/milepost/bin/libEGL.dll' egl_lib = args.orca_dir + '/milepost/build/bin/libEGL.dll'
pthread_lib = args.orca_dir + '/bin/pthreadVC3.dll' pthread_lib = args.orca_dir + '/build/bin/pthreadVC3.dll'
shutil.copy(orca_exe, exe_dir) shutil.copy(orca_exe, exe_dir)
shutil.copy(milepost_lib, exe_dir) shutil.copy(milepost_lib, exe_dir)