hate-no-d/build.bat
pedro-bento b48fbc4266
All checks were successful
release / linux/aarch64 (push) Successful in 2m2s
release / linux/i686 (push) Successful in 2m4s
release / freebsd/x86_64 (push) Successful in 4m54s
release / windows/i686 (push) Successful in 2m9s
release / windows/x86_64 (push) Successful in 2m13s
release / linux/armv7 (push) Successful in 2m19s
release / linux/x86_64 (push) Successful in 2m5s
release / android (push) Successful in 2m57s
Add raygui (#13)
Reviewed-on: #13
Co-authored-by: pedro-bento <mail@pbento.pt>
Co-committed-by: pedro-bento <mail@pbento.pt>
2026-10-25 10:05:36 +00:00

196 lines
7.2 KiB
Batchfile

@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 and raylib. raylib is built
@rem with CMake (shipped with Visual Studio) and linked in whole.
@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.
@rem Pin /MT through the CL environment so LuaJIT's static CRT matches raylib's
@rem below; the static branch of msvcbuild.bat does not choose a runtime itself.
echo === Building LuaJIT (static, lua52compat) for Windows/%ARCH% ===
if exist "submodules\luajit\src\lua51.lib" del /q "submodules\luajit\src\lua51.lib"
set "HNOD_CL=%CL%"
set "CL=/MT"
pushd "submodules\luajit\src" >nul
call msvcbuild.bat lua52compat static
popd >nul
set "CL=%HNOD_CL%"
set "HNOD_CL="
@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
)
@rem raylib is built through CMake, which ships with Visual Studio.
@rem It uses the static CRT to match LuaJIT's default msvcbuild output, and
@rem defines BUILD_LIBTYPE_SHARED so its RLAPI functions carry dllexport and
@rem land in the exe's export table -- MSVC has no --export-dynamic, and ffi.C
@rem resolves C symbols through that table at runtime.
if not exist "submodules\raylib\CMakeLists.txt" (
echo build.bat: submodules\raylib is missing.
echo Fetch it with: git submodule update --init submodules/raylib
goto :fail
)
where cmake >nul 2>&1
if errorlevel 1 (
echo build.bat: cmake not found - install CMake 3.22+ or use a Developer Command Prompt.
goto :fail
)
if /I "%ARCH%"=="x64" set "CMAKE_ARCH=x64"
if /I "%ARCH%"=="x86" set "CMAKE_ARCH=Win32"
if /I "%ARCH%"=="arm64" set "CMAKE_ARCH=ARM64"
@rem One build tree per arch: CMake refuses to reuse a cache configured for
@rem another -A platform, so `build.bat x86` after x64 must not share it.
set "RAYLIB_BUILD=build\raylib-%ARCH%"
echo === Building raylib (static) for Windows/%ARCH% ===
cmake -S "submodules\raylib" -B "%RAYLIB_BUILD%" -A %CMAKE_ARCH% ^
-DBUILD_SHARED_LIBS=OFF ^
-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ^
-DCMAKE_C_FLAGS_RELEASE="/O2 /Ob2 /DNDEBUG /DBUILD_LIBTYPE_SHARED" ^
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE="%CD%\%RAYLIB_BUILD%\lib" ^
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG="%CD%\%RAYLIB_BUILD%\lib"
if errorlevel 1 goto :fail
cmake --build "%RAYLIB_BUILD%" --config Release --target raylib
if errorlevel 1 goto :fail
if not exist "%RAYLIB_BUILD%\lib\raylib.lib" (
echo build.bat: raylib.lib was not produced.
goto :fail
)
echo === Building hate-no-d.exe ===
if not exist "build" mkdir "build"
if exist "build\hate-no-d.obj" del /q "build\hate-no-d.obj"
cl /nologo /c /O2 /W4 /MT /D_CRT_SECURE_NO_WARNINGS ^
/I "submodules\luajit\src" /I "submodules\raylib\src" /I "submodules\raygui\src" ^
/DRAYGUI_IMPLEMENTATION /FI"submodules\raygui\src\raygui.h" ^
/D"RAYGUIAPI=__declspec(dllexport)" ^
/Fo"build\hate-no-d.obj" hate-no-d.c
if errorlevel 1 goto :fail
link /nologo /OUT:hate-no-d.exe "build\hate-no-d.obj" ^
"/WHOLEARCHIVE:%CD%\%RAYLIB_BUILD%\lib\raylib.lib" ^
"submodules\luajit\src\lua51.lib" ^
opengl32.lib gdi32.lib winmm.lib user32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib advapi32.lib
if errorlevel 1 goto :fail
@rem ffi.C reads the exe's export table, so verify raylib and raygui really got exported.
dumpbin /nologo /exports hate-no-d.exe | findstr /C:"InitWindow" /C:"GuiButton" >nul
if errorlevel 1 (
echo build.bat: hate-no-d.exe does not export raylib/raygui - ffi.C would not find it.
goto :fail
)
del /q "build\hate-no-d.obj"
echo.
echo === Built %CD%\hate-no-d.exe ===
popd >nul
endlocal
exit /b 0
:clean
echo === Cleaning ===
rem Every build product lives under build\ or in the submodules' own trees;
rem only hate-no-d.exe is left at the root by a build.
if exist "hate-no-d.exe" del /q "hate-no-d.exe"
if exist "hate-no-d.obj" del /q "hate-no-d.obj"
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
)
if exist "build" rmdir /s /q "build"
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