Skip to content

Commit

Permalink
bindgen: Include top comment in Zig & Odin
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderArvidsson committed Jan 7, 2025
1 parent 5b3f88b commit 81dfc1d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion bindgen/gen_ir.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions bindgen/gen_odin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
7 changes: 5 additions & 2 deletions bindgen/gen_zig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 81dfc1d

Please sign in to comment.