contextfree / winrt-rust

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

Port code generator from C# to Rust #50

Open Boddlnagg opened 6 years ago

Boddlnagg commented 6 years ago

This would allow us to run code generation as part of build.rs (also see #21), and get rid of the C#/.NET dependency.

Blocked on having a suitable replacement for Mono.Cecil written in Rust, for reading the IL metadata.

Update: The easiest approach is probably to port https://github.com/Microsoft/xlang/tree/master/src/library/impl/meta_reader (modern C++, MIT licensed) to Rust (as an external crate).

CarePackage17 commented 6 years ago

Have you seen this project? https://github.com/paavohuhtala/clri

Maybe some parts could be reused (and even if not, there are some links to useful info).

Boddlnagg commented 5 years ago

Maybe we can make use of the metadata reader implemented as part of https://github.com/Microsoft/xlang (https://github.com/Microsoft/xlang/tree/master/src/library/impl/meta_reader), which is written in modern C++ and could probably be ported to Rust easier than something like Mono.Cecil.

CarePackage17 commented 5 years ago

Thanks for the link, that project seems really interesting. It's essentially an open source implementation of the Windows Runtime.

Also, it seems to contain the cppwinrt compiler/code generator itself as described in the wiki. So, if we were able to port those bits to Rust we'd have auto-generated language projections for any WinRT/xlang component in the future.

Boddlnagg commented 5 years ago

Yes, the project was announced only yesterday on the author's blog (same author as cppwinrt): https://kennykerr.ca/2018/10/10/xlang/

CarePackage17 commented 5 years ago

Wait, really? That's pretty fucking awesome!

I'm excited.

Boddlnagg commented 5 years ago

We probably can also hide much of the generated code behind procedural macros now that they are stable (though that arguably means that someone who wants to understand what actually happens in the generated code needs to drill through yet another layer of magic – but I guess that procedural macros can't get worse than the declarative macros we have now).

Boddlnagg commented 5 years ago

I'm working on a Rust port of xlang's meta_reader (https://github.com/Microsoft/xlang/tree/master/src/library/impl/meta_reader), but have nothing to show yet.

Boddlnagg commented 5 years ago

A first (incomplete) version of a CLI metadata reader in Rust is now available: https://github.com/Boddlnagg/climeta

Mart-Bogdan commented 4 years ago

I'd suggest to nog go down the road of proc macros. Having generated code commited into vcs spreads up compilation, and it allows IDE code completion. IDEs aren't good with proc macros.

Boddlnagg commented 4 years ago

@Mart-Bogdan That is tracked in issue #68. I agree that there are tradeoffs and it's definitely not yet clear whether a proc macro would be a good idea, but I think we should experiment with it.

This issue, however, is about implementing the code generator in Rust, which is a necessary precondition for #68, but has value on its own.