Skip to content

Commit c7957a7

Browse files
committed
Auto merge of #9968 - ehuss:verbose-version, r=alexcrichton,Eh2406
Add some more information to verbose version. This adds a little bit of extra information to the verbose version command. cc #6275 and #6161 Some examples of what it might look like: ``` cargo 1.57.0 release: 1.57.0 host: x86_64-unknown-linux-gnu libgit2: 1.3.0 (sys:0.13.23 vendored) libcurl: 7.79.1-DEV (sys:0.4.49+curl-7.79.1 vendored ssl:OpenSSL/1.1.1k) ssl: OpenSSL 1.1.1k 25 Mar 2021 ``` ``` cargo 1.57.0 release: 1.57.0 host: x86_64-pc-windows-msvc libgit2: 1.3.0 (sys:0.13.23 vendored) libcurl: 7.79.1-DEV (sys:0.4.49+curl-7.79.1 vendored ssl:Schannel) ``` ``` cargo 1.57.0 release: 1.57.0 host: x86_64-apple-darwin libgit2: 1.3.0 (sys:0.13.23 vendored) libcurl: 7.64.1 (sys:0.4.49+curl-7.79.1 system ssl:(SecureTransport) LibreSSL/2.8.3) ssl: OpenSSL 1.1.1l 24 Aug 2021 ```
2 parents dea587a + 9f5da7c commit c7957a7

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ labels: C-bug
2222

2323
**Notes**
2424

25-
Output of `cargo version`:
25+
Output of `cargo version --verbose`:
2626

2727
<!-- Also, any additional context or information you feel may be relevant to the issue. -->
2828
<!-- (e.g rust version, OS platform/distribution/version, target toolchain(s), release channel.. -->

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ cargo-platform = { path = "crates/cargo-platform", version = "0.1.2" }
2525
cargo-util = { path = "crates/cargo-util", version = "0.1.1" }
2626
crates-io = { path = "crates/crates-io", version = "0.33.0" }
2727
crossbeam-utils = "0.8"
28-
curl = { version = "0.4.38", features = ["http2"] }
29-
curl-sys = "0.4.48"
28+
curl = { version = "0.4.39", features = ["http2"] }
29+
curl-sys = "0.4.49"
3030
env_logger = "0.9.0"
3131
pretty_env_logger = { version = "0.4", optional = true }
3232
anyhow = "1.0"
@@ -48,6 +48,7 @@ libgit2-sys = "0.12.24"
4848
memchr = "2.1.3"
4949
num_cpus = "1.0"
5050
opener = "0.5"
51+
os_info = "3.0.7"
5152
percent-encoding = "2.0"
5253
rustfix = "0.6.0"
5354
semver = { version = "1.0.3", features = ["serde"] }

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ use std::path::Path;
55

66
fn main() {
77
compress_man();
8+
println!(
9+
"cargo:rustc-env=RUST_HOST_TARGET={}",
10+
std::env::var("TARGET").unwrap()
11+
);
812
}
913

1014
fn compress_man() {

src/bin/cargo/cli.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use cargo::{self, drop_print, drop_println, CliResult, Config};
44
use clap::{AppSettings, Arg, ArgMatches};
55
use itertools::Itertools;
66
use std::collections::HashMap;
7+
use std::fmt::Write;
78

89
use super::commands;
910
use super::list_commands;
@@ -173,10 +174,64 @@ pub fn get_version_string(is_verbose: bool) -> String {
173174
version_string.push_str(&format!("commit-date: {}\n", ci.commit_date));
174175
}
175176
}
177+
writeln!(version_string, "host: {}", env!("RUST_HOST_TARGET")).unwrap();
178+
add_libgit2(&mut version_string);
179+
add_curl(&mut version_string);
180+
add_ssl(&mut version_string);
181+
writeln!(version_string, "os: {}", os_info::get()).unwrap();
176182
}
177183
version_string
178184
}
179185

186+
fn add_libgit2(version_string: &mut String) {
187+
let git2_v = git2::Version::get();
188+
let lib_v = git2_v.libgit2_version();
189+
let vendored = if git2_v.vendored() {
190+
format!("vendored")
191+
} else {
192+
format!("system")
193+
};
194+
writeln!(
195+
version_string,
196+
"libgit2: {}.{}.{} (sys:{} {})",
197+
lib_v.0,
198+
lib_v.1,
199+
lib_v.2,
200+
git2_v.crate_version(),
201+
vendored
202+
)
203+
.unwrap();
204+
}
205+
206+
fn add_curl(version_string: &mut String) {
207+
let curl_v = curl::Version::get();
208+
let vendored = if curl_v.vendored() {
209+
format!("vendored")
210+
} else {
211+
format!("system")
212+
};
213+
writeln!(
214+
version_string,
215+
"libcurl: {} (sys:{} {} ssl:{})",
216+
curl_v.version(),
217+
curl_sys::rust_crate_version(),
218+
vendored,
219+
curl_v.ssl_version().unwrap_or("none")
220+
)
221+
.unwrap();
222+
}
223+
224+
fn add_ssl(version_string: &mut String) {
225+
#[cfg(feature = "openssl")]
226+
{
227+
writeln!(version_string, "ssl: {}", openssl::version::version()).unwrap();
228+
}
229+
#[cfg(not(feature = "openssl"))]
230+
{
231+
let _ = version_string; // Silence unused warning.
232+
}
233+
}
234+
180235
fn expand_aliases(
181236
config: &mut Config,
182237
args: ArgMatches<'static>,

tests/testsuite/version.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Tests for displaying the cargo version.
22
3-
use cargo_test_support::project;
3+
use cargo_test_support::{cargo_process, project};
44

55
#[cargo_test]
66
fn simple() {
@@ -41,3 +41,15 @@ fn version_works_with_bad_target_dir() {
4141
.build();
4242
p.cargo("version").run();
4343
}
44+
45+
#[cargo_test]
46+
fn verbose() {
47+
// This is mainly to check that it doesn't explode.
48+
cargo_process("-vV")
49+
.with_stdout_contains(&format!("cargo {}", cargo::version()))
50+
.with_stdout_contains("host: [..]")
51+
.with_stdout_contains("libgit2: [..]")
52+
.with_stdout_contains("libcurl: [..]")
53+
.with_stdout_contains("os: [..]")
54+
.run();
55+
}

0 commit comments

Comments
 (0)