improved build_win_premake.bat and package_win.bat

This commit is contained in:
Sak32009 2024-08-18 11:08:23 +02:00
parent 34f664621c
commit 26a07e06e7
6 changed files with 239 additions and 214 deletions

View File

@ -2,7 +2,7 @@ name: Prepare release
on: on:
push: push:
tags: tags:
- release-* - release-*
workflow_dispatch: workflow_dispatch:
# allows manual trigger # allows manual trigger
@ -58,12 +58,12 @@ jobs:
dir /s /b /a:-d build\win dir /s /b /a:-d build\win
### remove linker files ### remove linker files
- name: Remove linker files ### - name: Remove linker files
shell: cmd ### shell: cmd
working-directory: ${{ github.workspace }} ### working-directory: ${{ github.workspace }}
run: | ### run: |
del /f /s /q build\win\*.exp,build\win\*.lib ### del /f /s /q build\win\*.exp,build\win\*.lib
exit /b 0 ### exit /b 0
### package (release mode) ### package (release mode)
- name: Package build (release) - name: Package build (release)

View File

@ -1,120 +1,117 @@
@echo off @echo off
setlocal setlocal EnableDelayedExpansion
cd /d "%~dp0"
:: use 70%
set /a build_threads=2 set /a "MAX_THREADS=2"
if defined NUMBER_OF_PROCESSORS ( if defined NUMBER_OF_PROCESSORS (
set /a build_threads=NUMBER_OF_PROCESSORS*70/100 :: use 70%
) set /a "MAX_THREADS=%NUMBER_OF_PROCESSORS% * 70 / 100"
if %build_threads% lss 1 ( if %MAX_THREADS% lss 1 (
set /a build_threads=1 set /a "MAX_THREADS=1"
) )
)
set /a BUILD_DEPS=0
:args_loop set /a "BUILD_DEPS=0"
if "%~1"=="" (
goto :args_loop_end :args_loop
) else if "%~1"=="--deps" ( if "%~1" equ "" (
set /a BUILD_DEPS=1 goto :args_loop_end
) else if "%~1"=="--help" ( ) else if "%~1" equ "--deps" (
call :help_page set /a "BUILD_DEPS=1"
goto :end_script ) else if "%~1" equ "--help" (
) else ( goto :help_page
1>&2 echo "invalid arg %~1" ) else (
goto :end_script_with_err 1>&2 echo: invalid arg %~1
) goto :end_script_with_err
shift /1 )
goto :args_loop
:args_loop_end shift /1
goto :args_loop
set "premake_exe=third-party\common\win\premake\premake5.exe"
if not exist "%premake_exe%" ( :args_loop_end
1>&2 echo "preamke wasn't found" :: check premake
goto :end_script_with_err set "PREMAKE_EXE=third-party\common\win\premake\premake5.exe"
) if not exist "%PREMAKE_EXE%" (
1>&2 echo: premake wasn't found
:: build deps goto :end_script_with_err
if %BUILD_DEPS%==0 ( )
goto :build_deps_end
) :: build deps
set "CMAKE_GENERATOR=Visual Studio 17 2022" if %BUILD_DEPS% equ 1 (
call "%premake_exe%" --file="premake5-deps.lua" --all-ext --all-build --64-build --32-build --verbose --clean --os=windows vs2022 set "CMAKE_GENERATOR=Visual Studio 17 2022"
if %errorlevel% neq 0 ( call "%PREMAKE_EXE%" --file="premake5-deps.lua" --64-build --32-build --all-ext --all-build --j=2 --verbose --clean --os=windows vs2022
goto :end_script_with_err if %errorlevel% neq 0 (
) goto :end_script_with_err
:build_deps_end )
goto :end_script
:: VS WHERE to get MSBUILD )
set "vswhere_exe=third-party\common\win\vswhere\vswhere.exe"
if not exist "%vswhere_exe%" ( :: check vswhere
1>&2 echo "vswhere wasn't found" set "VSWHERE_EXE=third-party\common\win\vswhere\vswhere.exe"
goto :end_script_with_err if not exist "%VSWHERE_EXE%" (
) 1>&2 echo: vswhere wasn't found
goto :end_script_with_err
:: .sln file )
set "sln_file=build\project\vs2022\win\gbe.sln"
:: check msbuild
:: get msbuild path set "MSBUILD_EXE="
set "my_vs_path=" for /f "tokens=* delims=" %%A in ('"%VSWHERE_EXE%" -prerelease -latest -nocolor -nologo -property installationPath 2^>nul') do (
for /f "tokens=* delims=" %%A in ('"%vswhere_exe%" -prerelease -latest -nocolor -nologo -property installationPath 2^>nul') do ( set "MSBUILD_EXE=%%~A\MSBuild\Current\Bin\MSBuild.exe"
set "my_vs_path=%%~A\MSBuild\Current\Bin\MSBuild.exe" )
) if not exist "%MSBUILD_EXE%" (
if not exist "%my_vs_path%" ( 1>&2 echo: MSBuild wasn't found
1>&2 echo "MSBuild wasn't found" goto :end_script_with_err
goto :end_script_with_err )
)
:: create .sln
call "%premake_exe%" --file="premake5.lua" --dosstub --winrsrc --winsign --genproto --os=windows vs2022 call "%PREMAKE_EXE%" --file="premake5.lua" --genproto --dosstub --winrsrc --winsign --os=windows vs2022
if %errorlevel% neq 0 ( if %errorlevel% neq 0 (
goto :end_script_with_err goto :end_script_with_err
) )
if not exist "%sln_file%" (
1>&2 echo "project solution file wasn't found" :: check .sln
goto :end_script_with_err set "SLN_FILE=build\project\vs2022\win\gbe.sln"
) if not exist "%SLN_FILE%" (
1>&2 echo: .sln file wasn't found
:: -v:n make it so we can actually see what commands it runs goto :end_script_with_err
echo: & echo building debug x64 )
call "%my_vs_path%" /nologo "%sln_file%" /p:Configuration=debug /p:Platform=x64 -v:n -m:%build_threads%
if %errorlevel% neq 0 ( :: build .sln
goto :end_script_with_err set "BUILD_TYPES=release debug"
) set "BUILD_PLATFORMS=x64 Win32"
set "BUILD_TARGETS=api_regular api_experimental steamclient_experimental_stub steamclient_experimental steamclient_experimental_loader steamclient_experimental_extra lib_game_overlay_renderer tool_lobby_connect tool_generate_interfaces"
echo: & echo building debug x32
call "%my_vs_path%" /nologo "%sln_file%" /p:Configuration=debug /p:Platform=Win32 -v:n -m:%build_threads% for %%A in (%BUILD_TYPES%) do (
if %errorlevel% neq 0 ( set "BUILD_TYPE=%%A"
goto :end_script_with_err for %%B in (%BUILD_PLATFORMS%) do (
) set "BUILD_PLATFORM=%%B"
for %%C in (%BUILD_TARGETS%) do (
echo: & echo building release x64 set "BUILD_TARGET=%%C"
call "%my_vs_path%" /nologo "%sln_file%" /p:Configuration=release /p:Platform=x64 -v:n -m:%build_threads% echo. & echo: building !BUILD_TARGET! !BUILD_TYPE! !BUILD_PLATFORM!
if %errorlevel% neq 0 ( call "%MSBUILD_EXE%" /nologo -m:%MAX_THREADS% -v:n /p:Configuration=!BUILD_TYPE!,Platform=!BUILD_PLATFORM! /target:!BUILD_TARGET! "%SLN_FILE%"
goto :end_script_with_err if %errorlevel% neq 0 (
) goto :end_script_with_err
)
echo: & echo building release x32 )
call "%my_vs_path%" /nologo "%sln_file%" /p:Configuration=release /p:Platform=Win32 -v:n -m:%build_threads% )
if %errorlevel% neq 0 ( )
goto :end_script_with_err
) goto :end_script
:: exit without error
:: if all ok :end_script
:end_script endlocal
endlocal exit /b 0
exit /b 0
:: exit with error
:end_script_with_err
:: exit with error endlocal
:end_script_with_err exit /b 1
endlocal
exit /b 1 :: show help page
:help_page
echo: "%~nx0" [switches]
:help_page echo: switches:
echo: echo: --deps: rebuild third-party dependencies
echo "%~nx0" [switches] echo: --help: show this page
echo switches: goto :end_script
echo --deps: rebuild third-party dependencies
echo --help: show this page
exit /b 0

View File

@ -0,0 +1,3 @@
@echo off
call "build_win_premake.bat" --deps

View File

@ -1,87 +1,106 @@
@echo off @echo off
setlocal EnableDelayedExpansion
setlocal cd /d "%~dp0"
pushd "%~dp0"
set /a "MAX_THREADS=2"
set /a last_code=0 if defined NUMBER_OF_PROCESSORS (
:: use 70%
set "build_base_dir=build\win" set /a "MAX_THREADS=%NUMBER_OF_PROCESSORS% * 70 / 100"
set "out_dir=build\package\win" if %MAX_THREADS% lss 1 (
set /a "MAX_THREADS=1"
set /a MEM_PERCENT=90 )
set /a DICT_SIZE_MB=384 )
set "packager=third-party\deps\win\7za\7za.exe"
set "BUILD_DIR=build\win"
:: use 70% set "OUT_DIR=build\package\win"
set /a THREAD_COUNT=2
if defined NUMBER_OF_PROCESSORS ( if "%~1" equ "" (
set /a THREAD_COUNT=NUMBER_OF_PROCESSORS*70/100 1>&2 echo: missing build target folder arg
) goto :end_script_with_err
if %THREAD_COUNT% lss 2 ( )
set /a THREAD_COUNT=2
) set "TARGET_DIR=%BUILD_DIR%\%~1"
if not exist "%TARGET_DIR%\" (
if not exist "%packager%" ( 1>&2 echo: build target folder wasn't found
1>&2 echo [X] packager app wasn't found goto :end_script_with_err
set /a last_code=1 )
goto :script_end
) set /a "BUILD_DEBUG=0"
if "%~2" equ "1" (
if "%~1"=="" ( set /a "BUILD_DEBUG=1"
1>&2 echo [X] missing build folder )
set /a last_code=1
goto :script_end set /a "PKG_EXE_MEM_PERCENT=90"
) set /a "PKG_EXE_DICT_SIZE_MB=384"
set "PKG_EXE=third-party\deps\win\7za\7za.exe"
set "target_src_dir=%build_base_dir%\%~1" if not exist "%PKG_EXE%" (
if not exist "%target_src_dir%" ( 1>&2 echo: packager wasn't found
1>&2 echo [X] build folder wasn't found goto :end_script_with_err
set /a last_code=1 )
goto :script_end
) ::::::::::::::::::::::::::::::::::::::::::
echo: // copying readmes + example files
::::::::::::::::::::::::::::::::::::::::::
echo // copying readmes + example files xcopy /y /s /e /r "post_build\steam_settings.EXAMPLE\" "%TARGET_DIR%\steam_settings.EXAMPLE\"
xcopy /y /s /e /r "post_build\steam_settings.EXAMPLE\" "%target_src_dir%\steam_settings.EXAMPLE\"
copy /y "post_build\README.release.md" "%target_src_dir%\" copy /y "post_build\README.release.md" "%TARGET_DIR%\"
copy /y "CHANGELOG.md" "%target_src_dir%\" copy /y "CHANGELOG.md" "%TARGET_DIR%\"
copy /y "CREDITS.md" "%target_src_dir%\" copy /y "CREDITS.md" "%TARGET_DIR%\"
if "%~2"=="1" (
copy /y "post_build\README.debug.md" "%target_src_dir%\" if %BUILD_DEBUG% equ 1 (
) copy /y "post_build\README.debug.md" "%TARGET_DIR%\"
if exist "%target_src_dir%\experimental\" ( )
copy /y "post_build\README.experimental.md" "%target_src_dir%\experimental\"
) if exist "%TARGET_DIR%\experimental\" (
if exist "%target_src_dir%\steamclient_experimental\" ( copy /y "post_build\README.experimental.md" "%TARGET_DIR%\experimental\"
xcopy /y /s /e /r "post_build\win\ColdClientLoader.EXAMPLE\" "%target_src_dir%\steamclient_experimental\dll_injection.EXAMPLE\" )
copy /y "post_build\README.experimental_steamclient.md" "%target_src_dir%\steamclient_experimental\"
copy /y "tools\steamclient_loader\win\ColdClientLoader.ini" "%target_src_dir%\steamclient_experimental\" if exist "%TARGET_DIR%\steamclient_experimental\" (
) xcopy /y /s /e /r "post_build\win\ColdClientLoader.EXAMPLE\" "%TARGET_DIR%\steamclient_experimental\dll_injection.EXAMPLE\"
if exist "%target_src_dir%\tools\generate_interfaces\" ( copy /y "post_build\README.experimental_steamclient.md" "%TARGET_DIR%\steamclient_experimental\"
copy /y "post_build\README.generate_interfaces.md" "%target_src_dir%\tools\generate_interfaces\" copy /y "tools\steamclient_loader\win\ColdClientLoader.ini" "%TARGET_DIR%\steamclient_experimental\"
) )
if exist "%target_src_dir%\tools\lobby_connect\" (
copy /y "post_build\README.lobby_connect.md" "%target_src_dir%\tools\lobby_connect\" if exist "%TARGET_DIR%\tools\generate_interfaces\" (
) copy /y "post_build\README.generate_interfaces.md" "%TARGET_DIR%\tools\generate_interfaces\"
:::::::::::::::::::::::::::::::::::::::::: )
set "archive_dir=%out_dir%\%~1" if exist "%TARGET_DIR%\tools\lobby_connect\" (
if exist "%archive_dir%\" ( copy /y "post_build\README.lobby_connect.md" "%TARGET_DIR%\tools\lobby_connect\"
rmdir /s /q "%archive_dir%" )
) ::::::::::::::::::::::::::::::::::::::::::
set "archive_file="
for %%A in ("%archive_dir%") do ( set "ACHIVE_DIR=%OUT_DIR%\%~1"
set "archive_file=%%~dpAemu-win-%%~nxA.7z" if exist "%ACHIVE_DIR%\" (
) rmdir /s /q "%ACHIVE_DIR%"
)
for %%A in ("%archive_dir%") do (
mkdir "%%~dpA" for %%A in ("%ACHIVE_DIR%") do (
) md "%%~dpA"
"%packager%" a "%archive_file%" ".\%target_src_dir%" -t7z -slp -ssw -mx -myx -mmemuse=p%MEM_PERCENT% -ms=on -mqs=off -mf=on -mhc+ -mhe- -m0=LZMA2:d=%DICT_SIZE_MB%m -mmt=%THREAD_COUNT% -mmtf+ -mtm- -mtc- -mta- -mtr+ )
set "ACHIVE_FILE="
:script_end for %%A in ("%ACHIVE_DIR%") do (
popd set "ACHIVE_FILE=%%~dpAemu-win-%%~nxA.7z"
endlocal & ( )
exit /b %last_code%
) if exist "%ACHIVE_FILE%" (
del /f /s /q "%ACHIVE_FILE%"
)
call "%PKG_EXE%" a "%ACHIVE_FILE%" ".\%TARGET_DIR%" -t7z -xr^^!*.lib -xr^^!*.exp -slp -ssw -mx -myx -mmemuse=p%PKG_EXE_MEM_PERCENT% -ms=on -mqs=off -mf=on -mhc+ -mhe- -m0=LZMA2:d=%PKG_EXE_DICT_SIZE_MB%m -mmt=%MAX_THREADS% -mmtf+ -mtm- -mtc- -mta- -mtr+
if %errorlevel% neq 0 (
goto :end_script_with_err
)
goto :end_script
:: exit without error
:end_script
endlocal
exit /b 0
:: exit with error
:end_script_with_err
endlocal
exit /b 1

3
package_win_debug.bat Normal file
View File

@ -0,0 +1,3 @@
@echo off
call "package_win.bat" vs2022/debug 1

3
package_win_release.bat Normal file
View File

@ -0,0 +1,3 @@
@echo off
call "package_win.bat" vs2022/release