-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.bat
More file actions
116 lines (93 loc) · 4.17 KB
/
build.bat
File metadata and controls
116 lines (93 loc) · 4.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@echo off
setlocal
set exe_name=minecraft2d
set client_name=%exe_name%_client
::
:: Usage:
:: build - Default for `build debug`
:: build client - Builds src/main_client to ./*_client.exe
:: build debug - Builds a debug version of src/main_standalone
:: build release - Builds a optimized version of src/main_standalone
:: build hot - Builds src as a dll that is hot-reloaded by client.exe
::
:: Set working directory to path of this script
cd /d "%~dp0"
:: Unpack arguments
for %%a in (%*) do set "%%a=1"
set common_compiler_flags=-vet-style -vet-cast -show-timings -collection:third_party=third_party
set debug_flags=%common_compiler_flags% -debug -subsystem:console
set release_flags=%common_compiler_flags% -no-bounds-check -o:speed -subsystem:windows
pushd src
set SHADER_SRC=shader.glsl
set SHADER_OUT=generated_shader.odin
..\sokol-shdc -i %SHADER_SRC% -o %SHADER_OUT% -l hlsl5:glsl430:wgsl -f sokol_odin
popd
echo [metagen]
odin run metagen %common_compiler_flags% || exit /b 1
:: OpenGL
::if "%opengl%" == "1"
@REM set common_compiler_flags=%common_compiler_flags% -define:SOKOL_USE_GL=true && echo [opengl]
:: Handle special subarguments
if "%hot%" == "1" goto HOT_RELOAD
:: ======================================================================
if not "%release%" == "1" set debug=1
if "%debug%" == "1" set release=0 && echo [debug build]
if "%release%" == "1" set debug=0 && echo [release build]
if "%debug%" == "1" set compiler_flags=%debug_flags% && set sub_dir=debug
if "%release%" == "1" set compiler_flags=%release_flags% && set sub_dir=release
if "%client%" == "1" goto BUILD_CLIENT
if not exist build mkdir build
if not exist build\%sub_dir% mkdir build\%sub_dir%
odin build src\main_standalone -out:build/%sub_dir%/%exe_name%.exe %compiler_flags% || exit /b 1
echo [%exe_name%.exe]
exit /b 0
:: ======================================================================
:BUILD_CLIENT
odin build src\main_client -out:%client_name%.exe %compiler_flags% -define:SOKOL_DLL=true || exit /b 1
echo [%client_name%.exe]
exit /b 0
:: ======================================================================
:HOT_RELOAD
set game_running=false
:: out_dir is for everything except the exe. The exe needs to stay in root
:: folder so it sees the res folder, without having to copy it.
set out_dir=build\hot_reload
set game_pdbs_dir=%out_dir%\pdbs
if not exist %out_dir% mkdir %out_dir%
:: Check if game is running
set exe=%client_name%.exe
for /F %%x in ('tasklist /NH /FI "IMAGENAME eq %exe%"') DO if %%x == %exe% set game_running=true
:: if game isn't running then:
:: - delete all game_XXX.dll files
:: - delete all PDBs in pdbs subdir
:: - optionally create the pdbs subdir
:: - write 0 into pdbs\pdb_number so game.dll PDBs start counting from zero
::
:: This makes sure we start over "fresh" at PDB number 0 when starting up the
:: game and it also makes sure we don't have so many PDBs laying around.
if %game_running% == false (
del /q /s %out_dir% >nul 2>nul
if not exist "%game_pdbs_dir%" mkdir %game_pdbs_dir%
echo 0 > %game_pdbs_dir%\pdb_number
)
:: Load PDB number from file, increment and store back. For as long as the game
:: is running the pdb_number file won't be reset to 0, so we'll get a PDB of a
:: unique name on each hot reload.
set /p pdb_number=<%game_pdbs_dir%\pdb_number
set /a pdb_number=%pdb_number%+1
echo %pdb_number% > %game_pdbs_dir%\pdb_number
:: Build game dll, use pdbs\game_%pdb_number%.pdb as PDB name so each dll gets
:: its own PDB. This PDB stuff is done in order to make debugging work.
:: Debuggers tend to lock PDBs or just misbehave if you reuse the same PDB while
:: the debugger is attached. So each time we compile `game.dll` we give the
:: PDB a unique PDB.
::
:: Note that we could not just rename the PDB after creation; the DLL contains a
:: reference to where the PDB is.
::
:: Also note that we always write game.dll to the same file. hot_reload.exe
:: monitors this file and does the hot reload when it changes.
echo Building game.dll
odin build src -out:%out_dir%/game.dll -define:SOKOL_DLL=true -pdb-name:%game_pdbs_dir%\game_%pdb_number%.pdb %common_compiler_flags% -debug -build-mode:dll > nul
echo [game.dll] version %pdb_number%
exit /b 0