Skip to content

Commit 4f1125c

Browse files
authored
Use \r\n on windows (#2698)
1 parent d77e53e commit 4f1125c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bindgen/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -927,22 +927,24 @@ impl Bindings {
927927

928928
/// Write these bindings as source text to the given `Write`able.
929929
pub fn write<'a>(&self, mut writer: Box<dyn Write + 'a>) -> io::Result<()> {
930+
const NL: &str = if cfg!(windows) { "\r\n" } else { "\n" };
931+
930932
if !self.options.disable_header_comment {
931933
let version =
932934
option_env!("CARGO_PKG_VERSION").unwrap_or("(unknown version)");
933-
let header = format!(
934-
"/* automatically generated by rust-bindgen {version} */\n\n",
935-
);
936-
writer.write_all(header.as_bytes())?;
935+
writeln!(
936+
writer,
937+
"/* automatically generated by rust-bindgen {version} */{NL}",
938+
)?;
937939
}
938940

939941
for line in self.options.raw_lines.iter() {
940942
writer.write_all(line.as_bytes())?;
941-
writer.write_all("\n".as_bytes())?;
943+
writer.write_all(NL.as_bytes())?;
942944
}
943945

944946
if !self.options.raw_lines.is_empty() {
945-
writer.write_all("\n".as_bytes())?;
947+
writer.write_all(NL.as_bytes())?;
946948
}
947949

948950
match self.format_tokens(&self.module) {

0 commit comments

Comments
 (0)