From 81dfc1d0e9b032eff54173df21c043c14043ae54 Mon Sep 17 00:00:00 2001 From: Alexander Arvidsson <2972103+AlexanderArvidsson@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:37:34 +0100 Subject: [PATCH] bindgen: Include top comment in Zig & Odin --- bindgen/gen_ir.py | 5 ++++- bindgen/gen_odin.py | 3 +++ bindgen/gen_zig.py | 7 +++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bindgen/gen_ir.py b/bindgen/gen_ir.py index 3b3947e4b..cbeea3e8b 100644 --- a/bindgen/gen_ir.py +++ b/bindgen/gen_ir.py @@ -1,7 +1,7 @@ #------------------------------------------------------------------------------- # Generate an intermediate representation of a clang AST dump. #------------------------------------------------------------------------------- -import json, sys, subprocess +import re, json, sys, subprocess def is_api_decl(decl, prefix): if 'name' in decl: @@ -136,6 +136,9 @@ def gen(header_path, source_path, module, main_prefix, dep_prefixes, with_commen outp['decls'] = [] with open(header_path, 'r') as f: source = f.read() + first_comment = re.search(r"/\*(.*?)\*/", source, re.S).group(1) + if first_comment and "Project URL" in first_comment: + outp['comment'] = first_comment for decl in inp['inner']: is_dep = is_dep_decl(decl, dep_prefixes) if is_api_decl(decl, main_prefix) or is_dep: diff --git a/bindgen/gen_odin.py b/bindgen/gen_odin.py index 8d4588f9c..42d587051 100644 --- a/bindgen/gen_odin.py +++ b/bindgen/gen_odin.py @@ -509,6 +509,9 @@ def gen_module(inp, c_prefix, dep_prefixes): l('// machine generated, do not edit') l('') l(f"package sokol_{inp['module']}") + if inp.get('comment'): + l('') + c(inp['comment']) gen_imports(dep_prefixes) gen_helpers(inp) prefix = inp['prefix'] diff --git a/bindgen/gen_zig.py b/bindgen/gen_zig.py index 446585e48..f90e53ec7 100644 --- a/bindgen/gen_zig.py +++ b/bindgen/gen_zig.py @@ -126,10 +126,10 @@ def l(s): global out_lines out_lines += s + '\n' -def c(s, indent=""): +def c(s, indent="", comment="///"): if not s: return - prefix = f"{indent}///" + prefix = f"{indent}{comment}" for line in textwrap.dedent(s).splitlines(): l(f"{prefix} {line}" if line else prefix ) @@ -554,6 +554,9 @@ def gen_helpers(inp): def gen_module(inp, dep_prefixes): l('// machine generated, do not edit') + if inp.get('comment'): + l('') + c(inp['comment'], comment="//") l('') gen_imports(inp, dep_prefixes) gen_helpers(inp)