Added build.bat for Windows

This commit is contained in:
pedro-bento 2026-10-21 18:58:42 +01:00
parent 8462be8cfd
commit ee4e6a0e72
2 changed files with 153 additions and 2 deletions

View file

@ -2,10 +2,32 @@
A [Love2D](https://www.love2d.org/) antagonist.
## Quick start
## Quick Start
```sh
make
echo -e 'print("Hey! I am hate-no-d!")' > quick-start.lua
./hate-no-d quick-start.lua
```
## Build
```sh
git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git
cd hate-no-d
make
```
## Quick Start (Windows)
```bat
echo print("Hey! I am hate-no-d!") > quick-start.lua
hate-no-d.exe quick-start.lua
```
## Build (Windows)
```bat
git clone --recurse-submodules https://git.pbento.pt/pedro-bento/hate-no-d.git
cd hate-no-d
build.bat
```

129
build.bat Normal file
View file

@ -0,0 +1,129 @@
@rem Build hate-no-d for Windows with MSVC.
@rem
@rem build.bat x64 (default)
@rem build.bat x86 32-bit
@rem build.bat arm64 ARM64
@rem build.bat clean remove build artifacts
@rem
@rem Works from a plain cmd.exe (locates Visual Studio itself) or from an
@rem existing Developer Command Prompt. Produces hate-no-d.exe in this
@rem directory, statically linked against LuaJIT.
@echo off
setlocal EnableExtensions
pushd "%~dp0" >nul
set "ARCH=%~1"
if /I "%ARCH%"=="clean" goto :clean
if "%ARCH%"=="" set "ARCH=x64"
if /I "%ARCH%"=="x64" goto :archok
if /I "%ARCH%"=="x86" goto :archok
if /I "%ARCH%"=="arm64" goto :archok
echo Usage: build.bat [x64^|x86^|arm64^|clean]
goto :fail
:archok
@rem Reuse an existing compiler environment only if it targets the arch asked
@rem for; otherwise reinitialise, so `build.bat x86` is never a silent x64 build.
if not defined INCLUDE call :vsenv
if not defined INCLUDE goto :nosdk
if /I not "%VSCMD_ARG_TGT_ARCH%"=="%ARCH%" call :vsenv
if not defined INCLUDE goto :nosdk
if not exist "submodules\luajit\src\msvcbuild.bat" (
echo build.bat: submodules\luajit is missing.
echo Fetch it at the pinned commit, e.g.:
echo git clone https://luajit.org/git/luajit.git submodules\luajit
echo git -C submodules\luajit checkout a4c064539ea931274d407e1249b4bb575424a0f4
goto :fail
)
@rem msvcbuild.bat only ever appends options in a fixed order and deletes its
@rem own .obj files at the end, so every run is a full rebuild anyway.
echo === Building LuaJIT (static, lua52compat) for Windows/%ARCH% ===
if exist "submodules\luajit\src\lua51.lib" del /q "submodules\luajit\src\lua51.lib"
pushd "submodules\luajit\src" >nul
call msvcbuild.bat lua52compat static
popd >nul
@rem msvcbuild.bat does not set errorlevel when it fails, so the artifact is
@rem the only trustworthy signal.
if not exist "submodules\luajit\src\lua51.lib" (
echo.
echo build.bat: LuaJIT failed to build.
goto :fail
)
echo === Building hate-no-d.exe ===
if exist hate-no-d.obj del /q hate-no-d.obj
cl /nologo /c /O2 /W4 /D_CRT_SECURE_NO_WARNINGS ^
/I "submodules\luajit\src" /Fo"hate-no-d.obj" hate-no-d.c
if errorlevel 1 goto :fail
link /nologo /OUT:hate-no-d.exe hate-no-d.obj "submodules\luajit\src\lua51.lib"
if errorlevel 1 goto :fail
del /q hate-no-d.obj
echo.
echo === Built %CD%\hate-no-d.exe ===
popd >nul
endlocal
exit /b 0
:clean
echo === Cleaning ===
for %%f in (hate-no-d.exe hate-no-d.obj) do if exist "%%f" del /q "%%f"
if exist "submodules\luajit\src" (
pushd "submodules\luajit\src" >nul
for %%f in (lua51.lib lua51.dll luajit.exe minilua.exe buildvm.exe) do if exist "%%f" del /q "%%f"
for %%f in (lj_bcdef.h lj_ffdef.h lj_libdef.h lj_recdef.h lj_folddef.h) do if exist "%%f" del /q "%%f"
if exist "host\buildvm_arch.h" del /q "host\buildvm_arch.h"
del /q *.obj host\*.obj *.manifest >nul 2>&1
popd >nul
)
popd >nul
endlocal
exit /b 0
@rem ---------------------------------------------------------------------------
@rem Locate Visual Studio and load its compiler environment for %ARCH%.
@rem Leaves INCLUDE defined on success.
@rem ---------------------------------------------------------------------------
:vsenv
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist "%VSWHERE%" set "VSWHERE=%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe"
if not exist "%VSWHERE%" (
echo build.bat: vswhere.exe not found - is Visual Studio installed?
exit /b 1
)
set "VSPATH="
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath`) do set "VSPATH=%%i"
if not defined VSPATH (
echo build.bat: no Visual Studio installation with the C++ toolset was found.
exit /b 1
)
if exist "%VSPATH%\Common7\Tools\VsDevCmd.bat" (
call "%VSPATH%\Common7\Tools\VsDevCmd.bat" -arch=%ARCH% -no_logo
exit /b 0
)
if exist "%VSPATH%\VC\Auxiliary\Build\vcvarsall.bat" (
call "%VSPATH%\VC\Auxiliary\Build\vcvarsall.bat" %ARCH%
exit /b 0
)
echo build.bat: no VsDevCmd.bat or vcvarsall.bat under "%VSPATH%".
exit /b 1
:nosdk
echo build.bat: could not establish an MSVC environment for %ARCH%.
goto :fail
:fail
popd >nul
endlocal
exit /b 1