Skip to content

Commit 052138c

Browse files
committed
Support -Zfmt-debug=none
1 parent 91dd8ef commit 052138c

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

build/build.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod rustc;
99

1010
use std::env;
1111
use std::ffi::OsString;
12+
use std::fmt::{self, Debug, Display};
1213
use std::fs;
1314
use std::iter;
1415
use std::path::Path;
@@ -91,7 +92,7 @@ fn main() {
9192
println!("cargo:rustc-check-cfg=cfg(host_os, values(\"windows\"))");
9293
}
9394

94-
let version = format!("{:#?}\n", version);
95+
let version = format!("{:#}\n", Render(&version));
9596
let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR not set");
9697
let out_file = Path::new(&out_dir).join("version.expr");
9798
fs::write(out_file, version).expect("failed to write version.expr");
@@ -101,3 +102,13 @@ fn main() {
101102
println!("cargo:rustc-cfg=host_os=\"windows\"");
102103
}
103104
}
105+
106+
// Shim Version's {:?} format into a {} format, because {:?} is unusable in
107+
// format strings when building with `-Zfmt-debug=none`.
108+
struct Render<'a>(&'a rustc::Version);
109+
110+
impl<'a> Display for Render<'a> {
111+
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
112+
Debug::fmt(self.0, formatter)
113+
}
114+
}

0 commit comments

Comments
 (0)