Skip to content

Commit e5b3400

Browse files
committed
Auto merge of #1798 - RalfJung:nogit, r=oli-obk
support building Miri outside a git repo Fixes rust-lang/rust#84182 `@semarie` this should fix your problem... but I think any version of Miri actually shipped to users should have the proper git version information embedded, so I am not sure if this is the right fix. How do you do this for rustc proper? Even stable builds usually have a git version: ``` $ rustc +stable --version rustc 1.51.0 (2fd73fabe 2021-03-23) ```
2 parents bcae331 + 64f128c commit e5b3400

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

cargo-miri/bin.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::io::{self, BufRead, BufReader, BufWriter, Read, Write};
66
use std::ops::Not;
77
use std::path::{Path, PathBuf};
88
use std::process::Command;
9+
use std::fmt::{Write as _};
910

1011
use serde::{Deserialize, Serialize};
1112

@@ -90,12 +91,13 @@ fn show_help() {
9091
}
9192

9293
fn show_version() {
93-
println!(
94-
"miri {} ({} {})",
95-
env!("CARGO_PKG_VERSION"),
96-
env!("VERGEN_GIT_SHA_SHORT"),
97-
env!("VERGEN_GIT_COMMIT_DATE")
98-
);
94+
let mut version = format!("miri {}", env!("CARGO_PKG_VERSION"));
95+
// Only use `option_env` on vergen variables to ensure the build succeeds
96+
// when vergen failed to find the git info.
97+
if let Some(sha) = option_env!("VERGEN_GIT_SHA_SHORT") {
98+
write!(&mut version, " ({} {})", sha, option_env!("VERGEN_GIT_COMMIT_DATE").unwrap()).unwrap();
99+
}
100+
println!("{}", version);
99101
}
100102

101103
fn show_error(msg: String) -> ! {

cargo-miri/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ fn main() {
77
let mut gen_config = vergen::Config::default();
88
*gen_config.git_mut().sha_kind_mut() = vergen::ShaKind::Short;
99
*gen_config.git_mut().commit_timestamp_kind_mut() = vergen::TimestampKind::DateOnly;
10-
vergen(gen_config).expect("Unable to generate vergen keys!");
10+
vergen(gen_config).ok(); // Ignore failure (in case we are built outside a git repo)
1111
}

0 commit comments

Comments
 (0)