/bin/twnbuild: python based build solution
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -2,6 +2,7 @@
 | 
				
			|||||||
*
 | 
					*
 | 
				
			||||||
!*.*
 | 
					!*.*
 | 
				
			||||||
!*/
 | 
					!*/
 | 
				
			||||||
 | 
					!bin/*
 | 
				
			||||||
!Makefile
 | 
					!Makefile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
**/*.exe
 | 
					**/*.exe
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@ dev_id = "you"
 | 
				
			|||||||
# Game runtime details
 | 
					# Game runtime details
 | 
				
			||||||
[game]
 | 
					[game]
 | 
				
			||||||
resolution = [ 640, 480 ]
 | 
					resolution = [ 640, 480 ]
 | 
				
			||||||
 | 
					interpreter = "$TWNROOT/apps/twnlua"
 | 
				
			||||||
#debug = true
 | 
					#debug = true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Engine tweaks. You probably don't need to change these
 | 
					# Engine tweaks. You probably don't need to change these
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										19
									
								
								bin/build.sh
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								bin/build.sh
									
									
									
									
									
								
							@@ -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
 | 
					 | 
				
			||||||
							
								
								
									
										2
									
								
								bin/twn
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								bin/twn
									
									
									
									
									
								
							@@ -8,7 +8,7 @@ toolpath="$(dirname -- "${BASH_SOURCE[0]}")"
 | 
				
			|||||||
export TWNROOT=$(realpath "$toolpath"/../)
 | 
					export TWNROOT=$(realpath "$toolpath"/../)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
case "$1" in
 | 
					case "$1" in
 | 
				
			||||||
    build    ) "$toolpath"/build.sh "${@:2}"
 | 
					    build    ) "$toolpath"/twnbuild "${@:2}"
 | 
				
			||||||
               ;;
 | 
					               ;;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    run      ) $0 build && ./$exe "${@:2}"
 | 
					    run      ) $0 build && ./$exe "${@:2}"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										36
									
								
								bin/twnbuild
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										36
									
								
								bin/twnbuild
									
									
									
									
									
										Executable 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)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user