Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cargo-the-binary version the same as the Rust version #5083

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions src/cargo/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ pub struct CfgInfo {
}

pub struct VersionInfo {
pub major: String,
pub minor: String,
pub patch: String,
pub major: u8,
pub minor: u8,
pub patch: u8,
pub pre_release: Option<String>,
// Information that's only available when we were built with
// configure/make, rather than cargo itself.
Expand Down Expand Up @@ -192,12 +192,28 @@ fn handle_cause(cargo_err: &Error, shell: &mut Shell) -> bool {
}

pub fn version() -> VersionInfo {
macro_rules! env_str {
($name:expr) => { env!($name).to_string() }
}
macro_rules! option_env_str {
($name:expr) => { option_env!($name).map(|s| s.to_string()) }
}

// So this is pretty horrible...
// There are two versions at play here:
// - version of cargo-the-binary, which you see when you type `cargo --version`
// - version of cargo-the-library, which you download from crates.io for use
// in your projects.
//
// We want to make the `binary` version the same as the corresponding Rust/rustc release.
// At the same time, we want to keep the library version at `0.x`, because Cargo as
// a library is (and probably will always be) unstable.
//
// Historically, Cargo used the same version number for both the binary and the library.
// Specifically, rustc 1.x.z was paired with cargo 0.x+1.w.
// We continue to use this scheme for the library, but transform it to 1.x.w for the purposes
// of `cargo --version`.
let major = 1;
let minor = env!("CARGO_PKG_VERSION_MINOR").parse::<u8>().unwrap() - 1;
let patch = env!("CARGO_PKG_VERSION_PATCH").parse::<u8>().unwrap();

match option_env!("CFG_RELEASE_CHANNEL") {
// We have environment variables set up from configure/make.
Some(_) => {
Expand All @@ -210,9 +226,9 @@ pub fn version() -> VersionInfo {
}
});
VersionInfo {
major: env_str!("CARGO_PKG_VERSION_MAJOR"),
minor: env_str!("CARGO_PKG_VERSION_MINOR"),
patch: env_str!("CARGO_PKG_VERSION_PATCH"),
major,
minor,
patch,
pre_release: option_env_str!("CARGO_PKG_VERSION_PRE"),
cfg_info: Some(CfgInfo {
release_channel: option_env_str!("CFG_RELEASE_CHANNEL").unwrap(),
Expand All @@ -223,9 +239,9 @@ pub fn version() -> VersionInfo {
// We are being compiled by Cargo itself.
None => {
VersionInfo {
major: env_str!("CARGO_PKG_VERSION_MAJOR"),
minor: env_str!("CARGO_PKG_VERSION_MINOR"),
patch: env_str!("CARGO_PKG_VERSION_PATCH"),
major,
minor,
patch,
pre_release: option_env_str!("CARGO_PKG_VERSION_PRE"),
cfg_info: None,
}
Expand Down