Skip to content

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(); }
}
}
}
slint

To learn what you can write in a .slint file, see the Language Specification.

Pass --slint-sc and the output file:

Terminal window
slint-compiler --slint-sc ui/indicator.slint -o indicator.rs
bash

For the other options, see Slint Compiler.

Run the compiler from your crate’s build.rs, so that Cargo regenerates the code whenever a file in ui/ changes:

// build.rs
use 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");
}
rust

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.

Include the generated file in the module of your crate that uses the component:

include!(concat!(env!("OUT_DIR"), "/indicator.rs"));
rust

The include! declares the Indicator struct and the IndicatorCallbacks trait in the current module.


© 2026 SixtyFPS GmbH

Built from commit 07986dea0ccb8bb10721c83ecba08d9a3e2cc234