-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.bat
More file actions
169 lines (146 loc) · 4.52 KB
/
build.bat
File metadata and controls
169 lines (146 loc) · 4.52 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
@echo off
setlocal enabledelayedexpansion
:: Build script for pomodorust (Windows)
:: Usage: build.bat [release|fast|debug] [--clean] [--sign]
set "PROJECT_ROOT=%~dp0"
set "DIST_DIR=%PROJECT_ROOT%dist"
set "PROFILE=release"
set "CLEAN=0"
set "SIGN=0"
:: Parse arguments
:parse_args
if "%~1"=="" goto :find_vs
if /i "%~1"=="release" set "PROFILE=release" & shift & goto :parse_args
if /i "%~1"=="fast" set "PROFILE=release-fast" & shift & goto :parse_args
if /i "%~1"=="debug" set "PROFILE=debug" & shift & goto :parse_args
if /i "%~1"=="--clean" set "CLEAN=1" & shift & goto :parse_args
if /i "%~1"=="-c" set "CLEAN=1" & shift & goto :parse_args
if /i "%~1"=="--sign" set "SIGN=1" & shift & goto :parse_args
if /i "%~1"=="-s" set "SIGN=1" & shift & goto :parse_args
if /i "%~1"=="--help" goto :show_help
if /i "%~1"=="-h" goto :show_help
echo Unknown option: %~1
exit /b 1
:show_help
echo Usage: build.bat [profile] [options]
echo.
echo Profiles:
echo release Optimized for size (default)
echo fast Optimized for speed
echo debug Debug build
echo.
echo Options:
echo --clean, -c Clean before building
echo --sign, -s Sign executable after build
echo --help, -h Show this help
exit /b 0
:find_vs
:: Auto-detect Visual Studio
set "VCVARS="
:: Try VS 2022
for %%p in (
"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
"C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvars64.bat"
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
"C:\Program Files\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
) do (
if exist %%p (
set "VCVARS=%%~p"
goto :found_vs
)
)
:: Try VS 2019
for %%p in (
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
) do (
if exist %%p (
set "VCVARS=%%~p"
goto :found_vs
)
)
:: Try vswhere
where vswhere >nul 2>&1
if %errorlevel%==0 (
for /f "usebackq tokens=*" %%i in (`vswhere -latest -property installationPath`) do (
set "VCVARS=%%i\VC\Auxiliary\Build\vcvars64.bat"
if exist "!VCVARS!" goto :found_vs
)
)
echo Warning: Visual Studio not found, attempting build anyway...
goto :build
:found_vs
echo Setting up Visual Studio environment...
call "%VCVARS%" >nul 2>&1
:build
cd /d "%PROJECT_ROOT%"
:: Clean if requested
if "%CLEAN%"=="1" (
echo Cleaning...
cargo clean
if exist "%DIST_DIR%" rmdir /s /q "%DIST_DIR%"
)
:: Build
echo Building with profile: %PROFILE%
if "%PROFILE%"=="debug" (
cargo build
set "SOURCE_DIR=%PROJECT_ROOT%target\debug"
) else (
cargo build --profile %PROFILE%
set "SOURCE_DIR=%PROJECT_ROOT%target\%PROFILE%"
)
if %errorlevel% neq 0 (
echo Build failed!
exit /b 1
)
:: Create dist directory
if not exist "%DIST_DIR%" mkdir "%DIST_DIR%"
set "BINARY=pomodorust.exe"
set "SOURCE_PATH=%SOURCE_DIR%\%BINARY%"
set "DEST_PATH=%DIST_DIR%\%BINARY%"
if not exist "%SOURCE_PATH%" (
echo Binary not found: %SOURCE_PATH%
exit /b 1
)
:: Try UPX compression for release builds
set "COMPRESSED=0"
if not "%PROFILE%"=="debug" (
where upx >nul 2>&1
if %errorlevel%==0 (
echo Compressing with UPX...
upx --best --lzma "%SOURCE_PATH%" -f -o "%DEST_PATH%" >nul 2>&1
if %errorlevel%==0 set "COMPRESSED=1"
)
)
if "%COMPRESSED%"=="0" (
copy /y "%SOURCE_PATH%" "%DEST_PATH%" >nul
)
:: Sign if requested
if "%SIGN%"=="1" (
echo.
powershell -ExecutionPolicy Bypass -File "%PROJECT_ROOT%scripts\sign.ps1" -ExePath "%DEST_PATH%"
)
:: Create ZIP archive
set "VERSION="
for /f "tokens=3" %%v in ('findstr /r "^version" Cargo.toml') do (
set "VERSION=%%~v"
goto :got_version
)
:got_version
set "ZIP_NAME=pomodorust-v%VERSION%-windows-x64.zip"
set "ZIP_PATH=%DIST_DIR%\%ZIP_NAME%"
if exist "%ZIP_PATH%" del "%ZIP_PATH%"
echo Creating ZIP archive...
powershell -Command "Compress-Archive -Path '%DEST_PATH%' -DestinationPath '%ZIP_PATH%' -Force"
:: Show result
echo.
echo Output: %DEST_PATH%
for %%A in ("%DEST_PATH%") do echo Size: %%~zA bytes
if exist "%ZIP_PATH%" (
echo Archive: %ZIP_PATH%
for %%A in ("%ZIP_PATH%") do echo Archive size: %%~zA bytes
)
echo.
echo Done!