attempt to build web version out of emscripten legacy gl wrapper

This commit is contained in:
veclavtalica
2025-02-21 18:07:04 +03:00
parent 85e47dd677
commit dd4fc45be3
10 changed files with 123 additions and 68 deletions

View File

@ -7,45 +7,56 @@ from pathlib import Path
from sys import argv
import tomllib
#TODO: support for default pack override
#TODO: automatic full rebuild on git head change (such as new commits)
has_ninja = getoutput("command -v ninja") != ""
has_clang = getoutput("command -v clang") != ""
#TODO: support for default pack override
target_web = "--target=web" in argv
#TODO: infer what "native" means for current env
build_dir = "build/web" if target_web else "build/native"
build_dir += "/release" if "--release" in argv else "/debug"
cmake = ["emcmake", "cmake"] if target_web else ["cmake"]
# cmake configuration command
command = []
cmake = ["cmake"]
# check whether clang is around (it's just better)
if has_clang:
cmake += ["-DCMAKE_C_COMPILER=clang"]
command += ["-DCMAKE_C_COMPILER=clang"]
# check whether ninja is around (you better start running)
if has_ninja:
cmake += ["-G", "Ninja"]
cmake += ["-B", "build"]
command += ["-G", "Ninja"]
command += ["-B", build_dir]
# TODO: have it --fast=1 instead, where separate --debug=0 would mean stripping the debug info
if "--release" in argv:
cmake += ["-DCMAKE_BUILD_TYPE=Release"]
command += ["-DCMAKE_BUILD_TYPE=Release"]
elif "--debug" in argv:
cmake += ["-DCMAKE_BUILD_TYPE=Debug"]
command += ["-DCMAKE_BUILD_TYPE=Debug"]
if "--unified=1" in argv:
cmake += ["-DTWN_FEATURE_DYNLIB_GAME=ON"]
command += ["-DTWN_FEATURE_DYNLIB_GAME=ON"]
elif "--unified=0" in argv:
cmake += ["-DTWN_FEATURE_DYNLIB_GAME=OFF"]
command += ["-DTWN_FEATURE_DYNLIB_GAME=OFF"]
if "--sanitize=1" in argv:
cmake += ["-DTWN_SANITIZE=ON"]
command += ["-DTWN_SANITIZE=ON"]
elif "--sanitize=0" in argv:
cmake += ["-DTWN_SANITIZE=OFF"]
command += ["-DTWN_SANITIZE=OFF"]
cmake += [f"-DTWN_OUT_DIR={getcwd()}"]
command += [f"-DTWN_OUT_DIR={getcwd()}"]
# pass arbitrary arguments over
if "--" in argv:
cmake += argv[argv.index("--")+1:]
command += argv[argv.index("--")+1:]
# if no root cmake file is present, infer it from `twn.toml:game.interpreter`
if not Path("CMakeLists.txt").is_file():
config = tomllib.loads(Path("data/twn.toml").read_text())
cmake += ["-S", expandvars(config["game"]["interpreter"])]
command += ["-S", expandvars(config["game"]["interpreter"])]
run(cmake, check=True)
run(["cmake", "--build", "build", "--parallel"], check=True)
run(cmake + command, check=True)
run(["cmake"] + ["--build", build_dir, "--parallel"], check=True)