Compiling .slint Files
The Slint SC compiler translates a .slint file into one Rust source file.
The Rust file defines the component and the types the .slint file declares, and embeds the images the .slint file uses.
The generated code depends only on the slint-sc crate.
The examples on this page compile ui/indicator.slint:
export component Indicator inherits Window { in property <bool> alarm: false; callback acknowledged;
background: #202020;
Rectangle { x: 16px; y: 16px; width: 32px; height: 32px; background: root.alarm ? #c02020 : #20a020;
TouchArea { clicked => { root.acknowledged(); } } }}To learn what you can write in a .slint file, see the Language Specification.
From the Command Line
Section titled “From the Command Line”Pass --slint-sc and the output file:
slint-compiler --slint-sc ui/indicator.slint -o indicator.rsFor the other options, see Slint Compiler.
From a Build Script
Section titled “From a Build Script”Run the compiler from your crate’s build.rs, so that Cargo regenerates the code whenever a file in ui/ changes:
// build.rsuse std::path::PathBuf;use std::process::Command;
fn main() { let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); let output = out_dir.join("indicator.rs"); let compiler = std::env::var_os("SLINT_COMPILER").unwrap_or("slint-compiler".into());
let status = Command::new(&compiler) .arg("--slint-sc") .arg("ui/indicator.slint") .arg("-o") .arg(&output) .status() .expect("failed to run slint-compiler"); assert!(status.success(), "slint-compiler failed on ui/indicator.slint");
println!("cargo:rerun-if-env-changed=SLINT_COMPILER"); println!("cargo:rerun-if-changed=ui");}The script runs slint-compiler from your PATH.
To use a specific binary instead, set SLINT_COMPILER to the path of that binary.
Keep the .slint files and the images they use in ui/, since Cargo only watches that directory.
Including the Generated Code
Section titled “Including the Generated Code”Include the generated file in the module of your crate that uses the component:
include!(concat!(env!("OUT_DIR"), "/indicator.rs"));The include! declares the Indicator struct and the IndicatorCallbacks trait in the current module.
© 2026 SixtyFPS GmbH
Built from commit 07986dea0ccb8bb10721c83ecba08d9a3e2cc234