zig icon indicating copy to clipboard operation
zig copied to clipboard

ship .idl files rather than .h files for windows SDK

Open andrewrk opened this issue 1 year ago • 8 comments

This is a toolchain installation size optimization.

Many of the C header files Zig ships that come from mingw-w64 have this header:

/*** Autogenerated by WIDL 8.5 from include/xpsrassvc.idl - Do not edit ***/

If we compare total file sizes, it comes out to roughly 40 MiB reduced to 10 MiB:

[nix-shell:~/Downloads/mingw-w64/mingw-w64-headers]$ cat $(find -name "*.idl") | wc -c
10436832

[nix-shell:~/Downloads/mingw-w64/mingw-w64-headers]$ cat $(grep -RIl "Autogenerated by WIDL") | wc -c
41764448

In terms of tarball size it's roughly 2.4 MiB to 724 KB:

[nix-shell:~/Downloads/mingw-w64/mingw-w64-headers]$ cat $(find -name "*.idl") | xz | wc -c
740960

[nix-shell:~/Downloads/mingw-w64/mingw-w64-headers]$ cat $(grep -RIl "Autogenerated by WIDL") | xz | wc -c
2490188

A prerequisite for this issue would be a WIDL implementation in Zig. That could be a fun project for a contributor.

andrewrk avatar Jan 07 '24 23:01 andrewrk

Exposing such a parser to the user would enable generating bindings to the COM and WinRT APIs.

odecaux avatar Jan 15 '24 16:01 odecaux

is this the same IDL that's https://webidl.spec.whatwg.org ?

edit: hmm there are similarities but I think its different https://android.googlesource.com/toolchain/mingw/+/refs/heads/main/mingw-w64-v6.x/mingw-w64-headers/include/xpsrassvc.idl

nektro avatar Jan 15 '24 18:01 nektro

Microsoft Windows IDL: https://learn.microsoft.com/en-us/uwp/midl-3/

Paul-Dempsey avatar Jan 15 '24 19:01 Paul-Dempsey

Wine has an implementation you can look at. There's also one in mingw-w64 which may or may not just be the code ported from Wine.

andrewrk avatar Jan 15 '24 19:01 andrewrk

Hi, wanna ask a few questions to make sure I understand the issue properly.

Windows SDK from downloaded from MS includes all the .idl and .h of Windows SDK. Since it is not compatible with gnu libc (used with Clang when zig compiles), so Zig doesn't use it. Instead the .h distributed by mingw-w64 is used. These header files are generated by manually parsing the .idl into a gnu libc compatible form of headers (by Migw-w64's widl).

Now since those .h files are big, and they only exist for zig to understand the ABI, doing .idl -> .zig glue code would bring benefits in minimizing dependency, compiler size, improve compatability, probably decrease compiling speed, and make bug management easier.

Am I understanding correctly? Sorry if these are naive questions.

harrylaulau avatar Jan 19 '24 12:01 harrylaulau

Do you suggest using the wine implementation, e.g. zig with cpp bindings, or pure zig solution? I'm interested in the latter.

xinlifoobar avatar Feb 09 '24 14:02 xinlifoobar

Pure zig solution, obviously :-)

andrewrk avatar Feb 09 '24 19:02 andrewrk

Is the status of this issue changed by https://github.com/ziglang/zig/issues/16269#issuecomment-2241286865?

sno2 avatar Jul 20 '24 20:07 sno2

I would be interested in having a look at this, could you clarify the intended outcome, what options are you considering for this widl integration ?

  • No language change:
    • translate the distributed .idl files to .h files once at first usage, which will reduce the distributed tarball size but not the installed files
  • A builtin command similar or within @cImport like @idlImport("stuff.idl"), and this could either
    • produce C header content from the IDL file on the fly then feed them to the existing @cImport mecanism
    • directly produce Zig's ast nodes from the IDL without the above indirection
  • Something else ?

NyuB avatar Jan 12 '25 10:01 NyuB

I've created an early wip idl compiler here: https://github.com/tiehuis/zidl

tiehuis avatar May 16 '25 07:05 tiehuis