diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index e8a5ffc10..79d328c4d 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -775,7 +775,6 @@ impl Constant { self.documentation.write(config, out); let allow_constexpr = config.constant.allow_constexpr && self.value.can_be_constexpr(); - let allow_comptime = config.constant.allow_comptime; match config.language { Language::Cxx if config.constant.allow_static_const || allow_constexpr => { if allow_constexpr { @@ -809,11 +808,6 @@ impl Constant { write!(out, " {} # = ", name); value.write(config, out); } - Language::Zig if allow_comptime => { - if allow_comptime { - out.write("comptime "); - } - } Language::Zig => { out.write(config.style.zig_def()); self.ty.write(config, out); diff --git a/src/bindgen/ir/enumeration.rs b/src/bindgen/ir/enumeration.rs index 1db4fdc18..31f078799 100644 --- a/src/bindgen/ir/enumeration.rs +++ b/src/bindgen/ir/enumeration.rs @@ -863,7 +863,12 @@ impl Enum { Language::C | Language::Cxx => {} Language::Cython => out.write(config.style.cython_def()), Language::Zig => { - write!(out, "{}{} = extern ", config.style.zig_def(), self.export_name()); + write!( + out, + "{}{} = extern ", + config.style.zig_def(), + self.export_name() + ); } } @@ -939,7 +944,7 @@ impl Enum { if config.language != Language::Zig { write!(out, "{} tag;", tag_name); - }else { + } else { write!(out, "tag: {},", tag_name); } @@ -978,14 +983,21 @@ impl Enum { // support unnamed structs. // For the same reason with Cython we can omit per-variant tags (the first // field) to avoid extra noise, the main `tag` is enough in this case. - if config.language != Language::Cython { + if config.language != Language::Cython && config.language != Language::Zig { out.write("struct"); out.open_brace(); } let start_field = usize::from(inline_tag_field && config.language == Language::Cython); - out.write_vertical_source_list(&body.fields[start_field..], ListType::Cap(";")); - if config.language != Language::Cython { + out.write_vertical_source_list( + &body.fields[start_field..], + ListType::Cap(if config.language != Language::Zig { + ";" + } else { + "," + }), + ); + if config.language != Language::Cython && config.language != Language::Zig { out.close_brace(true); } } else if config.language == Language::Zig { diff --git a/src/bindgen/ir/structure.rs b/src/bindgen/ir/structure.rs index 07d33212c..9f10cfccd 100644 --- a/src/bindgen/ir/structure.rs +++ b/src/bindgen/ir/structure.rs @@ -439,7 +439,7 @@ impl Source for Struct { write!(out, "{} = extern struct", self.export_name()); } else { out.write("struct"); - } + } if config.language != Language::Cython { if let Some(align) = self.alignment { @@ -464,8 +464,10 @@ impl Source for Struct { } } - if config.language != Language::Zig && config.language != Language::C { - write!(out, " {}", self.export_name()); + if config.language != Language::C || config.style.generate_tag() { + if config.language != Language::Zig { + write!(out, " {}", self.export_name); + } } out.open_brace(); @@ -476,7 +478,14 @@ impl Source for Struct { out.new_line(); } - out.write_vertical_source_list(&self.fields, ListType::Cap(if config.language != Language::Zig {";"}else{","})); + out.write_vertical_source_list( + &self.fields, + ListType::Cap(if config.language != Language::Zig { + ";" + } else { + "," + }), + ); if config.language == Language::Cython && self.fields.is_empty() { out.write("pass"); } diff --git a/src/bindgen/ir/union.rs b/src/bindgen/ir/union.rs index e1888093f..8736e83fa 100644 --- a/src/bindgen/ir/union.rs +++ b/src/bindgen/ir/union.rs @@ -282,7 +282,11 @@ impl Source for Union { Language::Zig => out.write(config.style.zig_def()), } - out.write("union"); + if config.language == Language::Zig { + write!(out, "{} = extern union", self.export_name()); + } else { + out.write("union"); + } // Cython supports `packed` on structs (see comments there), but not on unions. if config.language != Language::Cython { @@ -303,7 +307,9 @@ impl Source for Union { } if config.language != Language::C || config.style.generate_tag() { - write!(out, " {}", self.export_name); + if config.language != Language::Zig { + write!(out, " {}", self.export_name); + } } out.open_brace(); @@ -314,7 +320,14 @@ impl Source for Union { out.new_line(); } - out.write_vertical_source_list(&self.fields, ListType::Cap(";")); + out.write_vertical_source_list( + &self.fields, + ListType::Cap(if config.language != Language::Zig { + ";" + } else { + "," + }), + ); if config.language == Language::Cython && self.fields.is_empty() { out.write("pass"); } diff --git a/tests/expectations/enum_self.zig b/tests/expectations/enum_self.zig index 95a0b682a..5d441e60e 100644 --- a/tests/expectations/enum_self.zig +++ b/tests/expectations/enum_self.zig @@ -1 +1,21 @@ const std = @import("std"); + +pub const Foo_Bar = extern struct { + something: ?*i32, +}; + +pub const Bar_Tag = enum { + Min, + Max, + Other, +}; + +pub const Bar = extern union { + tag: Bar_Tag, + min_tag: Bar_Tag, + min: Foo_Bar, + max_tag: Bar_Tag, + max: Foo_Bar, +}; + +pub extern fn root(b: Bar) anyopaque;