Hello Windows
Your first Rust app on Windows
PS> cargo new hello-win && cd hello-win
PS> cargo run
Compiling hello-win v0.1.0
Finished dev profile [unoptimized + debuginfo]
Hello, world!
Add Windows APIs
Use Win32 APIs with the windows crate
Add windows to your Cargo.toml:
[dependencies]
windows = { version = "0.57", features = [
"Win32_UI_WindowsAndMessaging",
"Win32_Foundation",
] }
Call a Win32 API from src/main.rs:
use windows::Win32::UI::WindowsAndMessaging::MessageBoxW;
use windows::Win32::Foundation::HWND;
use windows::core::w;
fn main() {
unsafe {
MessageBoxW(HWND(0), w!("Hello from Rust!"), w!("Test"), Default::default());
}
}
Build for release
Build a release binary
# Debug build (fast compile, large binary):
PS> cargo build
# Output: target\debug\hello-win.exe
# Release build (optimised, smaller binary):
PS> cargo build --release
# Output: target\release\hello-win.exe
FAQ
Quickstart questions
How long does Rust compilation take on Windows?
A fresh debug build of a "Hello, world!" app takes 5–15 seconds. Incremental builds (after changing one file) take under 1 second. Adding the windows crate increases the first compile to 30–90 seconds due to the large API surface. Release builds with LTO take 2–5x longer than debug builds.
How to open a window with Rust on Windows?
For a native Win32 window, use the windows crate and call CreateWindowExW. For a simpler cross-platform approach, use winit (event loop) with a renderer like egui or wgpu. See the GUI development guide.