floooh / sokol

minimal cross-platform standalone C headers
https://floooh.github.io/sokol-html5
zlib License
6.53k stars 467 forks source link

Seems .c file not generated in bindgen, producing errors #1060

Closed brytonsf closed 1 month ago

brytonsf commented 1 month ago

Hi. I'm trying to write a binding generator for Swift.

I run python3 gen_all.py from within /bindgen and see the following result/logs/error:

bindgen % python3 gen_all.py
=== Generating Odin bindings:
  ../sokol_log.h => log
clang: error: no such file or directory: 'sokol-odin/sokol/c/sokol_log.c'
clang: error: no input files
Traceback (most recent call last):
  File "/Users/bryton/Desktop/sokol/bindgen/gen_all.py", line 19, in <module>
    gen_odin.gen(c_header_path, main_prefix, dep_prefixes)
  File "/Users/bryton/Desktop/sokol/bindgen/gen_odin.py", line 532, in gen
    ir = gen_ir.gen(c_header_path, csource_path, module_name, c_prefix, dep_c_prefixes)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bryton/Desktop/sokol/bindgen/gen_ir.py", line 108, in gen
    ast = clang(source_path)
          ^^^^^^^^^^^^^^^^^^
  File "/Users/bryton/Desktop/sokol/bindgen/gen_ir.py", line 104, in clang
    return subprocess.check_output(cmd)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 466, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['clang', '-Xclang', '-ast-dump=json', '-c', 'sokol-odin/sokol/c/sokol_log.c']' returned non-zero exit status 1.

So, sokol_log.c doesn't seem to exist. sokol_log.h does get created. This seems to make sense, it seems the following things happen:

  1. sokol_log.h gets created via [lang-specific bindgen e.g. rust/odin].gen(...)
  2. gen_ir.gen(...) is called w/ an expected .c file

But in between steps 1 and 2, it doesn't seem like this .c file is generated! So this behavior makes sense. But in more global/holistic context, it doesn't make sense, I'd assume python3 gen_all.py should just work, and that these .c files should exist or be generated in the python script somehow. I am not sure what I'm missing here. I'm pretty C-ignorant, btw.

Maybe I should clone sokol-zig, sokol-nim, sokol-rust etc., first? That doesn't make sense to me, since the bindgen should create those things, right? This might be indicated by the bindgen doc, although it's under the Zig heading, so it's a bit confusing. I see in the gen bindings workflow that those repos are cloned before running the python bindgen script... But then those gen'd bindings are uploaded as repos? Seems circular, I don't understand.

brytonsf commented 1 month ago

I suppose I still have this issue, but right now I'm trying to use Sokol directly from Swift. I think it'd still make sense to generate bindings though, because otherwise I'm using a bunch of UnsafePointers in Swift...

floooh commented 1 month ago

Those .c files are not generated but are part of the sokol-odin repository. Basically, before running gen_all.py you need to clone the following respositories into the sokol/bindings directory, otherwise generation will fail:

Also see the gen_bindings.yml GH Action snippet here:

https://github.com/floooh/sokol/blob/7b5cfa72b3188b239c23ec0f0eb7a810ec128dd4/.github/workflows/gen_bindings.yml#L45-L68

Alternatively you can simply out-comment the languages you don't need in gen_all.py, in that case the respective subdirectories are not needed:

https://github.com/floooh/sokol/blob/master/bindgen/gen_all.py