From 28aaec87e2f6445859e9dbaaf2231d02d1e1d4b5 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 9 Dec 2021 06:28:26 +0200 Subject: [PATCH] feat(cli.rs): add active toolchain and rustup to `tauri info`, closes #2730 (#2986) --- .changes/cli.rs-active-toolchain.md | 5 ++++ tooling/cli.rs/src/info.rs | 40 +++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 .changes/cli.rs-active-toolchain.md diff --git a/.changes/cli.rs-active-toolchain.md b/.changes/cli.rs-active-toolchain.md new file mode 100644 index 000000000..b39202bcd --- /dev/null +++ b/.changes/cli.rs-active-toolchain.md @@ -0,0 +1,5 @@ +--- +"cli.rs": patch +--- + +Add `rustup` version and active rust toolchain to the `info` command output. diff --git a/tooling/cli.rs/src/info.rs b/tooling/cli.rs/src/info.rs index 13cd654ce..a2074f6c9 100644 --- a/tooling/cli.rs/src/info.rs +++ b/tooling/cli.rs/src/info.rs @@ -328,6 +328,32 @@ fn build_tools_version() -> crate::Result>> { Ok(versions) } +fn get_active_rust_toolchain() -> crate::Result> { + let mut cmd; + #[cfg(target_os = "windows")] + { + cmd = Command::new("cmd"); + cmd.arg("/c").arg("rustup"); + } + + #[cfg(not(target_os = "windows"))] + { + cmd = Command::new("rustup") + } + + let output = cmd.args(["show", "active-toolchain"]).output()?; + let toolchain = if output.status.success() { + Some( + String::from_utf8_lossy(&output.stdout) + .replace("\n", "") + .replace("\r", ""), + ) + } else { + None + }; + Ok(toolchain) +} + struct InfoBlock { section: bool, key: &'static str, @@ -513,6 +539,15 @@ impl Info { } InfoBlock::new("Rust environment").section().display(); + VersionBlock::new( + " rustup", + get_version("rustup", &[]).unwrap_or_default().map(|v| { + let mut s = v.split(' '); + s.next(); + s.next().unwrap().to_string() + }), + ) + .display(); VersionBlock::new( " rustc", get_version("rustc", &[]).unwrap_or_default().map(|v| { @@ -531,6 +566,11 @@ impl Info { }), ) .display(); + VersionBlock::new( + " toolchain", + get_active_rust_toolchain().unwrap_or_default(), + ) + .display(); if let Some(app_dir) = app_dir { InfoBlock::new("App directory structure")