contextfree / winrt-rust

Use and (eventually) make Windows Runtime APIs with Rust
Apache License 2.0
142 stars 10 forks source link

Autogenerate "low-level projection" from metadata #1

Closed contextfree closed 8 years ago

contextfree commented 8 years ago

Tentatively decided to write this in F# (there doesn't seem to be much benefit to bootstrapping a tool like this in Rust)

Boddlnagg commented 8 years ago

For reading the metadata, use either Mono.Cecil or System.Reflection.Metadata. The latter is newer, and slightly more low-level and lightweight, but probably sufficient if we don't need an in-memory-representation of everything and instead just go through the types and write them out as Rust code one-by-one. I agree that writing a metadata reader in Rust is not a priority, though it would be nice to have. I don't have much experience with F#, but this tool will probably be quite small anyway, so I don't really care. Furthermore, maybe a templating system might be helpful?

Boddlnagg commented 8 years ago

I started implementing the generator in C# using Mono.Cecil in my branch. The C# code is more like a proof-of-concept in terms of coding style, and I wouldn't object to a rewrite in F#. I'm just not really familiar with F#.

Running the codegen for the whole of C:\Windows\System32\WinMetadata results in a 40k+ line file which fails to compile due to some seemingly unrelated macro errors. Running on Windows.Foundation.winmd only works just fine, so further investigation is needed.

Boddlnagg commented 8 years ago

The problem was the keyword box appearing as a parameter name in one of the definitions. This is replaced by box_ now, and the whole of WinMetadata can now be generated, currently resulting in 43707 generated lines of Rust code (ca 5 MB) and a 194 MB (debug) libwinrt.rlib (after a few minutes of compilation).

Boddlnagg commented 8 years ago

Can this be closed now that we basically have a "mid-level" API (as high-level as possible, but still currently unsafe)?

contextfree commented 8 years ago

great! sorry I haven't really been contributing. i have been reading the code though & am amazed by what you've done, I didn't bother uploading any of the stuff I had because your implementations were so much better. I still hope to contribute in the future.