Open IngmarBitter opened 4 years ago
Language mappings seem to be already worked on: https://github.com/microsoft/winrt-rs
winrt-rs
is maybe able to achieve the connection, but an explicit winui3-rs
crate that pulls in the necessary dependencies and has a working hello world will make it much much more accessible.
This is (likely) blocked by winrt-rs
being stable.
@kennykerr as FYI
The Rust winrt crate provides the language projection and packaging support, comparable to C++/WinRT with its VS extension and NuGet support. All of that is provided by Rust/WinRT today. It's on my list to add some Xaml samples soon. We still have some way to go to support building your own Xaml controls in Rust, but you can already build basic Xaml apps and we are working furiously to get complete type system support in place.
I'd love to hear what else folks are looking for. I can imagine this is more about providing support for the kinds of things that the Xaml compiler traditionally takes care of, but I may be wrong.
I would really love to see this happen too. Rust is increasingly more popular for a reason. It's a really good language, and Microsoft has even said to be using rust for building some part of Windows. Having an app framework built around rust would mean c++ level performance but with much better readable code and less memory bugs.
@kennykerr "I'd love to hear what else folks are looking for." the main motivation was to be able to have professional-looking applications that are written as much natively in rust as possible. Somehow it seems that people that have great language design skills are not the same ones that have great artistic UI widget design skills. So a wrapper in rust for WIN UI 3 would bridge the divide. But the barrier to entry is high when there are libraries that should do the trick but have no example of actually doing so. Having a hello world example that ties the technologies together will get a lot more people to actually want to dive in and make their own derivations of it. I personally would love an example of rust using WIN UI 3 and DirectX12 in a panel within the WIN UI app. I did not start working on it since it seemed hard when also only just starting to learn rust.
I've been looking forward to doing more GUI work in Rust. WinUI sounds like just the place to try it out
@kennykerr "Having a hello world example that ties the technologies together will get a lot more people to actually want to dive in and make their own derivations of it."
Hello world is enough to show the ui. An example todo app shows some simple interactions, and how the pieces fit together.
I remember the announcement about .Net MAUI, and I'm wondering how much of the underpinnings of that are in WinUI?
To me, the inspiration comes from a Rust GUI framework called vgtk. https://bodil.lol/vgtk/
This framework's syntax is heavily inspired by React's jsx syntax for building declarative UI, and it's programming model is the nowadays popular MVU model.
To declare an app, you write
fn view(&self) -> VNode<Model> {
gtk! {
<Application::new_unwrap(None, ApplicationFlags::empty())>
<Window border_width=20 on destroy=|_| Message::Exit>
<HeaderBar title="inc!" show_close_button=true />
<Box spacing=10 halign=Align::Center>
<Label label=self.counter.to_string() />
<Button label="inc!" image="add" always_show_image=true
on clicked=|_| Message::Inc />
</Box>
</Window>
</Application>
}
}
This is very close to jsx, but even more close to XAML which is perfect to use for WinUI. This syntax in rust is enabled by rust's procedural macros feature.
It seems to me that this type of UI framework is the trend these days, and for rust with WinUI to succeed, it needs to ride this train as well. This type of work has been done countless times, and it's probably very easy for Microsoft to create one for WinUI. It might also be a good chance for a cross platform UI framework as that's what the rust GUI community eagerly await, but that seems to be out of scope of this issue.
Something also of note is that, XAML requires 'partial class' support, right? So you can add controls to the UI elements. Does Rust support this? Could you imitate it with procedural macros?
Thanks for all the feedback! Keep it coming.
@suleyth - the Xaml API doesn't require partial classes. That's a feature of the C# language that the Xaml compiler makes use of. For C++ and now Rust we're exploring a completely different approach that is more natural to those languages. And yes, procedural macros are a great way to solve this in Rust. We use them extensively in winrt-rs.
Any update on this? Edit: It would be great if there was a roadmap for supporting rust with winui
I can't speak for the WinUI team, but much of the support for Rust will come from the Rust/WinRT language projection (winrt-rs). In particular, I'm now working on adding support for defining and implementing COM and WinRT types in Rust. That's a major prerequisite for complete Xaml integration. Once that's ready, we can start looking at lighting up Xaml binding support more naturally in Rust.
@kennykerr
We still have some way to go to support building your own Xaml controls in Rust, but you can already build basic Xaml apps and we are working furiously to get complete type system support in place.
Can you please post example code for a basic xaml app ?
@kennykerr I'd love to see how creating a WinUI app is right now. It might be clunky, but I'd still love to see how far I can take it so long as the way to do it is at least somewhat documented. Example code would be wonderful to have.
I expect furious work is needed first before Rust/WinRT versions of HelloXaml and Blocks ... samples can be posted alongside Ocr sample.
Xaml still requires more work to enable, but the Windows crate for Rust (formerly Rust/WinRT) already supports building DirectX and Windows.UI.Composition apps.
Here's a Direct2D example:
And a Windows.UI.Composition example:
More info here: https://github.com/microsoft/windows-rs
@kennykerr
Xaml still requires more work to enable
Is this something currently being worked on ?
, but the Windows crate for Rust (formerly Rust/WinRT) already supports building DirectX and Windows.UI.Composition apps.
How far can one go with Composition apps in terms of accepting keyboard text input / list view display?
Translation in time of the cppwinrt samples like Ocr (done) and HelloXaml, Blocks etc. allows instructive one to one comparisons for those new to Rust.
cppwinrt samples like Ocr (done) and HelloXaml, Blocks etc. allows instructive one to one comparisons
Yes, having comparable samples is certainly helpful and I hope to fill in the gaps as support improves for more APIs. Note that you can already write the Blocks sample in Rust. I just haven't got around to that.
Is this something currently being worked on ?
It's on my list, but I have been focused on Win32 APIs for the last few months. I hope to look at this again soon.
How far can one go with Composition apps in terms of accepting keyboard text input / list view display?
You can go as far as you want, but it will be harder than simply adding a Xaml TextBox control. 😉
That'll work, but I use a screen reader and so Windows.UI.Composition isn't accessible. Is it possible to use the standard win32 controls but with WinRT and without the hastle of XAML?
The Win32/WinRT Desktop Bridge might help, https://techcommunity.microsoft.com/t5/windows-dev-appconsult/desktop-bridge-8211-the-bridge-between-desktop-apps-and-the/ba-p/316488
Things are starting to work. :wink: https://github.com/microsoft/windows-rs/issues/81#issuecomment-848110943
Things are starting to work. 😉 microsoft/windows-rs#81 (comment)
IMHO this marks the start of a new era for Windows desktop application development. @kennykerr Microsoft is fortunate to have you. Thank you!
There are now CoreApp and XamlApp examples in the Windows repo. This is based on in-box Xaml within a packaged app, but it should also work for WinUI and desktop apps (I just don't have any such examples yet). Lots more work for me to do, but this is a pretty big step forward for folks interested in experimenting with Rust and UI on Windows.
@kennykerr I read elsewhere that winui is supposed to also be cross platform via the uno platform. Could rust take advantage of that so I could say build an application for both windows and android?
Sorry, I have no idea what that would entail. There have been some other requests for cross-platform support in the Windows crate, but at this point I'm squarely focused on completing Windows support.
@1Dragoon Uno platform is C# only (it doesn't have WinRT APIs, it mimics the WinRT API surface in C#), so no.
Has anybody at MS ever explored the idea of a Rust macro that could deserialize XAML directly into structs?
Well, seems like the idea of Rust support for WinUI3 died before it got even usable.
At least C# has great Rust interoperability...
I have succeeded to create WinUI 3 app with Fluent design. Here is the sample code. https://github.com/sotanakamura/winui-rust. Please run it by debugging in VS code with CodeLLBD.
I have succeeded to create WinUI 3 app with Fluent design. Here is the sample code. https://github.com/sotanakamura/winui-rust. Please run it by debugging in VS code with CodeLLBD.
I cloned your repo and ran rustup update
. Then I hit the debug execute button is VS Code and it seemed to get and build everything needed, started to run but then crashed like this: https://i.imgur.com/S9d6rji.png
Kudos that it actually compiled and started to run out of the box. That's better than many other projects.
How do I figure out what's different in my setup that's preventing from executing successfully?
I'm on Win11 Pro and I got Bevy examples to run fine, so my rust installation in general seems to be operational.
I have no experience of Rust, so I can't help you. Someone here can help you.
Have fun!
@IngmarBitter If it stopped at bootstrap api, you may be lack of bootstarp dll. Please cargo build
to run the build script build.rs
. It copies the dll to your application folder.
Somewhat related: The Browser Company is making a library to use WinUI 3 in Swift with declarative-like syntax. It's not open-source yet, however they are planning to use it in production, so it shows Xaml can be "used" outside of C# with a great developer experience (IMO better than C# but I'm still a beginner). Porting the Windows SDK (including WinUI) to Swift took them around 8 months with only 2 people working on it (7:18), and the declarative syntax took them 3-4 days (14:45), so this sort of thing can definitely be done. Swift is similar to Rust in terms of not having GC, being based on LLVM, and producing native binaries instead of intermediate code like C#.
Update: here it is (very rough still, I suspect it will be more polished by the time their product actually releases for Windows, which I've heard they plan to by the end of the year)
Update 2: They have WinRT projections as well now. And WinUI sample code. If a tiny startup can go from zero to WinUI in Swift in a few months, surely a trillion dollar company can do it in Rust, already having WinRT projections?
Swift is similar to Rust in terms of not having GC, being based on LLVM, and producing native binaries instead of intermediate code like C#.
Half the world is similar to Rust on those grounds of course
But sounds like interesting work
Any update on this?
The WinUI team does not seem interested in Rust support. winrt-rs dropped support for WinUI 3 too due the team frequently doing undocumented changes breaking the crate. I don't expect any movement on this in the foreseeable future.
Rust is becoming increasingly popular. It already can drive DirectX 12 but only in full screen mode or via UI libraries that look like they are made by engineers for engineers. Having WinUI3 support for rust would allow to build rust apps that look modern and polished and under the hood enjoy all the advantages of rust. That would make engineers and marketing happy, i.e. make this combination viable for commercial apps.