-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.bat
More file actions
160 lines (138 loc) · 4.57 KB
/
run.bat
File metadata and controls
160 lines (138 loc) · 4.57 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
@echo off
color 0F
setlocal EnableDelayedExpansion
:main_install
echo.
echo ####################################################
echo # DEPLOY SCRIPT #
echo ####################################################
echo.
echo [[34mSTATUS[0m] Deployment initiated
echo [[34mCHECK[0m] Checking dependencies
echo.
call :check_for_rust
set "RUST_STATUS=!errorlevel!"
if !RUST_STATUS! equ 0 (
echo [[32mOK[0m] Rust is installed
) else (
echo [[31mERROR[0m] Rust is missing or incorrectly installed
)
if !RUST_STATUS! neq 0 (
echo.
echo [[33mWARNING[0m] Missing dependencies detected
echo [[33mQUESTION[0m] Install Rust? [Y/N]
set /p CONFIRM=^>
if /i "!CONFIRM!" == "Y" (
call :install_rust && cls || goto :error
) else (
echo.
echo [[33mWARNING[0m] Proceeding without dependencies may cause failures
echo [[33mQUESTION[0m] Continue? [Y/N]
set /p BUILD_ANYWAY=^>
if /i "!BUILD_ANYWAY!" == "N" exit /b 1
)
)
set "PATH=%USERPROFILE%\.cargo\bin;%USERPROFILE%\VSBuildTools\VC\Auxiliary\Build;%USERPROFILE%\LLVM\bin;!PATH!"
echo.
echo [[34mSTATUS[0m] Environment configured successfully
echo [[34mACTION[0m] Starting deployment...
call :main_run
:error
echo.
echo [[31mERROR[0m] Deployment failed
echo.
echo [[33mOPTION[0m] Would you like to:
echo [[33m1[0m] Reinstall Rust
echo [[33m2[0m] Re-run deploy script
echo [[33m3[0m] Exit
set /p OPTION=^>
if "%OPTION%" == "1" (
call :install_rust && (
echo [[32mOK[0m] Reinstallation successful
goto :main_install
) || (
echo [[31mERROR[0m] Reinstallation failed
pause >nul & exit /b 1
)
)else if "%OPTION%" == "2" (
call :main_run & goto :error
) else (
echo [[31mERROR[0m] Exiting deployment
pause >nul & exit /b 1
)
:check_for_rust
echo [[34mSTATUS[0m] Checking for existing Rust installation...
if exist "%USERPROFILE%\.cargo\bin\cargo.exe" exit /b 0
exit /b 1
:install_rust
cls
echo.
echo ####################################################
echo # RUST INSTALLER SCRIPT #
echo ####################################################
echo.
echo [[34mSELECT[0m] Target triple:
echo [[32mD[0m] x86_64-pc-windows-msvc (default)
echo [[32mG[0m] x86_64-pc-windows-gnu
echo [Custom] Enter your own target triple
set /p TARGET_TRIPLE=^>
set "INSTALL=0"
if not defined TARGET_TRIPLE (
echo [[34mSTATUS[0m] Setting toolchain to default
set "TARGET_TRIPLE=x86_64-pc-windows-msvc"
) else if /i "%TARGET_TRIPLE%" == "D" (
set "TARGET_TRIPLE=x86_64-pc-windows-msvc"
) else if /i "%TARGET_TRIPLE%" == "G" (
set "TARGET_TRIPLE=x86_64-pc-windows-gnu"
)
set "RUSTUP_URL=https://win.rustup.rs/x86_64"
if "%PROCESSOR_ARCHITECTURE%" == "x86" set "RUSTUP_URL=https://win.rustup.rs/i686"
echo [[34mDOWNLOAD[0m] Installer...
bitsadmin /transfer "RustInstall" /dynamic /priority high "%RUSTUP_URL%" "%TEMP%\rustup-init.exe" || (
echo [[31mERROR[0m] Failed to download installer
exit /b 1
)
"%TEMP%\rustup-init.exe" -y --default-toolchain "stable-%TARGET_TRIPLE%" -t %TARGET_TRIPLE%
if errorlevel 1 (
echo [[31mERROR[0m] Installation failed
exit /b 1
)
if not "%TARGET_TRIPLE%"== "x86_64-pc-windows-gnu" (
echo [[34mCONFIG[0m] Setting LLD linker...
(
echo [build]
echo rustflags = ["-C", "linker=rust-lld"]
) >> "%USERPROFILE%\.cargo\config.toml"
)
rustup component add cargo rustc 2>nul
echo [[32mOK[0m] Rust installed successfully
set "PATH=%USERPROFILE%\.cargo\bin;!PATH!"
echo [[34mSTATUS[0m] Added Rust to system PATH
exit /b 0
:main_run
cls
echo.
echo ####################################################
echo # RUN SCRIPT #
echo ####################################################
echo.
echo [[34mCHECK[0m] Verifying Rust installation...
if not exist "%USERPROFILE%\.cargo\bin\cargo.exe" (
echo [[31mERROR[0m] Rust/Cargo not found, install that first.
pause >nul & exit /b 1
)
echo [[34mCHECK[0m] Validating project directory...
if not exist "Cargo.toml" (
echo [[31mERROR[0m] No Cargo.toml found. Run from project root.
echo Current directory: %CD%
pause >nul & exit /b 1
)
echo [[34mCOMPILING[0m] Compiling in release mode...
cargo run --release || (
echo [[31mERROR[0m] Build or run failed
pause >nul & exit /b 1
)
for /f "tokens=2 delims== " %%a in ('findstr "^name *= *" Cargo.toml') do set "CRATE_NAME=%%a"
set "CRATE_NAME=%CRATE_NAME:"=%"
echo [[32mOK[0m] Release build completed and executed successfully!
pause >nul & exit /b 0