gen_zig.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. #-------------------------------------------------------------------------------
  2. # Generate Zig bindings.
  3. #
  4. # Zig coding style:
  5. # - types are PascalCase
  6. # - functions are camelCase
  7. # - otherwise snake_case
  8. #-------------------------------------------------------------------------------
  9. import gen_ir
  10. import os, shutil, sys
  11. import textwrap
  12. import gen_util as util
  13. module_names = {
  14. 'slog_': 'log',
  15. 'sg_': 'gfx',
  16. 'sapp_': 'app',
  17. 'stm_': 'time',
  18. 'saudio_': 'audio',
  19. 'sgl_': 'gl',
  20. 'sdtx_': 'debugtext',
  21. 'sshape_': 'shape',
  22. 'sglue_': 'glue',
  23. 'sfetch_': 'fetch',
  24. 'simgui_': 'imgui',
  25. }
  26. c_source_paths = {
  27. 'slog_': 'sokol-zig/src/sokol/c/sokol_log.c',
  28. 'sg_': 'sokol-zig/src/sokol/c/sokol_gfx.c',
  29. 'sapp_': 'sokol-zig/src/sokol/c/sokol_app.c',
  30. 'stm_': 'sokol-zig/src/sokol/c/sokol_time.c',
  31. 'saudio_': 'sokol-zig/src/sokol/c/sokol_audio.c',
  32. 'sgl_': 'sokol-zig/src/sokol/c/sokol_gl.c',
  33. 'sdtx_': 'sokol-zig/src/sokol/c/sokol_debugtext.c',
  34. 'sshape_': 'sokol-zig/src/sokol/c/sokol_shape.c',
  35. 'sglue_': 'sokol-zig/src/sokol/c/sokol_glue.c',
  36. 'sfetch_': 'sokol-zig/src/sokol/c/sokol_fetch.c',
  37. 'simgui_': 'sokol-zig/src/sokol/c/sokol_imgui.c',
  38. }
  39. ignores = [
  40. 'sdtx_printf',
  41. 'sdtx_vprintf',
  42. 'sg_install_trace_hooks',
  43. 'sg_trace_hooks',
  44. ]
  45. # functions that need to be exposed as 'raw' C callbacks without a Zig wrapper function
  46. c_callbacks = [
  47. 'slog_func'
  48. ]
  49. # NOTE: syntax for function results: "func_name.RESULT"
  50. overrides = {
  51. 'sgl_error': 'sgl_get_error', # 'error' is reserved in Zig
  52. 'sgl_deg': 'sgl_as_degrees',
  53. 'sgl_rad': 'sgl_as_radians',
  54. 'sg_apply_uniforms.ub_slot': 'uint32_t',
  55. 'sg_draw.base_element': 'uint32_t',
  56. 'sg_draw.num_elements': 'uint32_t',
  57. 'sg_draw.num_instances': 'uint32_t',
  58. 'sshape_element_range_t.base_element': 'uint32_t',
  59. 'sshape_element_range_t.num_elements': 'uint32_t',
  60. 'sdtx_font.font_index': 'uint32_t',
  61. 'SGL_NO_ERROR': 'SGL_ERROR_NO_ERROR',
  62. 'sfetch_continue': 'continue_fetching', # 'continue' is reserved in Zig
  63. 'sfetch_desc': 'sfetch_get_desc' # 'desc' shadowed by earlier definition
  64. }
  65. prim_types = {
  66. 'int': 'i32',
  67. 'bool': 'bool',
  68. 'char': 'u8',
  69. 'int8_t': 'i8',
  70. 'uint8_t': 'u8',
  71. 'int16_t': 'i16',
  72. 'uint16_t': 'u16',
  73. 'int32_t': 'i32',
  74. 'uint32_t': 'u32',
  75. 'int64_t': 'i64',
  76. 'uint64_t': 'u64',
  77. 'float': 'f32',
  78. 'double': 'f64',
  79. 'uintptr_t': 'usize',
  80. 'intptr_t': 'isize',
  81. 'size_t': 'usize'
  82. }
  83. prim_defaults = {
  84. 'int': '0',
  85. 'bool': 'false',
  86. 'int8_t': '0',
  87. 'uint8_t': '0',
  88. 'int16_t': '0',
  89. 'uint16_t': '0',
  90. 'int32_t': '0',
  91. 'uint32_t': '0',
  92. 'int64_t': '0',
  93. 'uint64_t': '0',
  94. 'float': '0.0',
  95. 'double': '0.0',
  96. 'uintptr_t': '0',
  97. 'intptr_t': '0',
  98. 'size_t': '0'
  99. }
  100. struct_types = []
  101. enum_types = []
  102. enum_items = {}
  103. out_lines = ''
  104. def reset_globals():
  105. global struct_types
  106. global enum_types
  107. global enum_items
  108. global out_lines
  109. struct_types = []
  110. enum_types = []
  111. enum_items = {}
  112. out_lines = ''
  113. def l(s):
  114. global out_lines
  115. out_lines += s + '\n'
  116. def c(s, indent="", comment="///"):
  117. if not s:
  118. return
  119. prefix = f"{indent}{comment}"
  120. for line in textwrap.dedent(s).splitlines():
  121. l(f"{prefix} {line}" if line else prefix )
  122. def as_zig_prim_type(s):
  123. return prim_types[s]
  124. # prefix_bla_blub(_t) => (dep.)BlaBlub
  125. def as_zig_struct_type(s, prefix):
  126. parts = s.lower().split('_')
  127. outp = '' if s.startswith(prefix) else f'{parts[0]}.'
  128. for part in parts[1:]:
  129. # ignore '_t' type postfix
  130. if (part != 't'):
  131. outp += part.capitalize()
  132. return outp
  133. # prefix_bla_blub(_t) => (dep.)BlaBlub
  134. def as_zig_enum_type(s, prefix):
  135. parts = s.lower().split('_')
  136. outp = '' if s.startswith(prefix) else f'{parts[0]}.'
  137. for part in parts[1:]:
  138. if (part != 't'):
  139. outp += part.capitalize()
  140. return outp
  141. def check_override(name, default=None):
  142. if name in overrides:
  143. return overrides[name]
  144. elif default is None:
  145. return name
  146. else:
  147. return default
  148. def check_ignore(name):
  149. return name in ignores
  150. # PREFIX_ENUM_BLA => Bla, _PREFIX_ENUM_BLA => Bla
  151. def as_enum_item_name(s):
  152. outp = s.lstrip('_')
  153. parts = outp.split('_')[2:]
  154. outp = '_'.join(parts)
  155. if outp[0].isdigit():
  156. outp = '_' + outp
  157. return outp
  158. def enum_default_item(enum_name):
  159. return enum_items[enum_name][0]
  160. def is_prim_type(s):
  161. return s in prim_types
  162. def is_struct_type(s):
  163. return s in struct_types
  164. def is_enum_type(s):
  165. return s in enum_types
  166. def is_const_prim_ptr(s):
  167. for prim_type in prim_types:
  168. if s == f"const {prim_type} *":
  169. return True
  170. return False
  171. def is_prim_ptr(s):
  172. for prim_type in prim_types:
  173. if s == f"{prim_type} *":
  174. return True
  175. return False
  176. def is_const_struct_ptr(s):
  177. for struct_type in struct_types:
  178. if s == f"const {struct_type} *":
  179. return True
  180. return False
  181. def type_default_value(s):
  182. return prim_defaults[s]
  183. def as_c_arg_type(arg_type, prefix):
  184. if arg_type == "void":
  185. return "void"
  186. elif is_prim_type(arg_type):
  187. return as_zig_prim_type(arg_type)
  188. elif is_struct_type(arg_type):
  189. return as_zig_struct_type(arg_type, prefix)
  190. elif is_enum_type(arg_type):
  191. return as_zig_enum_type(arg_type, prefix)
  192. elif util.is_void_ptr(arg_type):
  193. return "?*anyopaque"
  194. elif util.is_const_void_ptr(arg_type):
  195. return "?*const anyopaque"
  196. elif util.is_string_ptr(arg_type):
  197. return "[*c]const u8"
  198. elif is_const_struct_ptr(arg_type):
  199. return f"[*c]const {as_zig_struct_type(util.extract_ptr_type(arg_type), prefix)}"
  200. elif is_prim_ptr(arg_type):
  201. return f"[*c]{as_zig_prim_type(util.extract_ptr_type(arg_type))}"
  202. elif is_const_prim_ptr(arg_type):
  203. return f"[*c]const {as_zig_prim_type(util.extract_ptr_type(arg_type))}"
  204. else:
  205. sys.exit(f"Error as_c_arg_type(): {arg_type}")
  206. def as_zig_arg_type(arg_prefix, arg_type, prefix):
  207. # NOTE: if arg_prefix is None, the result is used as return value
  208. pre = "" if arg_prefix is None else arg_prefix
  209. if arg_type == "void":
  210. if arg_prefix is None:
  211. return "void"
  212. else:
  213. return ""
  214. elif is_prim_type(arg_type):
  215. return pre + as_zig_prim_type(arg_type)
  216. elif is_struct_type(arg_type):
  217. return pre + as_zig_struct_type(arg_type, prefix)
  218. elif is_enum_type(arg_type):
  219. return pre + as_zig_enum_type(arg_type, prefix)
  220. elif util.is_void_ptr(arg_type):
  221. return pre + "?*anyopaque"
  222. elif util.is_const_void_ptr(arg_type):
  223. return pre + "?*const anyopaque"
  224. elif util.is_string_ptr(arg_type):
  225. return pre + "[:0]const u8"
  226. elif is_const_struct_ptr(arg_type):
  227. # not a bug, pass const structs by value
  228. return pre + f"{as_zig_struct_type(util.extract_ptr_type(arg_type), prefix)}"
  229. elif is_prim_ptr(arg_type):
  230. return pre + f"*{as_zig_prim_type(util.extract_ptr_type(arg_type))}"
  231. elif is_const_prim_ptr(arg_type):
  232. return pre + f"*const {as_zig_prim_type(util.extract_ptr_type(arg_type))}"
  233. else:
  234. sys.exit(f"ERROR as_zig_arg_type(): {arg_type}")
  235. def is_zig_string(zig_type):
  236. return zig_type == "[:0]const u8"
  237. # get C-style arguments of a function pointer as string
  238. def funcptr_args_c(field_type, prefix):
  239. tokens = field_type[field_type.index('(*)')+4:-1].split(',')
  240. s = ""
  241. for token in tokens:
  242. arg_type = token.strip()
  243. if s != "":
  244. s += ", "
  245. c_arg = as_c_arg_type(arg_type, prefix)
  246. if c_arg == "void":
  247. return ""
  248. else:
  249. s += c_arg
  250. return s
  251. # get C-style result of a function pointer as string
  252. def funcptr_result_c(field_type):
  253. res_type = field_type[:field_type.index('(*)')].strip()
  254. if res_type == 'void':
  255. return 'void'
  256. elif is_prim_type(res_type):
  257. return as_zig_prim_type(res_type)
  258. elif util.is_const_void_ptr(res_type):
  259. return '?*const anyopaque'
  260. elif util.is_void_ptr(res_type):
  261. return '?*anyopaque'
  262. else:
  263. sys.exit(f"ERROR funcptr_result_c(): {field_type}")
  264. def funcdecl_args_c(decl, prefix):
  265. s = ""
  266. func_name = decl['name']
  267. for param_decl in decl['params']:
  268. if s != "":
  269. s += ", "
  270. param_name = param_decl['name']
  271. param_type = check_override(f'{func_name}.{param_name}', default=param_decl['type'])
  272. s += as_c_arg_type(param_type, prefix)
  273. return s
  274. def funcdecl_args_zig(decl, prefix):
  275. s = ""
  276. func_name = decl['name']
  277. for param_decl in decl['params']:
  278. if s != "":
  279. s += ", "
  280. param_name = param_decl['name']
  281. param_type = check_override(f'{func_name}.{param_name}', default=param_decl['type'])
  282. s += f"{as_zig_arg_type(f'{param_name}: ', param_type, prefix)}"
  283. return s
  284. def funcdecl_result_c(decl, prefix):
  285. func_name = decl['name']
  286. decl_type = decl['type']
  287. result_type = check_override(f'{func_name}.RESULT', default=decl_type[:decl_type.index('(')].strip())
  288. return as_c_arg_type(result_type, prefix)
  289. def funcdecl_result_zig(decl, prefix):
  290. func_name = decl['name']
  291. decl_type = decl['type']
  292. result_type = check_override(f'{func_name}.RESULT', default=decl_type[:decl_type.index('(')].strip())
  293. zig_res_type = as_zig_arg_type(None, result_type, prefix)
  294. return zig_res_type
  295. def gen_struct(decl, prefix):
  296. struct_name = check_override(decl['name'])
  297. zig_type = as_zig_struct_type(struct_name, prefix)
  298. c(decl.get('comment'))
  299. l(f"pub const {zig_type} = extern struct {{")
  300. for field in decl['fields']:
  301. field_name = check_override(field['name'])
  302. field_type = check_override(f'{struct_name}.{field_name}', default=field['type'])
  303. if is_prim_type(field_type):
  304. l(f" {field_name}: {as_zig_prim_type(field_type)} = {type_default_value(field_type)},")
  305. elif is_struct_type(field_type):
  306. l(f" {field_name}: {as_zig_struct_type(field_type, prefix)} = .{{}},")
  307. elif is_enum_type(field_type):
  308. l(f" {field_name}: {as_zig_enum_type(field_type, prefix)} = .{enum_default_item(field_type)},")
  309. elif util.is_string_ptr(field_type):
  310. l(f" {field_name}: [*c]const u8 = null,")
  311. elif util.is_const_void_ptr(field_type):
  312. l(f" {field_name}: ?*const anyopaque = null,")
  313. elif util.is_void_ptr(field_type):
  314. l(f" {field_name}: ?*anyopaque = null,")
  315. elif is_const_prim_ptr(field_type):
  316. l(f" {field_name}: ?[*]const {as_zig_prim_type(util.extract_ptr_type(field_type))} = null,")
  317. elif util.is_func_ptr(field_type):
  318. l(f" {field_name}: ?*const fn ({funcptr_args_c(field_type, prefix)}) callconv(.c) {funcptr_result_c(field_type)} = null,")
  319. elif util.is_1d_array_type(field_type):
  320. array_type = util.extract_array_type(field_type)
  321. array_sizes = util.extract_array_sizes(field_type)
  322. if is_prim_type(array_type) or is_struct_type(array_type):
  323. if is_prim_type(array_type):
  324. zig_type = as_zig_prim_type(array_type)
  325. def_val = type_default_value(array_type)
  326. elif is_struct_type(array_type):
  327. zig_type = as_zig_struct_type(array_type, prefix)
  328. def_val = '.{}'
  329. elif is_enum_type(array_type):
  330. zig_type = as_zig_enum_type(array_type, prefix)
  331. def_val = '.{}'
  332. else:
  333. sys.exit(f"ERROR gen_struct is_1d_array_type: {array_type}")
  334. t0 = f"[{array_sizes[0]}]{zig_type}"
  335. t1 = f"[_]{zig_type}"
  336. l(f" {field_name}: {t0} = {t1}{{{def_val}}} ** {array_sizes[0]},")
  337. elif util.is_const_void_ptr(array_type):
  338. l(f" {field_name}: [{array_sizes[0]}]?*const anyopaque = [_]?*const anyopaque{{null}} ** {array_sizes[0]},")
  339. else:
  340. sys.exit(f"ERROR gen_struct: array {field_name}: {field_type} => {array_type} [{array_sizes[0]}]")
  341. elif util.is_2d_array_type(field_type):
  342. array_type = util.extract_array_type(field_type)
  343. array_sizes = util.extract_array_sizes(field_type)
  344. if is_prim_type(array_type):
  345. zig_type = as_zig_prim_type(array_type)
  346. def_val = type_default_value(array_type)
  347. elif is_struct_type(array_type):
  348. zig_type = as_zig_struct_type(array_type, prefix)
  349. def_val = ".{}"
  350. else:
  351. sys.exit(f"ERROR gen_struct is_2d_array_type: {array_type}")
  352. t0 = f"[{array_sizes[0]}][{array_sizes[1]}]{zig_type}"
  353. l(f" {field_name}: {t0} = [_][{array_sizes[1]}]{zig_type}{{[_]{zig_type}{{{def_val}}} ** {array_sizes[1]}}} ** {array_sizes[0]},")
  354. else:
  355. sys.exit(f"ERROR gen_struct: {field_name}: {field_type};")
  356. l("};")
  357. l("")
  358. def gen_consts(decl, prefix):
  359. c(decl.get('comment'))
  360. for item in decl['items']:
  361. item_name = check_override(item['name'])
  362. c(item.get('comment'))
  363. l(f"pub const {util.as_lower_snake_case(item_name, prefix)} = {item['value']};")
  364. l("")
  365. def gen_enum(decl, prefix):
  366. enum_name = check_override(decl['name'])
  367. c(decl.get('comment'))
  368. l(f"pub const {as_zig_enum_type(enum_name, prefix)} = enum(i32) {{")
  369. for item in decl['items']:
  370. item_name = as_enum_item_name(check_override(item['name']))
  371. if item_name != "FORCE_U32":
  372. if 'value' in item:
  373. l(f" {item_name} = {item['value']},")
  374. else:
  375. l(f" {item_name},")
  376. l("};")
  377. l("")
  378. def gen_func_c(decl, prefix):
  379. c(decl.get('comment'))
  380. l(f"extern fn {decl['name']}({funcdecl_args_c(decl, prefix)}) {funcdecl_result_c(decl, prefix)};")
  381. l('')
  382. def gen_func_zig(decl, prefix, tiger_style=False):
  383. c_func_name = decl['name']
  384. if not tiger_style:
  385. zig_func_name = util.as_lower_camel_case(check_override(decl['name']), prefix)
  386. else:
  387. zig_func_name = util.as_lower_snake_case(check_override(decl['name']), prefix)
  388. c(decl.get('comment'))
  389. if c_func_name in c_callbacks:
  390. # a simple forwarded C callback function
  391. l(f"pub const {zig_func_name} = {c_func_name};")
  392. else:
  393. zig_res_type = funcdecl_result_zig(decl, prefix)
  394. l(f"pub fn {zig_func_name}({funcdecl_args_zig(decl, prefix)}) {zig_res_type} {{")
  395. if is_zig_string(zig_res_type):
  396. # special case: convert C string to Zig string slice
  397. s = f" return cStrToZig({c_func_name}("
  398. elif zig_res_type != 'void':
  399. s = f" return {c_func_name}("
  400. else:
  401. s = f" {c_func_name}("
  402. for i, param_decl in enumerate(decl['params']):
  403. if i > 0:
  404. s += ", "
  405. arg_name = param_decl['name']
  406. arg_type = param_decl['type']
  407. if is_const_struct_ptr(arg_type):
  408. s += f"&{arg_name}"
  409. elif util.is_string_ptr(arg_type):
  410. s += f"@ptrCast({arg_name})"
  411. else:
  412. s += arg_name
  413. if is_zig_string(zig_res_type):
  414. s += ")"
  415. s += ");"
  416. l(s)
  417. l("}")
  418. l("")
  419. def pre_parse(inp):
  420. global struct_types
  421. global enum_types
  422. for decl in inp['decls']:
  423. kind = decl['kind']
  424. if kind == 'struct':
  425. struct_types.append(decl['name'])
  426. elif kind == 'enum':
  427. enum_name = decl['name']
  428. enum_types.append(enum_name)
  429. enum_items[enum_name] = []
  430. for item in decl['items']:
  431. enum_items[enum_name].append(as_enum_item_name(item['name']))
  432. def gen_imports(inp, dep_prefixes):
  433. l('const builtin = @import("builtin");')
  434. for dep_prefix in dep_prefixes:
  435. dep_module_name = module_names[dep_prefix]
  436. l(f'const {dep_prefix[:-1]} = @import("{dep_module_name}.zig");')
  437. l('')
  438. def gen_helpers(inp):
  439. l('// helper function to convert a C string to a Zig string slice')
  440. l('fn cStrToZig(c_str: [*c]const u8) [:0]const u8 {')
  441. l(' return @import("std").mem.span(c_str);')
  442. l('}')
  443. if inp['prefix'] in ['sg_', 'sdtx_', 'sshape_', 'sfetch_']:
  444. l('// helper function to convert "anything" to a Range struct')
  445. l('pub fn asRange(val: anytype) Range {')
  446. l(' const type_info = @typeInfo(@TypeOf(val));')
  447. l(' switch (type_info) {')
  448. l(' .pointer => {')
  449. l(' switch (type_info.pointer.size) {')
  450. l(' .one => return .{ .ptr = val, .size = @sizeOf(type_info.pointer.child) },')
  451. l(' .slice => return .{ .ptr = val.ptr, .size = @sizeOf(type_info.pointer.child) * val.len },')
  452. l(' else => @compileError("FIXME: Pointer type!"),')
  453. l(' }')
  454. l(' },')
  455. l(' .@"struct", .array => {')
  456. l(' @compileError("Structs and arrays must be passed as pointers to asRange");')
  457. l(' },')
  458. l(' else => {')
  459. l(' @compileError("Cannot convert to range!");')
  460. l(' },')
  461. l(' }')
  462. l('}')
  463. l('')
  464. if inp['prefix'] == 'sdtx_':
  465. l('// std.fmt-style formatted print')
  466. l('pub fn print(comptime fmt: anytype, args: anytype) void {')
  467. l(' const cbuf = getClearedFmtBuffer();')
  468. l(' const p: [*]u8 = @constCast(@ptrCast(cbuf.ptr));')
  469. l(' const buf = p[0..cbuf.size];')
  470. l(' const out = @import("std").fmt.bufPrint(buf, fmt, args) catch "";')
  471. l(' for (out) |c| putc(c);')
  472. l('}')
  473. l('')
  474. def gen_module(inp, dep_prefixes, opt={}):
  475. l('// machine generated, do not edit')
  476. if inp.get('comment'):
  477. l('')
  478. c(inp['comment'], comment="//")
  479. l('')
  480. gen_imports(inp, dep_prefixes)
  481. gen_helpers(inp)
  482. pre_parse(inp)
  483. prefix = inp['prefix']
  484. for decl in inp['decls']:
  485. if not decl['is_dep']:
  486. kind = decl['kind']
  487. if kind == 'consts':
  488. gen_consts(decl, prefix)
  489. elif not check_ignore(decl['name']):
  490. if kind == 'struct':
  491. gen_struct(decl, prefix)
  492. elif kind == 'enum':
  493. gen_enum(decl, prefix)
  494. elif kind == 'func':
  495. gen_func_c(decl, prefix)
  496. tiger_style = opt.get('tiger-style', False)
  497. gen_func_zig(decl, prefix, tiger_style=tiger_style)
  498. def prepare():
  499. print('=== Generating Zig bindings:')
  500. if not os.path.isdir('sokol-zig/src/sokol'):
  501. os.makedirs('sokol-zig/src/sokol')
  502. if not os.path.isdir('sokol-zig/src/sokol/c'):
  503. os.makedirs('sokol-zig/src/sokol/c')
  504. def gen(c_header_path, c_prefix, dep_c_prefixes, opt={}):
  505. if not c_prefix in module_names:
  506. print(f' >> warning: skipping generation for {c_prefix} prefix...')
  507. return
  508. module_name = module_names[c_prefix]
  509. c_source_path = c_source_paths[c_prefix]
  510. print(f' {c_header_path} => {module_name}')
  511. reset_globals()
  512. shutil.copyfile(c_header_path, f'sokol-zig/src/sokol/c/{os.path.basename(c_header_path)}')
  513. ir = gen_ir.gen(c_header_path, c_source_path, module_name, c_prefix, dep_c_prefixes, with_comments=True)
  514. gen_module(ir, dep_c_prefixes, opt)
  515. output_path = f"sokol-zig/src/sokol/{ir['module']}.zig"
  516. with open(output_path, 'w', newline='\n') as f_outp:
  517. f_outp.write(out_lines)