@@ -12,13 +12,15 @@ fn is_rustc_installed() -> bool {
1212 . map ( |o| o. status . success ( ) )
1313 . unwrap_or ( false )
1414}
15+
1516fn is_cargo_installed ( ) -> bool {
1617 Command :: new ( "cargo" )
1718 . arg ( "-V" )
1819 . output ( )
1920 . map ( |o| o. status . success ( ) )
2021 . unwrap_or ( false )
2122}
23+
2224fn is_node_installed ( ) -> bool {
2325 Command :: new ( "node" )
2426 . arg ( "-v" )
@@ -34,11 +36,12 @@ fn is_trunk_installed() -> bool {
3436 . map ( |o| o. status . success ( ) )
3537 . unwrap_or ( false )
3638}
39+
3740fn is_appropriate_tauri_cli_installed ( alpha : bool ) -> bool {
3841 let check = |o : Output | match o. status . success ( ) {
39- true if alpha => String :: from_utf8_lossy ( & o. stderr )
42+ true => String :: from_utf8_lossy ( & o. stdout )
4043 . split_once ( ' ' )
41- . map ( |( _, v) | v. starts_with ( '2' ) )
44+ . map ( |( _, v) | v. starts_with ( if alpha { '2' } else { '1' } ) )
4245 . unwrap_or ( false ) ,
4346 s => s,
4447 } ;
@@ -49,6 +52,7 @@ fn is_appropriate_tauri_cli_installed(alpha: bool) -> bool {
4952 . or_else ( |_| Command :: new ( "tauri" ) . arg ( "-V" ) . output ( ) . map ( check) )
5053 . unwrap_or ( false )
5154}
55+
5256fn is_wasm32_installed ( ) -> bool {
5357 Command :: new ( "rustup" )
5458 . args ( [ "target" , "list" , "--installed" ] )
@@ -59,6 +63,7 @@ fn is_wasm32_installed() -> bool {
5963 } )
6064 . unwrap_or ( false )
6165}
66+
6267#[ cfg( windows) ]
6368fn is_webview2_installed ( ) -> bool {
6469 let powershell_path = std:: env:: var ( "SYSTEMROOT" ) . map_or_else (
@@ -98,6 +103,7 @@ fn is_webview2_installed() -> bool {
98103
99104 false
100105}
106+
101107#[ cfg( any(
102108 target_os = "linux" ,
103109 target_os = "dragonfly" ,
@@ -116,6 +122,7 @@ fn is_webkit2gtk_installed(alpha: bool) -> bool {
116122 . map ( |o| o. status . success ( ) )
117123 . unwrap_or ( false )
118124}
125+
119126#[ cfg( any(
120127 target_os = "linux" ,
121128 target_os = "dragonfly" ,
@@ -140,6 +147,13 @@ fn is_xcode_command_line_tools_installed() -> bool {
140147 . unwrap_or ( false )
141148}
142149
150+ struct Dep < ' a > {
151+ name : & ' a str ,
152+ instruction : String ,
153+ exists : & ' a dyn Fn ( ) -> bool ,
154+ skip : bool ,
155+ }
156+
143157pub fn print_missing_deps ( pkg_manager : PackageManager , template : Template , alpha : bool ) {
144158 let rustc_installed = is_rustc_installed ( ) ;
145159 let cargo_installed = is_cargo_installed ( ) ;
@@ -154,124 +168,124 @@ pub fn print_missing_deps(pkg_manager: PackageManager, template: Template, alpha
154168 let ( webkit2gtk_installed, rsvg2_installed) =
155169 ( is_webkit2gtk_installed ( alpha) , is_rsvg2_installed ( ) ) ;
156170
157- let deps: & [ ( & str , String , & dyn Fn ( ) -> bool , bool ) ] = & [
158- (
159- "Rust" ,
160- format ! ( "Visit {BLUE}{BOLD}https://www.rust-lang.org/learn/get-started#installing-rust{RESET}" ) ,
161- & || rustc_installed && cargo_installed,
162- rustc_installed || cargo_installed,
163- ) ,
164- (
165- "rustc" ,
166- format ! ( "Visit {BLUE}{BOLD}https://www.rust-lang.org/learn/get-started#installing-rust{RESET} to install Rust" ) ,
167- & || rustc_installed,
168- !rustc_installed && !cargo_installed,
169- ) ,
170- (
171- "Cargo" ,
172- format ! ( "Visit {BLUE}{BOLD}https://www.rust-lang.org/learn/get-started#installing-rust{RESET} to install Rust" ) ,
173- & || cargo_installed,
174- !rustc_installed && !cargo_installed,
175- ) ,
176- (
177- "Tauri CLI" ,
178- if alpha {
171+ let deps: & [ Dep < ' _ > ] = & [
172+ Dep {
173+ name : "Rust" ,
174+ instruction : format ! ( "Visit {BLUE}{BOLD}https://www.rust-lang.org/learn/get-started#installing-rust{RESET}" ) ,
175+ exists : & || rustc_installed && cargo_installed,
176+ skip : rustc_installed || cargo_installed,
177+ } ,
178+ Dep {
179+ name : "rustc" ,
180+ instruction : format ! ( "Visit {BLUE}{BOLD}https://www.rust-lang.org/learn/get-started#installing-rust{RESET} to install Rust" ) ,
181+ exists : & || rustc_installed,
182+ skip : !rustc_installed && !cargo_installed,
183+ } ,
184+ Dep {
185+ name : "Cargo" ,
186+ instruction : format ! ( "Visit {BLUE}{BOLD}https://www.rust-lang.org/learn/get-started#installing-rust{RESET} to install Rust" ) ,
187+ exists : & || cargo_installed,
188+ skip : !rustc_installed && !cargo_installed,
189+ } ,
190+ Dep {
191+ name : "Tauri CLI" ,
192+ instruction : if alpha {
179193 format ! ( "Run `{BLUE}{BOLD}cargo install tauri-cli --version '^2.0.0-alpha'{RESET}`" )
180194 } else {
181195 format ! ( "Run `{BLUE}{BOLD}cargo install tauri-cli{RESET}`" )
182196 } ,
183- & || is_appropriate_tauri_cli_installed ( alpha) ,
184- pkg_manager. is_node ( ) || !template. needs_tauri_cli ( ) ,
185- ) ,
186- (
187- "Trunk" ,
188- format ! ( "Run `{BLUE}{BOLD}cargo install trunk{RESET}`" ) ,
189- & is_trunk_installed,
190- pkg_manager. is_node ( ) || !template. needs_trunk ( ) ,
191- ) ,
192- (
193- "wasm32 target" ,
194- format ! ( "Run `{BLUE}{BOLD}rustup target add wasm32-unknown-unknown{RESET}`" ) ,
195- & is_wasm32_installed,
196- pkg_manager. is_node ( ) || !template. needs_wasm32_target ( ) ,
197- ) ,
198- (
199- "Node.js" ,
200- format ! ( "Visit {BLUE}{BOLD}https://nodejs.org/en/{RESET}" ) ,
201- & is_node_installed,
202- !pkg_manager. is_node ( ) ,
203- ) ,
197+ exists : & || is_appropriate_tauri_cli_installed ( alpha) ,
198+ skip : pkg_manager. is_node ( ) || !template. needs_tauri_cli ( ) ,
199+ } ,
200+ Dep {
201+ name : "Trunk" ,
202+ instruction : format ! ( "Run `{BLUE}{BOLD}cargo install trunk{RESET}`" ) ,
203+ exists : & is_trunk_installed,
204+ skip : pkg_manager. is_node ( ) || !template. needs_trunk ( ) ,
205+ } ,
206+ Dep {
207+ name : "wasm32 target" ,
208+ instruction : format ! ( "Run `{BLUE}{BOLD}rustup target add wasm32-unknown-unknown{RESET}`" ) ,
209+ exists : & is_wasm32_installed,
210+ skip : pkg_manager. is_node ( ) || !template. needs_wasm32_target ( ) ,
211+ } ,
212+ Dep {
213+ name : "Node.js" ,
214+ instruction : format ! ( "Visit {BLUE}{BOLD}https://nodejs.org/en/{RESET}" ) ,
215+ exists : & is_node_installed,
216+ skip : !pkg_manager. is_node ( ) ,
217+ } ,
204218 #[ cfg( windows) ]
205- (
206- "Webview2" ,
207- format ! ( "Visit {BLUE}{BOLD}https://go.microsoft.com/fwlink/p/?LinkId=2124703{RESET}" ) ,
208- & is_webview2_installed,
209- false ,
210- ) ,
219+ Dep {
220+ name : "Webview2" ,
221+ instruction : format ! ( "Visit {BLUE}{BOLD}https://go.microsoft.com/fwlink/p/?LinkId=2124703{RESET}" ) ,
222+ exists : & is_webview2_installed,
223+ skip : false ,
224+ } ,
211225 #[ cfg( any(
212226 target_os = "linux" ,
213227 target_os = "dragonfly" ,
214228 target_os = "freebsd" ,
215229 target_os = "openbsd" ,
216230 target_os = "netbsd"
217231 ) ) ]
218- (
219- "webkit2gtk & rsvg2" ,
220- format ! ( "Visit {BLUE}{BOLD}{}{RESET}" , if alpha {
232+ Dep {
233+ name : "webkit2gtk & rsvg2" ,
234+ instruction : format ! ( "Visit {BLUE}{BOLD}{}{RESET}" , if alpha {
221235 "https://next--tauri.netlify.app/next/guides/getting-started/prerequisites/linux#1-system-dependencies"
222236 } else {
223237 "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
224238 } ) ,
225- & || webkit2gtk_installed && rsvg2_installed,
226- webkit2gtk_installed || rsvg2_installed,
227- ) ,
239+ exists : & || webkit2gtk_installed && rsvg2_installed,
240+ skip : webkit2gtk_installed || rsvg2_installed,
241+ } ,
228242 #[ cfg( any(
229243 target_os = "linux" ,
230244 target_os = "dragonfly" ,
231245 target_os = "freebsd" ,
232246 target_os = "openbsd" ,
233247 target_os = "netbsd"
234248 ) ) ]
235- (
236- "webkit2gtk" ,
237- format ! ( "Visit {BLUE}{BOLD}{}{RESET}" , if alpha {
249+ Dep {
250+ name : "webkit2gtk" ,
251+ instruction : format ! ( "Visit {BLUE}{BOLD}{}{RESET}" , if alpha {
238252 "https://next--tauri.netlify.app/next/guides/getting-started/prerequisites/linux#1-system-dependencies"
239253 } else {
240254 "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
241255 } ) ,
242- & || webkit2gtk_installed,
243- !rsvg2_installed && !webkit2gtk_installed,
244- ) ,
256+ exists : & || webkit2gtk_installed,
257+ skip : !rsvg2_installed && !webkit2gtk_installed,
258+ } ,
245259 #[ cfg( any(
246260 target_os = "linux" ,
247261 target_os = "dragonfly" ,
248262 target_os = "freebsd" ,
249263 target_os = "openbsd" ,
250264 target_os = "netbsd"
251265 ) ) ]
252- (
253- "rsvg2" ,
254- format ! ( "Visit {BLUE}{BOLD}{}{RESET}" , if alpha {
266+ Dep {
267+ name : "rsvg2" ,
268+ instruction : format ! ( "Visit {BLUE}{BOLD}{}{RESET}" , if alpha {
255269 "https://next--tauri.netlify.app/next/guides/getting-started/prerequisites/linux#1-system-dependencies"
256270 } else {
257271 "https://tauri.app/v1/guides/getting-started/prerequisites#setting-up-linux"
258272 } ) ,
259- & || rsvg2_installed,
260- !rsvg2_installed && !webkit2gtk_installed,
261- ) ,
273+ exists : & || rsvg2_installed,
274+ skip : !rsvg2_installed && !webkit2gtk_installed,
275+ } ,
262276 #[ cfg( target_os = "macos" ) ]
263- (
264- "Xcode Command Line Tools" ,
265- format ! ( "Run `{BLUE}{BOLD}xcode-select --install{RESET}`" ) ,
266- & is_xcode_command_line_tools_installed,
267- false ,
268- ) ,
277+ Dep {
278+ name : "Xcode Command Line Tools" ,
279+ instruction : format ! ( "Run `{BLUE}{BOLD}xcode-select --install{RESET}`" ) ,
280+ exists : & is_xcode_command_line_tools_installed,
281+ skip : false ,
282+ } ,
269283 ] ;
270284
271285 let missing_deps: Vec < ( String , String ) > = deps
272286 . iter ( )
273- . filter ( |( _ , _ , exists , skip ) | !skip && !exists ( ) )
274- . map ( |( s , d , _ , _ ) | ( s . to_string ( ) , d . clone ( ) ) )
287+ . filter ( |dep | !dep . skip && !( dep . exists ) ( ) )
288+ . map ( |dep | ( dep . name . to_string ( ) , dep . instruction . clone ( ) ) )
275289 . collect ( ) ;
276290
277291 let ( largest_first_cell, largest_second_cell) =
0 commit comments