/bin/twnbuild: python based build solution

This commit is contained in:
veclavtalica 2025-02-02 23:08:02 +03:00
parent ccfdfd8a35
commit 96b6b7e70b
5 changed files with 39 additions and 20 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
*
!*.*
!*/
!bin/*
!Makefile
**/*.exe

View File

@ -14,6 +14,7 @@ dev_id = "you"
# Game runtime details
[game]
resolution = [ 640, 480 ]
interpreter = "$TWNROOT/apps/twnlua"
#debug = true
# Engine tweaks. You probably don't need to change these

View File

@ -1,19 +0,0 @@
#!/bin/env sh
set +e
# check whether ninja is around (you better start running)
if [ -x "$(command -v ninja)" ]; then
generator="-G Ninja"
fi
# check whether clang is around (it's just better)
if [ -x "$(command -v clang)" ]; then
cc="-DCMAKE_C_COMPILER=clang"
fi
if [ "$1" = "web" ]; then
emcmake cmake $generator $cc -B build-web "${@:2}" && cmake --build build-web --parallel
else
cmake $generator $cc -B build "$@" && cmake --build build --parallel
fi

View File

@ -8,7 +8,7 @@ toolpath="$(dirname -- "${BASH_SOURCE[0]}")"
export TWNROOT=$(realpath "$toolpath"/../)
case "$1" in
build ) "$toolpath"/build.sh "${@:2}"
build ) "$toolpath"/twnbuild "${@:2}"
;;
run ) $0 build && ./$exe "${@:2}"

36
bin/twnbuild Executable file
View File

@ -0,0 +1,36 @@
#!/bin/env python3
from subprocess import getoutput, run
from os.path import expandvars
from pathlib import Path
from sys import argv
import tomllib
has_ninja = getoutput("command -v ninja") != ""
has_clang = getoutput("command -v clang") != ""
#TODO: support for default pack override
cmake = ["cmake"]
# check whether clang is around (it's just better)
if has_clang:
cmake += ["-DCMAKE_C_COMPILER=clang"]
# check whether ninja is around (you better start running)
if has_ninja:
cmake += ["-G", "Ninja"]
cmake += ["-B", "build"]
# TODO: have it --fast instead, where separate --no-debug would mean stripping the debug info
if "--release" in argv:
cmake += ["-DCMAKE_BUILD_TYPE=Release"]
# pass arbitrary arguments over
if "--" in argv:
cmake += argv[argv.find("--"):]
# if no root cmake file is present, infer it from `twn.toml:game.interpreter`
if not Path("CMakeLists.txt").is_file():
with open("data/twn.toml", "rb") as f:
config = tomllib.load(f)
cmake += ["-S", expandvars(config["game"]["interpreter"])]
run(cmake, check=True)
run(["cmake", "--build", "build", "--parallel"], check=True)