Get rust versions correctly
@@ -2,14 +2,15 @@ use std::path::Path;
use std::fs::File;
use std::io::Write;
use std::env;
+use std::process::Command;
static USER_AGENT_FILE_NAME: &str = "user_agent";
fn main() {
- let package_name = option_env!("CARGO_PKG_NAME").unwrap_or("Exonum");
+ let package_name = option_env!("CARGO_PKG_NAME").unwrap_or("exonum");
let package_version = option_env!("CARGO_PKG_VERSION").unwrap_or("?");
- let rust_version = option_env!("CARGO_RUST_VERSION").unwrap_or("?");
- let user_agent = format!("{} {}/Rust {}", package_name, package_version, rust_version);
+ let rust_version = rust_version().unwrap_or("rust ?".to_string());
+ let user_agent = format!("{} {}/{}", package_name, package_version, rust_version);
let out_dir = env::var("OUT_DIR").expect("Unable to get OUT_DIR");
let dest_path = Path::new(&out_dir).join(USER_AGENT_FILE_NAME);
@@ -18,3 +19,13 @@ fn main() {
"Unable to data to file",
);
}
+
+fn rust_version() -> Option<String> {
+ let rustc = env!("RUSTC");
+
+ if let Ok(output) = Command::new(rustc).arg("-V").output().map(|x| x.stdout) {
+ String::from_utf8(output).ok()
+ } else {
+ None
+ }
+}
