From a5c92035898a55352f28458fe4b1c9562a71ae55 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 11 Jan 2021 12:26:37 +0100 Subject: [PATCH 01/21] Remove Travis badge --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d8bf7ec..81524a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,6 @@ repository = "https://github.com/Kimundi/rustc-version-rs" keywords = ["version", "rustc"] edition = "2018" -[badges] -travis-ci = { repository = "Kimundi/rustc-version-rs" } - [dependencies] semver = "0.11" From a4bbdafb0b852f7e89e6ca9a69ae96f463301bcc Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 11 Jan 2021 12:27:00 +0100 Subject: [PATCH 02/21] Remove extern crate statement from README example --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index c686932..e76ef95 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,6 @@ rustc_version = "0.2" ```rust // This could be a cargo build script -extern crate rustc_version; use rustc_version::{version, version_meta, Channel, Version}; fn main() { From 62b3cf9c8a0c04944d1ae343a9c0bb864f7e36e5 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 18 Jan 2021 08:29:23 +0100 Subject: [PATCH 03/21] Allow (but ignore) micro part of LLVM version (fixes #37) --- src/lib.rs | 5 +++++ tests/all.rs | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95a076e..5929696 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,6 +95,7 @@ pub struct LlvmVersion { pub major: u64, /// Minor version pub minor: u64, + // TODO: expose micro version here } impl fmt::Display for LlvmVersion { @@ -135,6 +136,10 @@ impl FromStr for LlvmVersion { return Err(LlvmVersionParseError::MinorVersionRequiredBefore4); } + if let Some(Err(e)) = parts.next() { + return Err(e.into()); + } + if parts.next().is_some() { return Err(LlvmVersionParseError::TooManyComponents); } diff --git a/tests/all.rs b/tests/all.rs index f1dc890..7098373 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -198,6 +198,36 @@ LLVM version: 11.0", ); } +#[test] +fn parse_llvm_micro() { + let version = version_meta_for( + "rustc 1.51.0-nightly (4253153db 2021-01-17) +binary: rustc +commit-hash: 4253153db205251f72ea4493687a31e04a2a8ca0 +commit-date: 2021-01-17 +host: x86_64-pc-windows-msvc +release: 1.51.0-nightly +LLVM version: 11.0.1", + ) + .unwrap(); + + assert_eq!(version.semver, Version::parse("1.51.0-nightly").unwrap()); + assert_eq!( + version.commit_hash.as_deref(), + Some("4253153db205251f72ea4493687a31e04a2a8ca0") + ); + assert_eq!(version.commit_date.as_deref(), Some("2021-01-17")); + assert_eq!(version.host, "x86_64-pc-windows-msvc"); + assert_eq!(version.short_version_string, "rustc 1.51.0-nightly (4253153db 2021-01-17)"); + assert_eq!( + version.llvm_version, + Some(LlvmVersion { + major: 11, + minor: 0 + }) + ); +} + #[test] fn parse_debian_buster() { let version = version_meta_for( @@ -296,16 +326,6 @@ fn parse_llvm_version_leading_zero_on_nonzero() { }); } -#[test] -fn parse_llvm_version_3_components() { - let res: Result = "4.0.0".parse(); - - assert!(match res { - Err(LlvmVersionParseError::TooManyComponents) => true, - _ => false, - }); -} - #[test] fn parse_llvm_version_4_components() { let res: Result = "4.0.0.0".parse(); From b989903369559964e14845813479db4b0b7998d7 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 18 Jan 2021 08:31:16 +0100 Subject: [PATCH 04/21] Remove requirement that minor LLVM version is always 0 --- src/lib.rs | 4 ---- tests/all.rs | 10 ---------- 2 files changed, 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5929696..d7f2738 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,10 +127,6 @@ impl FromStr for LlvmVersion { if let Some(part) = parts.next() { minor = part?; - if major >= 4 && minor != 0 { - // only LLVM versions earlier than 4.0 can have non-zero minor versions - return Err(LlvmVersionParseError::MinorVersionMustBeZeroAfter4); - } } else if major < 4 { // LLVM versions earlier than 4.0 have significant minor versions, so require the minor version in this case. return Err(LlvmVersionParseError::MinorVersionRequiredBefore4); diff --git a/tests/all.rs b/tests/all.rs index 7098373..523fd47 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -366,16 +366,6 @@ fn parse_llvm_version_3() { }); } -#[test] -fn parse_llvm_version_4_1() { - let res: Result = "4.1".parse(); - - assert!(match res { - Err(LlvmVersionParseError::MinorVersionMustBeZeroAfter4) => true, - _ => false, - }); -} - #[test] fn parse_llvm_version_5() { let v: LlvmVersion = "5".parse().unwrap(); From 9d8912cac6431c948bf81c899825465574934a9f Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 18 Jan 2021 08:35:50 +0100 Subject: [PATCH 05/21] Fix formatting --- tests/all.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/all.rs b/tests/all.rs index 523fd47..9d30f57 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -218,7 +218,10 @@ LLVM version: 11.0.1", ); assert_eq!(version.commit_date.as_deref(), Some("2021-01-17")); assert_eq!(version.host, "x86_64-pc-windows-msvc"); - assert_eq!(version.short_version_string, "rustc 1.51.0-nightly (4253153db 2021-01-17)"); + assert_eq!( + version.short_version_string, + "rustc 1.51.0-nightly (4253153db 2021-01-17)" + ); assert_eq!( version.llvm_version, Some(LlvmVersion { From 7421a8abb053eab4fbe560a821d51261fb67447d Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 18 Jan 2021 08:35:59 +0100 Subject: [PATCH 06/21] Fix compatibility with MSRV --- tests/all.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/all.rs b/tests/all.rs index 9d30f57..c3cff70 100644 --- a/tests/all.rs +++ b/tests/all.rs @@ -213,10 +213,10 @@ LLVM version: 11.0.1", assert_eq!(version.semver, Version::parse("1.51.0-nightly").unwrap()); assert_eq!( - version.commit_hash.as_deref(), - Some("4253153db205251f72ea4493687a31e04a2a8ca0") + version.commit_hash.unwrap(), + "4253153db205251f72ea4493687a31e04a2a8ca0" ); - assert_eq!(version.commit_date.as_deref(), Some("2021-01-17")); + assert_eq!(version.commit_date.unwrap(), "2021-01-17"); assert_eq!(version.host, "x86_64-pc-windows-msvc"); assert_eq!( version.short_version_string, From 81f27acad96c7db6048b54d07bf2a9d3b08f24ec Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 18 Jan 2021 08:36:57 +0100 Subject: [PATCH 07/21] Apply clippy suggestion --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d7f2738..3ba218f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -133,7 +133,7 @@ impl FromStr for LlvmVersion { } if let Some(Err(e)) = parts.next() { - return Err(e.into()); + return Err(e); } if parts.next().is_some() { From bede9a62ff53ba3fe12058fccb6e5ff5ec03946e Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 18 Jan 2021 08:38:56 +0100 Subject: [PATCH 08/21] Bump version to 0.3.3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 81524a6..232db27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc_version" -version = "0.3.2" +version = "0.3.3" authors = ["Marvin Löbel "] license = "MIT/Apache-2.0" description = "A library for querying the version of a installed rustc compiler" From 13cbfb70e5dc9fea727debdeed549be51bb26201 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 27 May 2021 10:58:52 -0700 Subject: [PATCH 09/21] Update to semver 1.0.0 --- Cargo.toml | 2 +- src/lib.rs | 24 +++++++++--------------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 232db27..f60e326 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ keywords = ["version", "rustc"] edition = "2018" [dependencies] -semver = "0.11" +semver = "1.0" [dev-dependencies] doc-comment = "0.3" diff --git a/src/lib.rs b/src/lib.rs index 3ba218f..cee1ec8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,7 +61,6 @@ use std::process::Command; use std::{env, error, fmt, io, num, str}; use std::{ffi::OsString, str::FromStr}; -use semver::{self, Identifier}; // Convenience re-export to allow version comparison without needing to add // semver crate. pub use semver::Version; @@ -231,12 +230,12 @@ pub fn version_meta_for(verbose_version_string: &str) -> Result { let release = expect_key("release", &map)?; let semver: Version = release.parse()?; - let channel = match semver.pre.first() { - None => Channel::Stable, - Some(Identifier::AlphaNumeric(s)) if s == "dev" => Channel::Dev, - Some(Identifier::AlphaNumeric(s)) if s == "beta" => Channel::Beta, - Some(Identifier::AlphaNumeric(s)) if s == "nightly" => Channel::Nightly, - Some(x) => return Err(Error::UnknownPreReleaseTag(x.clone())), + let channel = match semver.pre.split('.').next().unwrap() { + "" => Channel::Stable, + "dev" => Channel::Dev, + "beta" => Channel::Beta, + "nightly" => Channel::Nightly, + x => return Err(Error::UnknownPreReleaseTag(x.to_owned())), }; let commit_hash = expect_key_or_unknown("commit-hash", &map)?; @@ -353,12 +352,10 @@ pub enum Error { Utf8Error(str::Utf8Error), /// The output of `rustc -vV` was not in the expected format. UnexpectedVersionFormat, - /// An error occurred in parsing a `VersionReq`. - ReqParseError(semver::ReqParseError), /// An error occurred in parsing the semver. - SemVerError(semver::SemVerError), + SemVerError(semver::Error), /// The pre-release tag is unknown. - UnknownPreReleaseTag(Identifier), + UnknownPreReleaseTag(String), /// An error occurred in parsing a `LlvmVersion`. LlvmVersionError(LlvmVersionParseError), } @@ -377,7 +374,6 @@ impl fmt::Display for Error { ), Utf8Error(_) => write!(f, "invalid UTF-8 output from `rustc -vV`"), UnexpectedVersionFormat => write!(f, "unexpected `rustc -vV` format"), - ReqParseError(ref e) => write!(f, "error parsing version requirement: {}", e), SemVerError(ref e) => write!(f, "error parsing version: {}", e), UnknownPreReleaseTag(ref i) => write!(f, "unknown pre-release tag: {}", i), LlvmVersionError(ref e) => write!(f, "error parsing LLVM's version: {}", e), @@ -392,7 +388,6 @@ impl error::Error for Error { CommandError { .. } => None, Utf8Error(ref e) => Some(e), UnexpectedVersionFormat => None, - ReqParseError(ref e) => Some(e), SemVerError(ref e) => Some(e), UnknownPreReleaseTag(_) => None, LlvmVersionError(ref e) => Some(e), @@ -414,8 +409,7 @@ macro_rules! impl_from { impl_from! { str::Utf8Error => Utf8Error, - semver::SemVerError => SemVerError, - semver::ReqParseError => ReqParseError, + semver::Error => SemVerError, LlvmVersionParseError => LlvmVersionError, } From 339c9b97ad0d1134549fe0f6c742158e186d4705 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 28 May 2021 10:45:42 +0200 Subject: [PATCH 10/21] Ignore macOS cruft --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index a9d37c5..22d9b57 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target Cargo.lock +.DS_Store From a3b4595bd8066cdddb12a123b362d31bab031402 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 28 May 2021 10:46:39 +0200 Subject: [PATCH 11/21] Add Dependabot config --- .github/dependabot.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..93a4164 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +version: 2 +updates: +- package-ecosystem: cargo + directory: "/" + schedule: + interval: daily + time: "04:00" + open-pull-requests-limit: 10 + ignore: + - dependency-name: semver + versions: + - "> 1.0, < 2" From 5437ed457f1d9383c00a4a613d9e52fdc2d8ea1b Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Fri, 28 May 2021 10:56:28 +0200 Subject: [PATCH 12/21] Add myself as an author --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f60e326..d4d6342 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "rustc_version" version = "0.3.3" -authors = ["Marvin Löbel "] +authors = ["Dirkjan Ochtman ", "Marvin Löbel "] license = "MIT/Apache-2.0" description = "A library for querying the version of a installed rustc compiler" readme = "README.md" From 6093aa9de6428df2e1c04aa9e969f1af7c34664f Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 7 Jun 2021 09:44:44 +0200 Subject: [PATCH 13/21] Bump version to 0.4.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d4d6342..464176f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc_version" -version = "0.3.3" +version = "0.4.0" authors = ["Dirkjan Ochtman ", "Marvin Löbel "] license = "MIT/Apache-2.0" description = "A library for querying the version of a installed rustc compiler" From 9cdb26683edb35a31573f5322594ef07e43aa142 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 14 Jun 2021 10:50:52 +0200 Subject: [PATCH 14/21] Update URLs after repo transfer --- Cargo.toml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 464176f..8e037bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT/Apache-2.0" description = "A library for querying the version of a installed rustc compiler" readme = "README.md" documentation = "https://docs.rs/rustc_version/" -repository = "https://github.com/Kimundi/rustc-version-rs" +repository = "https://github.com/djc/rustc-version-rs" keywords = ["version", "rustc"] edition = "2018" diff --git a/README.md b/README.md index e76ef95..9f3f7a5 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ rustc-version-rs [![Documentation](https://docs.rs/rustc_version/badge.svg)](https://docs.rs/rustc_version/) [![Crates.io](https://img.shields.io/crates/v/rustc_version.svg)](https://crates.io/crates/rustc_version) -[![Build status](https://github.com/Kimundi/rustc-version-rs/workflows/CI/badge.svg)](https://github.com/Kimundi/rustc-version-rs/actions?query=workflow%3ACI) +[![Build status](https://github.com/djc/rustc-version-rs/workflows/CI/badge.svg)](https://github.com/djc/rustc-version-rs/actions?query=workflow%3ACI) A library for querying the version of a `rustc` compiler. From 599b9e91dd33a384b67460066f415512661e04ce Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 14 Jun 2021 10:52:27 +0200 Subject: [PATCH 15/21] Add funding options --- .github/FUNDING.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..90ee18e --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: [djc] +patreon: dochtman From 7e78539d2ae0c3d757acec2534efe026de59d79e Mon Sep 17 00:00:00 2001 From: Marijn Schouten Date: Thu, 18 Apr 2024 17:36:50 +0200 Subject: [PATCH 16/21] respect RUSTC_WRAPPER env var --- src/lib.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cee1ec8..d14c768 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -198,9 +198,16 @@ pub fn version() -> Result { /// Returns the `rustc` SemVer version and additional metadata /// like the git short hash and build date. pub fn version_meta() -> Result { - let cmd = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc")); + let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc")); + let cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER").filter(|w| !w.is_empty()) { + let mut cmd = Command::new(wrapper); + cmd.arg(rustc); + cmd + } else { + Command::new(rustc) + }; - VersionMeta::for_command(Command::new(cmd)) + VersionMeta::for_command(cmd) } /// Parses a "rustc -vV" output string and returns @@ -263,7 +270,7 @@ pub fn version_meta_for(verbose_version_string: &str) -> Result { fn expect_key_or_unknown(key: &str, map: &HashMap<&str, &str>) -> Result, Error> { match map.get(key) { - Some(&v) if v == "unknown" => Ok(None), + Some(&"unknown") => Ok(None), Some(&v) => Ok(Some(String::from(v))), None => Err(Error::UnexpectedVersionFormat), } From 75d6f4a851ee51f17a0884cdb473f1bb3bd0eafb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 27 Aug 2024 20:52:01 +0200 Subject: [PATCH 17/21] bump version number: v0.4.1 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8e037bd..daa119a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustc_version" -version = "0.4.0" +version = "0.4.1" authors = ["Dirkjan Ochtman ", "Marvin Löbel "] license = "MIT/Apache-2.0" description = "A library for querying the version of a installed rustc compiler" From 3997cc6ad2926aee0636da63c44bcaa7c4df6ef6 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 28 Aug 2024 11:14:25 +0200 Subject: [PATCH 18/21] Make license metadata SPDX compatible --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index daa119a..04fb522 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "rustc_version" version = "0.4.1" authors = ["Dirkjan Ochtman ", "Marvin Löbel "] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" description = "A library for querying the version of a installed rustc compiler" readme = "README.md" documentation = "https://docs.rs/rustc_version/" From b4b6dbbefa1a0ff9cb5e628f15015c87cb83c042 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 28 Aug 2024 11:15:17 +0200 Subject: [PATCH 19/21] Update cargo-deny config --- deny.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deny.toml b/deny.toml index 38c47a8..ab17368 100644 --- a/deny.toml +++ b/deny.toml @@ -1,3 +1,2 @@ [licenses] -allow-osi-fsf-free = "either" -copyleft = "deny" +allow = ["MIT"] From a47da65cafc5a70ce62e9cdbf73b4c7aaba8745c Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 28 Aug 2024 11:15:53 +0200 Subject: [PATCH 20/21] Remove authors from metadata (per RFC 3052) --- Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 04fb522..f98cd14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [package] name = "rustc_version" version = "0.4.1" -authors = ["Dirkjan Ochtman ", "Marvin Löbel "] license = "MIT OR Apache-2.0" description = "A library for querying the version of a installed rustc compiler" readme = "README.md" From eeca449cca83e24150e46739e797aa82e9142809 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Wed, 28 Aug 2024 11:16:55 +0200 Subject: [PATCH 21/21] Set rust-version in metadata --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index f98cd14..0c7c487 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "rustc_version" version = "0.4.1" +rust-version = "1.32" license = "MIT OR Apache-2.0" description = "A library for querying the version of a installed rustc compiler" readme = "README.md"