Skip to content

Commit 28aaec8

Browse files
authored
feat(cli.rs): add active toolchain and rustup to tauri info, closes #2730 (#2986)
1 parent feb3a8f commit 28aaec8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"cli.rs": patch
3+
---
4+
5+
Add `rustup` version and active rust toolchain to the `info` command output.

tooling/cli.rs/src/info.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,32 @@ fn build_tools_version() -> crate::Result<Option<Vec<String>>> {
328328
Ok(versions)
329329
}
330330

331+
fn get_active_rust_toolchain() -> crate::Result<Option<String>> {
332+
let mut cmd;
333+
#[cfg(target_os = "windows")]
334+
{
335+
cmd = Command::new("cmd");
336+
cmd.arg("/c").arg("rustup");
337+
}
338+
339+
#[cfg(not(target_os = "windows"))]
340+
{
341+
cmd = Command::new("rustup")
342+
}
343+
344+
let output = cmd.args(["show", "active-toolchain"]).output()?;
345+
let toolchain = if output.status.success() {
346+
Some(
347+
String::from_utf8_lossy(&output.stdout)
348+
.replace("\n", "")
349+
.replace("\r", ""),
350+
)
351+
} else {
352+
None
353+
};
354+
Ok(toolchain)
355+
}
356+
331357
struct InfoBlock {
332358
section: bool,
333359
key: &'static str,
@@ -513,6 +539,15 @@ impl Info {
513539
}
514540

515541
InfoBlock::new("Rust environment").section().display();
542+
VersionBlock::new(
543+
" rustup",
544+
get_version("rustup", &[]).unwrap_or_default().map(|v| {
545+
let mut s = v.split(' ');
546+
s.next();
547+
s.next().unwrap().to_string()
548+
}),
549+
)
550+
.display();
516551
VersionBlock::new(
517552
" rustc",
518553
get_version("rustc", &[]).unwrap_or_default().map(|v| {
@@ -531,6 +566,11 @@ impl Info {
531566
}),
532567
)
533568
.display();
569+
VersionBlock::new(
570+
" toolchain",
571+
get_active_rust_toolchain().unwrap_or_default(),
572+
)
573+
.display();
534574

535575
if let Some(app_dir) = app_dir {
536576
InfoBlock::new("App directory structure")

0 commit comments

Comments
 (0)