redbadger / crux

Cross-platform app development in Rust
https://redbadger.github.io/crux/
Apache License 2.0
1.77k stars 66 forks source link

Thoughts on Windows 11 C# Windows App SDK WinUI 3 XAML #164

Open kaidelorenzo opened 11 months ago

kaidelorenzo commented 11 months ago

I'm wondering about 2 things

  1. Are there plans to build out C#/WinUI 3 support?
  2. Is that something that folks would get behind integrating into Crux?
charypar commented 10 months ago

Hi @kaidelorenzo! Thanks for the questions.

  1. Not at present. We don't have a use for it, and it would likely depend on #145
  2. We would definitely welcome your thoughts on what if anything should be supported (beyond C# typegen) and contributions towards it.

There are a few things that depend on the custom type gen in #145, so it's relatively likely we'll start investigating options there pretty soon.

kaidelorenzo commented 10 months ago

I haven't given much thought to what limitations would be acceptable. I've read online that the interop between c# and rust isn't great right now so that might make things more challenge.

My goal would probably be minimal typegen support so that it is possible to run the framework even if the data types sent are simple (maybe restrict to integer or string structs only).

I don't have much time right now to work on this but glad that you'd be open to contributions. To me Windows seems like the last native platform that doesn't already work with crux.

charypar commented 10 months ago

One problem for which I can't see an immediate solution is representing Rust enum's, which are quite central to how Crux communicates with the shells (for events and effects). We'd need to do something like this probably https://bugsquash.blogspot.com/2012/01/encoding-algebraic-data-types-in-c.html. I'm not very familiar with the windows ecosystem, but maybe it would make more sense to target F# and rely on its interop with C# if that's more mature?

@StuartHarris Do you know much about the state of interop in C# land?

StuartHarris commented 9 months ago

I don't. But I'm putting this link here mainly so I can find it again to do a bit more reading on it. https://github.com/FractalFir/rustc_codegen_clr

huwaireb commented 4 months ago

👋

with windows-rs and WinRT components you can integrate Rust into a C#/WinUI 3 or any WinRT based application. I've done it the other day, works fine, just have to write an interface using MIDL 3 and then windows-rs has a bindgen that generates bindings, of which you implement for, samples (c++ no official c# as of yet).

it's pretty simple outside of having to conform to the quirks of WinRT on implementation, works well.

depends on CsWinRT (to generate the c# bindings) and Visual Studio (for midlrt.exe to generate .winmd which is then used to generate both Rust implementation and C# projection bindings).

i can share an example with C# & WinUI if anyone's interested.

I should probably mention I only got started like 3-4 days developing on Windows, so not much of an expert 🤣, in fact spent 7+ hours trying to get it to work 🤣, but eventually did.

kaidelorenzo commented 4 months ago

Yeah an example would be great. No rush if you'd rather tidy up some code first or something

huwaireb commented 4 months ago

Yeah an example would be great. No rush if you'd rather tidy up some code first or something

https://github.com/redbadger/crux/assets/69181766/5bc06f36-591d-4f14-bc8d-7c540f883874

thought might as well get crux also working 😭 spent entire day, but !! works. i'm too tired to clean up now given its 3 am 😭, will push it up tomorrow.

should clarify nothing was generally complicated, it's just my inexperience with C# as a language, and Windows as a platform. As well as getting familiar with how Crux does typegen. And how to implement state in WinUI 3.

given as i mentioned above i only started 3-4 days ago.