From 6b3dfa751c017b4dde585fe5f50c1320445eb964 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 14 Dec 2023 15:01:51 -0500 Subject: [PATCH] Use `\r\n` on windows --- bindgen/lib.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bindgen/lib.rs b/bindgen/lib.rs index 54348e2232..70aa67149f 100644 --- a/bindgen/lib.rs +++ b/bindgen/lib.rs @@ -927,22 +927,24 @@ impl Bindings { /// Write these bindings as source text to the given `Write`able. pub fn write<'a>(&self, mut writer: Box) -> io::Result<()> { + const NL: &str = if cfg!(windows) { "\r\n" } else { "\n" }; + if !self.options.disable_header_comment { let version = option_env!("CARGO_PKG_VERSION").unwrap_or("(unknown version)"); - let header = format!( - "/* automatically generated by rust-bindgen {version} */\n\n", - ); - writer.write_all(header.as_bytes())?; + writeln!( + writer, + "/* automatically generated by rust-bindgen {version} */{NL}", + )?; } for line in self.options.raw_lines.iter() { writer.write_all(line.as_bytes())?; - writer.write_all("\n".as_bytes())?; + writer.write_all(NL.as_bytes())?; } if !self.options.raw_lines.is_empty() { - writer.write_all("\n".as_bytes())?; + writer.write_all(NL.as_bytes())?; } match self.format_tokens(&self.module) {