-
Notifications
You must be signed in to change notification settings - Fork 17.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/sys/windows: use win32metadata? #43838
Comments
That's a great idea. https://docs.microsoft.com/en-us/uwp/winrt-cref/winmd-files is the file format. I'd be in favor of making |
CC @jstarks in case you're interested too. |
At that point would it make sense to rewrite |
Yes, this sounds like a great idea. I agree that starting fresh, rather than trying to replat Note that there are fidelity issues with win32metadata today--for example, C unions are not yet supported correctly. But I'm told the team is working on it. I bet @sotteson1 and @kennykerr would be happy to give advice and take feedback. |
That would potentially be a lot of work but wouldn't be impossible. It'd probably easier, though, to just deprecate x/sys/windows and encourage people to gradually move over to x/windows/win32 (or x/windows/winrt). |
C unions are the big annoying thing for Go too, and we'd probably want to come up with an overall approach at handling these, whether it's just using |
Note that the metadata fully supports C-style unions. Some of the early language support don't yet support them, but the metadata is ready for consumption/trial. |
Ah, good, I misunderstood the source of the union bug in the Rust crate. Thanks Kenny. |
Does this mean golang's CGO will link with MSVC compiler in future? or I am missing something. If I am correct, golang on windows works with MingGW & not MSVC |
CGO and MSVC are unrelated concerns to this one, as far as I can see here. |
Yes, I agree with most of what you said. We'll try not to repeat the mistakes of x/sys/windows, of which there are many many, when generating from winmd. Fully generating it means we can easily tweak the output format until it looks like something acceptable. And relaxing the compatibility requirements -- mentioned in #43838 (comment) -- means that we'd be able to actually perfect the output, rather than getting stuck with inconsistent signatures, like the one you mentioned. |
I cannot begin to tell you how much I want this feature. 💯 |
Note that the file referenced in Brad's first comment here is now located at https://github.com/microsoft/windows-rs/blob/master/crates/gen/default/Windows.Win32.winmd |
To follow up, that file can be fetched from this package: https://www.nuget.org/packages/Microsoft.Windows.SDK.Win32Metadata Download and unzip the file (nuget packages are just zip files) and you should find |
I also just discovered today that WinMD files are valid PE files, so someone could potentially use |
Regarding parsing the WinMD files, Jonathan Marler created a project to generate JSON representation from the win32 metadata, which was used to create the win32 binding for Zig. There's also a talk on Youtube explaining the project. The generated JSON files are here: https://github.com/marlersoft/win32json/tree/main/api |
There is a full ECMA-335 specification https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf. |
https://github.com/tdakkota/win32metadata Wrote metadata parser in Go. There is a simple tool to generate some Go defintions from metadata:
|
Awesome work @tdakkota! After looking at the repo, I'm considering what would be the next steps to move this issue forward. I notice that |
ECMA-335 defines some flags for types ( There is also a
windows-rs adds zigwin32gen too I think if you want a pretty Go idiomatic API, you need a well-known types mapping. |
Interesting. That sounds like something worth bringing up upstream. I agree that in the meantime, having a mapping of well-known types is the right approach. Edit: I filed an issue upstream at microsoft/win32metadata#589. |
I've created a project go-win32api that provides win32 API bindings in go, which are generated based the the mentioned JSON files. Anyone interested could go and take a look. |
It would be great if the WinRT API was added as well but that may be out of scope for this issue. They release those over NuGet as well: https://www.nuget.org/packages/Microsoft.Windows.SDK.Contracts |
I'm (also!) interested in helping with this if possible, but I'm not totally sure what the current plan is after making the new repo. Sorry if it's simply too early in the process for these kinds of questions. 😄 Based on how On the dependency side, it seems to me that parsing the I work for Microsoft, and a couple of us have done some work on another implementation that we can publish on the |
Also, please see https://github.com/saltosystems/winrt-go which has seen some active development recently, and that we are currently using in the https://github.com/tinygo-org/bluetooth project. Great to see some movement on this! |
Thanks for mentioning us @deadprogram and kudos for the fantastic work done by @jagobagascon there! |
Now that we're past the Dec holidays, wanted to ping this. I imagine that because creating some kind of Is someone driving this proposal? This GitHub issue has been around for about a year now, so I wonder if priorities and perspectives may have shifted and a fresh, perhaps more detailed proposal is needed. |
Beware that the data portions of the github.com/microsoft/win32metadata repository are.. not open source, and the derivative versions built from those sources are.. questionably licensed: https://github.com/microsoft/win32metadata/blob/main/licenses/sdk_license.txt |
There is no derivative issue here (Microsoft owns all the goop in there). The license on the bits you care about (the .winmd) is MIT. I'll poke some folks again to get that clarified in the README. |
fyi, there is also https://github.com/microsoft/go-winmd now |
Yeah, just to clarify, https://github.com/microsoft/go-winmd is the repo for the project I mentioned here:
There are a number of open issues on the repo, https://github.com/microsoft/go-winmd/issues, and we haven't been able to work on this recently to get it to a point where we think it's stable and produces truly usable syscall signatures. After a little more work, what we're planning to do as our next step is create a new proposal to create a |
Microsoft released this win32 metadata project: https://github.com/microsoft/win32metadata
It or its output is basically this 9.5MB machine-readable file describing all the Win32 APIs: https://github.com/microsoft/windows-rs/blob/master/crates/winmd/default/Windows.Win32.winmd
Maybe x/sys/windows could use it to auto-generate bindings more easily/accurately.
Might be fun. Might be tedious. Might be worth it.
/cc @alexbrainman @ianlancetaylor @zx2c4
The text was updated successfully, but these errors were encountered: