1
1
use colored:: * ;
2
2
3
- pub struct Logger ;
4
-
5
- impl Logger {
6
- pub fn info ( msg : & str ) {
7
- println ! ( "{} {}" , "[xtask]" . green( ) . bold( ) , msg) ;
8
- }
3
+ pub fn info ( msg : & str ) {
4
+ println ! ( "{} {}" , "[xtask]" . green( ) . bold( ) , msg) ;
5
+ }
9
6
10
- pub fn error ( msg : & str ) {
11
- println ! ( "{} {}" , "[xtask]" . red( ) . bold( ) , msg) ;
12
- }
7
+ pub fn error ( msg : & str ) {
8
+ println ! ( "{} {}" , "[xtask]" . red( ) . bold( ) , msg) ;
9
+ }
13
10
14
- pub fn warning ( msg : & str ) {
15
- println ! ( "{} {}" , "[xtask]" . yellow( ) . bold( ) , msg) ;
16
- }
11
+ pub fn warning ( msg : & str ) {
12
+ println ! ( "{} {}" , "[xtask]" . yellow( ) . bold( ) , msg) ;
17
13
}
18
14
19
15
pub fn install_env ( env : & str ) {
20
16
match env {
21
17
"Python" => {
22
- Logger :: info ( "Checking if Python is already installed..." ) ;
18
+ info ( "Checking if Python is already installed..." ) ;
23
19
println ! ( ) ;
24
20
25
21
// Check if python or python3 is installed
@@ -40,11 +36,11 @@ pub fn install_env(env: &str) {
40
36
} ;
41
37
42
38
if check_installed {
43
- Logger :: info ( "Python is already installed. No need to reinstall." ) ;
39
+ info ( "Python is already installed. No need to reinstall." ) ;
44
40
return ;
45
41
}
46
42
47
- Logger :: info ( "Python not detected. Installing Python environment..." ) ;
43
+ info ( "Python not detected. Installing Python environment..." ) ;
48
44
49
45
#[ cfg( target_os = "windows" ) ]
50
46
let output = std:: process:: Command :: new ( "powershell" )
@@ -90,26 +86,26 @@ pub fn install_env(env: &str) {
90
86
. arg ( "brew install python" )
91
87
. status ( )
92
88
} else {
93
- Logger :: error (
89
+ error (
94
90
"No supported package manager found (apt-get, dnf, yum, pacman). Please install Python manually." ,
95
91
) ;
96
92
return ;
97
93
}
98
94
} ;
99
95
100
96
match output {
101
- Ok ( status) if status. success ( ) => Logger :: info ( "Python installation completed!" ) ,
102
- Ok ( status) => Logger :: error ( & format ! (
97
+ Ok ( status) if status. success ( ) => info ( "Python installation completed!" ) ,
98
+ Ok ( status) => error ( & format ! (
103
99
"Python installation failed, exit code: {:?}" ,
104
100
status. code( )
105
101
) ) ,
106
- Err ( e) => Logger :: error ( & format ! (
102
+ Err ( e) => error ( & format ! (
107
103
"Error occurred while running install command: {e}"
108
104
) ) ,
109
105
}
110
106
}
111
107
"xmake" => {
112
- Logger :: info ( "Checking if xmake is already installed..." ) ;
108
+ info ( "Checking if xmake is already installed..." ) ;
113
109
println ! ( ) ;
114
110
115
111
// Check if xmake is installed
@@ -121,11 +117,11 @@ pub fn install_env(env: &str) {
121
117
. unwrap_or ( false ) ;
122
118
123
119
if check_installed {
124
- Logger :: info ( "xmake is already installed. No need to reinstall." ) ;
120
+ info ( "xmake is already installed. No need to reinstall." ) ;
125
121
return ;
126
122
}
127
123
128
- Logger :: info ( "xmake not detected. Installing xmake environment..." ) ;
124
+ info ( "xmake not detected. Installing xmake environment..." ) ;
129
125
130
126
#[ cfg( target_os = "windows" ) ]
131
127
let output = std:: process:: Command :: new ( "powershell" )
@@ -142,18 +138,18 @@ pub fn install_env(env: &str) {
142
138
. status ( ) ;
143
139
144
140
match output {
145
- Ok ( status) if status. success ( ) => Logger :: info ( "xmake installation completed!" ) ,
146
- Ok ( status) => Logger :: error ( & format ! (
141
+ Ok ( status) if status. success ( ) => info ( "xmake installation completed!" ) ,
142
+ Ok ( status) => error ( & format ! (
147
143
"xmake installation failed, exit code: {:?}" ,
148
144
status. code( )
149
145
) ) ,
150
- Err ( e) => Logger :: error ( & format ! (
146
+ Err ( e) => error ( & format ! (
151
147
"Error occurred while running install command: {e}"
152
148
) ) ,
153
149
}
154
150
}
155
151
"CUDA" => {
156
- Logger :: info ( "Checking if CUDA Toolkit is already installed..." ) ;
152
+ info ( "Checking if CUDA Toolkit is already installed..." ) ;
157
153
println ! ( ) ;
158
154
159
155
// Check if cuda toolkit is installed
@@ -165,7 +161,7 @@ pub fn install_env(env: &str) {
165
161
. unwrap_or ( false ) ;
166
162
167
163
if check_installed {
168
- Logger :: info ( "CUDA Toolkit is already installed. No need to reinstall." ) ;
164
+ info ( "CUDA Toolkit is already installed. No need to reinstall." ) ;
169
165
return ;
170
166
}
171
167
@@ -183,57 +179,57 @@ pub fn install_env(env: &str) {
183
179
let smi_info = String :: from_utf8_lossy ( & output. stdout ) ;
184
180
for line in smi_info. lines ( ) {
185
181
if line. contains ( "CUDA Version" ) {
186
- Logger :: info ( & format ! ( "Detected by nvidia-smi: {line}" ) ) ;
182
+ info ( & format ! ( "Detected by nvidia-smi: {line}" ) ) ;
187
183
}
188
184
if let Some ( idx) = line. find ( "CUDA Version:" ) {
189
185
// extract the CUDA version number
190
186
let version_str = line[ idx + "CUDA Version:" . len ( ) ..]
191
187
. split_whitespace ( )
192
188
. next ( )
193
189
. unwrap_or ( "" ) ;
194
- Logger :: info ( & format ! (
190
+ info ( & format ! (
195
191
"The highest CUDA version supported by your driver is {version_str}"
196
192
) ) ;
197
- Logger :: warning (
193
+ warning (
198
194
"You can also visit https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html to find the CUDA version compatible with your GPU driver." ,
199
195
) ;
200
196
}
201
197
}
202
- Logger :: info (
198
+ info (
203
199
"Please make sure to install a CUDA Toolkit version compatible with your driver." ,
204
200
) ;
205
201
} else {
206
- Logger :: error (
202
+ error (
207
203
"nvidia-smi not found. Please make sure you have an NVIDIA GPU and drivers installed." ,
208
204
) ;
209
205
}
210
206
211
207
println ! ( ) ;
212
- Logger :: warning (
208
+ warning (
213
209
"Please visit https://developer.nvidia.com/cuda-toolkit-archive to select and download the appropriate CUDA version for your driver." ,
214
210
) ;
215
211
}
216
212
"OpenCL" => {
217
- Logger :: info (
213
+ info (
218
214
"The current automatic installation script only supports OpenCL installation for Intel CPU on Windows or Ubuntu systems." ,
219
215
) ;
220
- Logger :: info ( "Checking if OpenCL is already installed..." ) ;
216
+ info ( "Checking if OpenCL is already installed..." ) ;
221
217
println ! ( ) ;
222
218
223
219
// Check if OpenCL is installed
224
220
#[ cfg( target_os = "windows" ) ]
225
221
{
226
222
let clinfo_path = std:: path:: Path :: new ( "clinfo.exe" ) ;
227
223
if !clinfo_path. exists ( ) {
228
- Logger :: info ( "Downloading clinfo tool..." ) ;
224
+ info ( "Downloading clinfo tool..." ) ;
229
225
let download_status = std:: process:: Command :: new ( "curl" )
230
226
. args ( [ "-o" , "clinfo.exe" , "https://github.com/ahoylabs/clinfo/releases/download/master-d2baa06/clinfo.exe" ] )
231
227
. status ( ) ;
232
228
233
229
if let Err ( e) = download_status {
234
- Logger :: error ( & format ! ( "Failed to download clinfo: {}" , e) ) ;
235
- Logger :: warning ( "You may need to enable proxy." ) ;
236
- Logger :: warning (
230
+ error ( & format ! ( "Failed to download clinfo: {}" , e) ) ;
231
+ warning ( "You may need to enable proxy." ) ;
232
+ warning (
237
233
"You can also manually download from https://github.com/ahoylabs/clinfo/releases/download/master-d2baa06/clinfo.exe" ,
238
234
) ;
239
235
return ;
@@ -251,19 +247,19 @@ pub fn install_env(env: &str) {
251
247
{
252
248
if let Some ( number) = line. split_whitespace ( ) . last ( ) {
253
249
if number == "0" {
254
- Logger :: info ( "OpenCL is not installed." ) ;
250
+ info ( "OpenCL is not installed." ) ;
255
251
} else {
256
- Logger :: info ( & format ! (
252
+ info ( & format ! (
257
253
"OpenCL is installed. Number of platforms: {}" ,
258
254
number
259
255
) ) ;
260
256
return ;
261
257
}
262
258
} else {
263
- Logger :: error ( "Failed to parse the number of platforms." ) ;
259
+ error ( "Failed to parse the number of platforms." ) ;
264
260
}
265
261
} else {
266
- Logger :: error ( "Failed to find 'Number of platforms' in clinfo output." ) ;
262
+ error ( "Failed to find 'Number of platforms' in clinfo output." ) ;
267
263
}
268
264
}
269
265
#[ cfg( not( target_os = "windows" ) ) ]
@@ -280,20 +276,18 @@ pub fn install_env(env: &str) {
280
276
281
277
if !has_cmd ( "clinfo" ) {
282
278
if has_cmd ( "apt" ) {
283
- Logger :: info ( "Installing clinfo tool..." ) ;
279
+ info ( "Installing clinfo tool..." ) ;
284
280
let install_status = std:: process:: Command :: new ( "sh" )
285
281
. arg ( "-c" )
286
282
. arg ( "sudo apt update && sudo apt install opencl-headers ocl-icd-opencl-dev -y" )
287
283
. status ( ) ;
288
284
289
285
if let Err ( e) = install_status {
290
- Logger :: error ( & format ! ( "Failed to install clinfo: {}" , e) ) ;
286
+ error ( & format ! ( "Failed to install clinfo: {}" , e) ) ;
291
287
return ;
292
288
}
293
289
} else {
294
- Logger :: error (
295
- "Unsupported package manager. Please install clinfo manually." ,
296
- ) ;
290
+ error ( "Unsupported package manager. Please install clinfo manually." ) ;
297
291
return ;
298
292
}
299
293
}
@@ -309,23 +303,23 @@ pub fn install_env(env: &str) {
309
303
{
310
304
if let Some ( number) = line. split_whitespace ( ) . last ( ) {
311
305
if number == "0" {
312
- Logger :: info ( "OpenCL is not installed." ) ;
306
+ info ( "OpenCL is not installed." ) ;
313
307
} else {
314
- Logger :: info ( & format ! (
308
+ info ( & format ! (
315
309
"OpenCL is installed. Number of platforms: {}" ,
316
310
number
317
311
) ) ;
318
312
return ;
319
313
}
320
314
} else {
321
- Logger :: error ( "Failed to parse the number of platforms." ) ;
315
+ error ( "Failed to parse the number of platforms." ) ;
322
316
}
323
317
} else {
324
- Logger :: error ( "Failed to find 'Number of platforms' in clinfo output." ) ;
318
+ error ( "Failed to find 'Number of platforms' in clinfo output." ) ;
325
319
}
326
320
}
327
321
328
- Logger :: info ( "OpenCL not detected. Installing OpenCL environment..." ) ;
322
+ info ( "OpenCL not detected. Installing OpenCL environment..." ) ;
329
323
330
324
#[ cfg( target_os = "windows" ) ]
331
325
{
@@ -334,18 +328,18 @@ pub fn install_env(env: &str) {
334
328
. status ( ) ;
335
329
336
330
if let Err ( e) = download_status {
337
- Logger :: error ( & format ! (
331
+ error ( & format ! (
338
332
"Failed to download w_opencl_runtime_p_2025.1.0.972: {}" ,
339
333
e
340
334
) ) ;
341
- Logger :: warning ( "You may need to enable proxy." ) ;
342
- Logger :: warning (
335
+ warning ( "You may need to enable proxy." ) ;
336
+ warning (
343
337
"You can also manually download from https://registrationcenter-download.intel.com/akdlm/IRC_NAS/b6dccdb7-b503-41ea-bd4b-a78e9c2d8dd6/w_opencl_runtime_p_2025.1.0.972.exe" ,
344
338
) ;
345
339
return ;
346
340
}
347
341
348
- Logger :: warning (
342
+ warning (
349
343
"Download completed. Please manually execute 'w_opencl_runtime_p_2025.1.0.972.exe' to install OpenCL for Intel CPU." ,
350
344
) ;
351
345
}
@@ -362,18 +356,18 @@ pub fn install_env(env: &str) {
362
356
} ;
363
357
364
358
if has_cmd ( "apt" ) {
365
- Logger :: info ( "Installing opencl-headers..." ) ;
359
+ info ( "Installing opencl-headers..." ) ;
366
360
let install_status = std:: process:: Command :: new ( "sh" )
367
361
. arg ( "-c" )
368
362
. arg ( "sudo apt update && sudo apt install opencl-headers ocl-icd-opencl-dev -y" )
369
363
. status ( ) ;
370
364
371
365
if let Err ( e) = install_status {
372
- Logger :: error ( & format ! ( "Failed to install OpenCL: {}" , e) ) ;
366
+ error ( & format ! ( "Failed to install OpenCL: {}" , e) ) ;
373
367
return ;
374
368
}
375
369
376
- Logger :: info ( "Installing Intel OpenCL runtime..." ) ;
370
+ info ( "Installing Intel OpenCL runtime..." ) ;
377
371
let setup_status = std:: process:: Command :: new ( "sh" )
378
372
. arg ( "-c" )
379
373
. arg (
@@ -385,23 +379,23 @@ pub fn install_env(env: &str) {
385
379
. status ( ) ;
386
380
387
381
if let Err ( e) = setup_status {
388
- Logger :: error ( & format ! ( "Failed to set up Intel OpenCL repository: {}" , e) ) ;
382
+ error ( & format ! ( "Failed to set up Intel OpenCL repository: {}" , e) ) ;
389
383
return ;
390
384
}
391
385
392
- Logger :: warning (
386
+ warning (
393
387
"Intel OpenCL runtime installation requires a proxy and may take time." ,
394
388
) ;
395
- Logger :: warning (
389
+ warning (
396
390
"Please manually execute the following command after enabling the proxy:" ,
397
391
) ;
398
- Logger :: warning ( "sudo apt install -y intel-oneapi-runtime-opencl" ) ;
392
+ warning ( "sudo apt install -y intel-oneapi-runtime-opencl" ) ;
399
393
} else {
400
- Logger :: error ( "Unsupported package manager. Please install OpenCL manually." ) ;
394
+ error ( "Unsupported package manager. Please install OpenCL manually." ) ;
401
395
}
402
396
}
403
397
}
404
- _ => Logger :: error ( & format ! (
398
+ _ => error ( & format ! (
405
399
"Automatic installation for this environment is not supported: {env}"
406
400
) ) ,
407
401
}
0 commit comments