Rust for the Windows App SDK

Overview

crates.io docs.rs Build and Test

Rust for the Windows App SDK

The windows-app crate makes the Windows App SDK (formerly known as Project Reunion) available to Rust developers. It is powered by the windows crate.

It's early days, but the windows-app crate is meant to make it much easier to use the Windows App SDK from Rust. As this new set of APIs requires bootstrapping and various other hooks to get it up and running, using only the windows crate—while possible—is a little more cumbersome for these new APIs.

So while the windows crate is still essential as it provides all of the language support, the windows-app crate will provide the necessary bootstrapping unique to the Windows App SDK.

As WinUI is a large part of the Windows App SDK, the goal is to support the latest WinUI app development through the windows-app crate.

Comments
  • Wondering why some controls work in xamlapp sample and some do not

    Wondering why some controls work in xamlapp sample and some do not

    (More of a question than an issue. If this repo had Discussions, this would belong there.)

    So the xamlapp sample in this repo works nicely.

    But if I replace the Button with, for example, a TextBox, it crashes.

    Do we (by which I mean "you all") know why?

    RatingControl and ColorPicker crash too.

    CalendarDatePicker and DatePicker and Slider do not.

    I know I'm probably in unsupported/uncharted territory here, but I'm just curious what's going on. Because, in the Swift projection I've been working on, I get exactly the same results: ericsink/SwiftWinRT#3

    In fact, running each of these cases under a debugger, the Rust and Swift versions show the same debug messages before failing.

    Any insights would be appreciated.

    question 
    opened by ericsink 12
  • the second sample in your readme produces an error

    the second sample in your readme produces an error

    Problem

    Running this sample:

    fn main() -> ::windows::core::Result<()> {
        println!("starting app");
        bootstrap::initialize()
            .and_then(|_| {
                println!(
                    "Remaining charge: {}%",
                    PowerManager::RemainingChargePercent()?
                );
                Ok(())
            })
            .and_then(|_| bootstrap::uninitialize())
    }
    

    produces this error:

    Error: Error { code: 0x80070491, message: There was no match for the specified key in the index. , win32_error: 1169 }

    Steps to reproduce

    Follow the readme.

    Screenshots

    Notes

    • Output from cargo version:
      cargo 1.57.0 (b2e52d7ca 2021-10-21)

    • Output from rustup show: Default host: x86_64-pc-windows-msvc rustup home: C:\Users\lovet.rustup stable-x86_64-pc-windows-msvc (default) rustc 1.57.0 (f1edd0429 2021-11-29)

    • Output from rustup --version:
      rustup 1.24.3 (ce5817a94 2021-05-31)

    • Output from cmd /c ver: Microsoft Windows [Version 10.0.22000.376]

    opened by clovett 9
  • Xaml::Controls::MenuBar crashes

    Xaml::Controls::MenuBar crashes

    I'm trying to add a menu bar to the simple window example.

    It crashes with exit code 0xc000027b.

    To get access to Append() on Children, I added Microsoft::UI::Xaml::Controls::UIElementCollection to windows::build!.

    let menu_bar = MenuBar::new()?;
    let stack_panel = StackPanel::new()?;
    stack_panel.Children()?.Append(&menu_bar)?;
    stack_panel.Children()?.Append(&button)?;
    window.SetContent(&stack_panel)?;
    
    question 
    opened by allan2 9
  • Cross compilation from Linux?

    Cross compilation from Linux?

    I know this project is currently experimental, and this isn't a priority, but I figured I'd document in case someone else runs into this.

    I'm trying to compile the example in the README from WSL using Linux cross compilation, which includes installing MinGW:

    rustup target add x86_64-pc-windows-gnu
    rustup toolchain install stable-x86_64-pc-windows-gnu
    sudo apt-get install mingw-w64
    

    This seems to almost work (because windows-rs supports cross compilation, it seems) but fails when the linker tries to find the app runtime:

      = note: /usr/bin/x86_64-w64-mingw32-ld: cannot find -lmicrosoft.windowsappruntime.bootstrap
              collect2: error: ld returned 1 exit status
    error: could not compile `rust_windows` due to previous error
    

    I'm really not sure how this could be solved, but it would be nice to have the workflow in WSL more clear. Thanks!

    enhancement 
    opened by rachtsingh 5
  • Move to cargo-generate template

    Move to cargo-generate template

    Switches out the crate for a new cargo-generate template with the same goals in mind. Also now generates metadata for Microsoft.WindowsAppSDK.Foundation and Microsoft.WindowsAppSDK.WinUI interop types, eliminating the need to manually write and maintain that code.

    opened by riverar 5
  • STATUS_ACCESS_VIOLATION

    STATUS_ACCESS_VIOLATION

    Problem

    The reproducer here performs an access violation, which I don't think ought to be possible in safe rust.

    I suspect this is really a bug in windows-rs, related to uninitialization of the field App.Window, but since it involves this crate I'm tentatively putting it here, feel free to move.

    Steps to reproduce

    1. cargo run
    >cargo run
       Compiling simple_window v0.0.0 (C:\Users\drew\CLionProjects\access-violation)
        Finished dev [unoptimized + debuginfo] target(s) in 2.41s
         Running `target\debug\simple_window.exe`
    error: process didn't exit successfully: `target\debug\simple_window.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
    

    Screenshots

    Notes

    • Output from cargo version: cargo 1.53.0 (4369396ce 2021-04-27)
    • Output from rustup show:
    Default host: x86_64-pc-windows-msvc
    rustup home:  C:\Users\drew\.rustup
    
    stable-x86_64-pc-windows-msvc (default)
    rustc 1.53.0 (53cb7b09b 2021-06-17)
    
    • Output from rustup --version:
    rustup 1.24.3 (ce5817a94 2021-05-31)
    info: This is the version for the rustup toolchain manager, not the rustc compiler.
    info: The currently active `rustc` version is `rustc 1.53.0 (53cb7b09b 2021-06-17)`
    
    • Output from cmd /c ver:
    Microsoft Windows [Version 10.0.19043.1055]
    
    question 
    opened by drewcrawford 5
  • Where do the winmd files come from? (besides the generated one)

    Where do the winmd files come from? (besides the generated one)

    Hi! I have some questions regarding how the fns are generated, specifically for the XAML part of it.

    I've been playing with the metadata generator project and now I'm able to generate the Microsoft.WindowsAppSdk.Generated.winmd file. However, I wonder where do the rest of the winmd files in the .windows/winmd folder come from 🤔. Are those also generated?

    I got into generating my own bindings due to the reduced API surface of the windows-rs crate (https://github.com/microsoft/windows-rs/issues/1715) so I just set the min_xaml option to false. That helped and now I can call some more methods like SetContent but I can't seem to find others like Windows::new.

    So, in fewer words:

    • Are the APIs published in this package under UI::Xaml substantially different from those in windows-rs (even with min_xaml disabled)?
    • How/Where can I get the mentioned winmd files?
    • Can we have some docs in how to use WinUI 3 from Rust with just windows-rs?
      • I know now we have this amazing crate (windows-app-rs) that simplifies the process, but I think documenting how it works will help people who are trying to experiment with it, use newer preview versions of the WindowsAppSDK or just tweaking it.
    question 
    opened by jesdazrez 4
  • Append to CommandBar.PrimaryCommands

    Append to CommandBar.PrimaryCommands

    Is there a way to add items to the PrimaryCommands collection?

    let cmd_bar = CommandBar::new()?;
    let add_btn = AppBarButton::new()?;
    let add_icon = SymbolIcon::new()?;
    add_icon.SetSymbol(Symbol::Add)?;
    add_btn.SetLabel("Add Task")?;
    add_btn.SetIcon(add_icon)?;
    cmd_bar.PrimaryCommands()?.Add(add_btn)?; // something like this
    

    [1] WinUI 3 docs on CommandBar [2] WinUI 3 docs on PrimaryCommands

    question 
    opened by allan2 4
  • Initial crate

    Initial crate

    The beginnings of the windows-app crate. Includes the wiring necessary to bootstrap dynamic dependencies for unpackaged Windows Apps and a native window handle helper.

    opened by riverar 4
  • Can't use `implement` macro for `Application`

    Can't use `implement` macro for `Application`

    Problem

    I am trying to use the implement macro to implement a subclass of Microsoft::UI::Xaml::Application. It produces a build error

    error[E0599]: no function or associated item named `new` found for struct `windows_app::Microsoft::UI::Xaml::IApplication_Vtbl` in the current scope
    error[E0599]: no function or associated item named `matches` found for struct `windows_app::Microsoft::UI::Xaml::IApplication_Vtbl` in the current scope
    
    opened by ZoeyR 3
  • windows_app_sdk `STATUS_STACK_BUFFER_OVERRUN`

    windows_app_sdk `STATUS_STACK_BUFFER_OVERRUN`

    Problem

    `target\debug\skeleton.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
    `target\debug\simple_window.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
    

    Steps to reproduce

    Build and launch on Win Server 2019 (with last updates)

    Screenshots

    изображение изображение изображение

    Notes

    • Output from cargo version: 1.55.0-nightly (cebef2951 2021-07-22)
    • Output from rustup show:
    Default host: x86_64-pc-windows-msvc
    rustup home:  D:\Rust\rustup
    
    installed toolchains
    --------------------
    
    stable-x86_64-pc-windows-msvc
    nightly-x86_64-pc-windows-msvc (default)
    
    active toolchain
    ----------------
    
    nightly-x86_64-pc-windows-msvc (default)
    rustc 1.56.0-nightly (d9aa28767 2021-07-24)
    
    • Output from rustup --version: rustup 1.24.3 (ce5817a94 2021-05-31)
    • Output from cmd /c ver: Microsoft Windows [Version 10.0.17763.2061]
    opened by Zymlex 3
Owner
Microsoft
Open source projects and samples from Microsoft
Microsoft
Rust SDK for writing contracts for Stellar Jump Cannon

rs-stellar-contract-sdk Rust SDK for writing contracts for Stellar Jump Cannon. This repository contains code that is in early development, incomplete

Stellar 44 Dec 28, 2022
Rust SDK for Stellar XDR.

rs-stellar-xdr Rust SDK for Stellar XDR. This repository contains code that is in early development, incomplete, not tested, and not recommended for u

Stellar 14 Dec 15, 2022
Click-once - A small tiny little binary to fix undesired mouse double clicks in Windows, written in Rust.

click-once A small tiny little binary to fix malfunctioning mouse double clicks in Windows, written in Rust. Minimal executable with little to no over

null 23 Dec 29, 2022
LSR - A Rust Implementation of LS for Windows

LSR - A Rust Implementation of LS for Windows(and possibly other platforms) This is underdevelopment Quick Start For now, I only tested this code on t

Christopher Schneider 4 Jan 31, 2023
Modify fonts to remove bitmap and disable gridfit for Windows font rendering.

Since Windows 10 version 1703 (Creators Update), its built-in TrueType renderer now supports vertical anti-aliasing. Despite there are only 30 levels of grayscale shade, it dramatically improves text rendering, especially for CJK languages. Sadly, it is only enabled for selected fonts at selected sizes.

Star Brilliant 54 Dec 21, 2022
Novus - A blazingly fast and efficient package manager for windows.

Novus - A blazingly fast and efficient package manager for windows. Why Novus Swift Unlike any other package manager, Novus uses multithreaded downloads

Novus 197 Dec 18, 2022
Adds size optimizations to any Perseus app automatically.

Perseus Size Optimization Plugin WARNING: Until Perseus #66 is fixed, this plugin can actually increase overall binary size! Once that issue is fixed

arctic_hen7 6 Aug 14, 2022
The working code for my Safe Pay app - check out my tutorial!

Safe Pay Tutorial This repository contains the source code for my blog post Using PDAs and SPL Token in Anchor. The code contains the following: Solan

Daniel Pyrathon 39 Aug 28, 2022
Provides a wrapper to deserialize clap app using serde.

clap-serde Provides a wrapper to deserialize clap app using serde. API Reference toml const CLAP_TOML: &'static str = r#" name = "app_clap_serde" vers

null 17 Jan 9, 2023
First Git on Rust is reimplementation with rust in order to learn about rust, c and git.

First Git on Rust First Git on Rust is reimplementation with rust in order to learn about rust, c and git. Reference project This project refer to the

Nobkz 1 Jan 28, 2022
A stupid macro that compiles and executes Rust and spits the output directly into your Rust code

inline-rust This is a stupid macro inspired by inline-python that compiles and executes Rust and spits the output directly into your Rust code. There

William 19 Nov 29, 2022
Learn-rust - An in-depth resource to learn Rust 🦀

Learning Rust ?? Hello friend! ?? Welcome to my "Learning Rust" repo, a home for my notes as I'm learning Rust. I'm structuring everything into lesson

Lazar Nikolov 7 Jan 28, 2022
A highly modular Bitcoin Lightning library written in Rust. Its Rust-Lightning, not Rusty's Lightning!

Rust-Lightning is a Bitcoin Lightning library written in Rust. The main crate, lightning, does not handle networking, persistence, or any other I/O. Thus, it is runtime-agnostic, but users must implement basic networking logic, chain interactions, and disk storage. More information is available in the About section.

Lightning Dev Kit 850 Jan 3, 2023
Telegram bot help you to run Rust code in Telegram via Rust playground

RPG_BOT (Rust Playground Bot) Telegram bot help you to run Rust code in Telegram via Rust playground Bot interface The bot supports 3 straightforward

TheAwiteb 8 Dec 6, 2022
`Debug` in rust, but only supports valid rust syntax and outputs nicely formatted using pretty-please

dbg-pls A Debug-like trait for rust that outputs properly formatted code Showcase Take the following code: let code = r#" [ "Hello, World!

Conrad Ludgate 12 Dec 22, 2022
Playing with web dev in Rust. This is a sample Rust microservice that can be deployed on Kubernetes.

Playing with web dev in Rust. This is a sample Rust microservice that can be deployed on Kubernetes.

André Gomes 10 Nov 17, 2022
🐀 Building a federated alternative to reddit in rust

Lemmy A link aggregator / Reddit clone for the fediverse. Join Lemmy · Documentation · Report Bug · Request Feature · Releases · Code of Conduct About

LemmyNet 7.2k Jan 3, 2023
Applied offensive security with Rust

Black Hat Rust - Early Access Deep dive into offensive security with the Rust programming language Buy the book now! Summary Whether in movies or main

Sylvain Kerkour 2.2k Jan 2, 2023
Rholang runtime in rust

Rholang Runtime A rholang runtime written in Rust.

Jerry.Wang 17 Sep 23, 2022