winrt-rust icon indicating copy to clipboard operation
winrt-rust copied to clipboard

Port code generator from C# to Rust

Open Boddlnagg opened this issue 7 years ago • 10 comments

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).

Boddlnagg avatar Dec 27 '17 12:12 Boddlnagg

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).

CarePackage17 avatar May 08 '18 19:05 CarePackage17

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.

Boddlnagg avatar Oct 11 '18 06:10 Boddlnagg

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.

CarePackage17 avatar Oct 11 '18 15:10 CarePackage17

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

Boddlnagg avatar Oct 11 '18 19:10 Boddlnagg

Wait, really? That's pretty fucking awesome!

I'm excited.

CarePackage17 avatar Oct 11 '18 20:10 CarePackage17

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 avatar Feb 09 '19 17:02 Boddlnagg

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 avatar Apr 27 '19 14:04 Boddlnagg

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

Boddlnagg avatar May 07 '19 19:05 Boddlnagg

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.

Mart-Bogdan avatar Aug 04 '19 01:08 Mart-Bogdan

@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.

Boddlnagg avatar Aug 13 '19 18:08 Boddlnagg