Repository: dtolnay/cxx (language: rust)

Issue:
Build error with MSVC
The generated `.rs.h` file cannot be built with MSVC because of the unrecognized `assert` macro. If you could add the `<cassert>` include in there, it would fix the issue.


Discussion / hints:

Fix patch:
diff --git a/gen/src/builtin.rs b/gen/src/builtin.rs
index 3b411aa1c..378467b66 100644
--- a/gen/src/builtin.rs
+++ b/gen/src/builtin.rs
@@ -64,6 +64,7 @@ pub(super) fn write(out: &mut OutFile) {
     if builtin.rust_vec {
         include.algorithm = true;
         include.array = true;
+        include.cassert = true;
         include.cstddef = true;
         include.cstdint = true;
         include.initializer_list = true;
@@ -78,6 +79,7 @@ pub(super) fn write(out: &mut OutFile) {
 
     if builtin.rust_slice {
         include.array = true;
+        include.cassert = true;
         include.cstddef = true;
         include.cstdint = true;
         include.iterator = true;
diff --git a/gen/src/include.rs b/gen/src/include.rs
index 6b7e58011..93ce60b99 100644
--- a/gen/src/include.rs
+++ b/gen/src/include.rs
@@ -23,6 +23,7 @@ pub struct Includes<'a> {
     pub custom: Vec<Include>,
     pub algorithm: bool,
     pub array: bool,
+    pub cassert: bool,
     pub cstddef: bool,
     pub cstdint: bool,
     pub cstring: bool,
@@ -75,6 +76,7 @@ pub(super) fn write(out: &mut OutFile) {
         custom: _,
         algorithm,
         array,
+        cassert,
         cstddef,
         cstdint,
         cstring,
@@ -99,6 +101,9 @@ pub(super) fn write(out: &mut OutFile) {
     if array {
         writeln!(out, "#include <array>");
     }
+    if cassert {
+        writeln!(out, "#include <cassert>");
+    }
     if cstddef {
         writeln!(out, "#include <cstddef>");
     }


Test patch: