Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: WinUI 3 rust support #2488

Open
IngmarBitter opened this issue May 19, 2020 · 41 comments
Open

Proposal: WinUI 3 rust support #2488

IngmarBitter opened this issue May 19, 2020 · 41 comments
Labels
feature proposal New feature proposal

Comments

@IngmarBitter
Copy link

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.

@IngmarBitter IngmarBitter added the feature proposal New feature proposal label May 19, 2020
@msft-github-bot msft-github-bot added the needs-triage Issue needs to be triaged by the area owners label May 19, 2020
@weltkante
Copy link

weltkante commented May 19, 2020

Language mappings seem to be already worked on: https://github.com/microsoft/winrt-rs

@IngmarBitter
Copy link
Author

IngmarBitter commented May 20, 2020

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.

@StephenLPeters StephenLPeters removed the needs-triage Issue needs to be triaged by the area owners label May 20, 2020
@kylone
Copy link

kylone commented Jul 21, 2020

This is (likely) blocked by winrt-rs being stable.

@ranjeshj
Copy link
Contributor

@kennykerr as FYI

@kennykerr
Copy link

kennykerr commented Jul 22, 2020

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.

@nerocui
Copy link
Member

nerocui commented Jul 22, 2020

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.

@IngmarBitter
Copy link
Author

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

@matthewfcarlson
Copy link

I've been looking forward to doing more GUI work in Rust. WinUI sounds like just the place to try it out

@kylone
Copy link

kylone commented Jul 26, 2020

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

@nerocui
Copy link
Member

nerocui commented Jul 28, 2020

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.

@ghost
Copy link

ghost commented Jul 30, 2020

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?

@kennykerr
Copy link

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.

@lukechu10
Copy link

lukechu10 commented Sep 22, 2020

Any update on this?
Edit: It would be great if there was a roadmap for supporting rust with winui

@kennykerr
Copy link

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.

@gitspeaks
Copy link

gitspeaks commented Jan 23, 2021

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

@ethindp
Copy link

ethindp commented Apr 13, 2021

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

@ghost
Copy link

ghost commented Apr 14, 2021

I expect furious work is needed first before Rust/WinRT versions of HelloXaml and Blocks ... samples can be posted alongside Ocr sample.

@kennykerr
Copy link

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:

minesweeper-opt2

More info here: https://github.com/microsoft/windows-rs

@gitspeaks
Copy link

gitspeaks commented Apr 14, 2021

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

@ghost
Copy link

ghost commented Apr 14, 2021

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.

@kennykerr
Copy link

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

@ethindp
Copy link

ethindp commented Apr 18, 2021

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?

@ghost
Copy link

ghost commented Apr 19, 2021

@kennykerr
Copy link

I just implemented weak references in Rust (#718 and #745), a prerequisite for Xaml/WinUI support. More to come! 😉

@kennykerr
Copy link

Things are starting to work. 😉 microsoft/windows-rs#81 (comment)

@gitspeaks
Copy link

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!

@kennykerr
Copy link

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.

@1Dragoon
Copy link

1Dragoon commented Jun 16, 2021

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

@kennykerr
Copy link

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.

@sylveon
Copy link
Contributor

sylveon commented Jun 21, 2021

@1Dragoon Uno platform is C# only (it doesn't have WinRT APIs, it mimics the WinRT API surface in C#), so no.

@1Dragoon
Copy link

Has anybody at MS ever explored the idea of a Rust macro that could deserialize XAML directly into structs?

@Rustacian
Copy link

Well, seems like the idea of Rust support for WinUI3 died before it got even usable.

At least C# has great Rust interoperability...

@sotanakamura
Copy link

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.

@IngmarBitter
Copy link
Author

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.

@sotanakamura
Copy link

I have no experience of Rust, so I can't help you. Someone here can help you.

@sotanakamura
Copy link

sotanakamura commented May 20, 2023

Have fun!
image

@sotanakamura
Copy link

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

@andre4ik3
Copy link

andre4ik3 commented May 24, 2023

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?

@ZanderBrown
Copy link

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

@doonv
Copy link

doonv commented Sep 25, 2023

Any update on this?

@sylveon
Copy link
Contributor

sylveon commented Sep 25, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature proposal New feature proposal
Projects
None yet
Development

No branches or pull requests