floooh / sokol

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

Update zig bindgen produce source that matches "zig fmt" style #849

Closed nurpax closed 1 year ago

nurpax commented 1 year ago

for #39, #40

nurpax commented 1 year ago

Tested by running this in the bindgen sub-directory:

import glob
import subprocess

def main():
    for file in glob.glob('sokol-zig/src/sokol/*.zig'):
        # Open the file and read its contents
        with open(file, 'rt', encoding='utf-8') as f:
            file_contents = f.read()
        p = subprocess.run('zig fmt --stdin', input=file_contents, shell=True, text=True, capture_output=True)
        with open(f'{file}.fmt', 'wt', encoding='utf-8') as f:
            f.write(p.stdout)
        diff_fname = f'{file}.patch'
        p = subprocess.run(["diff", '-u', file, f'{file}.fmt'], text=True, capture_output=True)
        with open(diff_fname, 'wt', encoding='utf-8') as f:
            f.write(p.stdout)
        print('wrote', diff_fname)

if __name__ == '__main__':
    main()

This writes <zig src>.fmt (zig fmt'd version) and <zig src>.patch files in the zig source directory. Patch is expected to be empty if bindgen output matches what zig fmt outputs.

I didn't test compiling the output. I'd wait for the pending zig devel changes to go in first.

floooh commented 1 year ago

Very nice, thanks! I'll merge right after the CI pipeline ran through.

...I'll merge in coordination with the other PRs, and will also check with the latest Zig dev version first. Might take a bit longer :)

floooh commented 1 year ago

Ok, here's the plan: I'll merge this PR into a new branch [bindgen-sokol-zig-0.11.0](https://github.com/floooh/sokol/tree/bindgen-sokol-zig-0.11.0) and then will use this together with the pending PR in sokol-zig to get the 0.11.0 branch in sokol-zig uptodate.

...we can then also collect any more bindgen changes targeted at for zig 0.11.0 into this new bindgen-sokol-zig-0.11.0 branch, and when zig 0.11.0 is released we merge that into master.

floooh commented 1 year ago

Ok, I think the branch zig-0.11.0 is now back in good shape. This also has the latest headers from the main branch, including example fixes (had some trouble merghing because of the fmt fixes, hopefully zig-0.11.0 isn't too far out so that we can put everything back on the respective master branches)

(oops this comment should go into sokol-zig, but anyway)