slint
slint copied to clipboard
slint_build::compile compile multiple slint files
slint version: 1.1.1 rust version: 1.71.0 OS version: Macos 12.6
When I compile using slint_build::compile
, the compilation is successful. However, when running main.rs, it gives an error stating that "use of undeclared type AppWindow
". I also observed that when compiling multiple slint files, only the component compiled last can be used. I’m uncertain whether this is a bug.
appwindow.slint:
import { Button, VerticalBox } from "std-widgets.slint";
export component AppWindow inherits Window {
in-out property<int> counter: 42;
callback request-increase-value();
VerticalBox {
Text {
text: "Counter: \{root.counter}";
}
Button {
text: "Increase value";
clicked => {
root.request-increase-value();
}
}
}
}
import { Button, VerticalBox } from "std-widgets.slint";
export component AppWindow2 inherits Window {
in-out property<int> counter: 42;
callback request-increase-value();
VerticalBox {
Text {
text: "hello world";
}
}
}
build.rs:
fn main() {
// slint_build::compile("ui/appwindow.slint").unwrap();
// slint_build::compile("ui/appwindow2.slint").unwrap();
println!("cargo:warning================================== compile build.rs =================================\n");
if let Ok(_) = slint_build::compile("ui/appwindow.slint") {
println!("cargo:warning=compile ui/appwindow.slint success\n");
}
if let Ok(_) = slint_build::compile("ui/appwindow2.slint") {
println!("cargo:warning=compile ui/appwindow2.slint success\n");
}
}
main.rs:
slint::include_modules!();
fn main() -> Result<(), slint::PlatformError> {
// let ui = MarcoWindow::new()?;
// ui.run()
// MarcoWindow2::new().unwrap().run().unwrap();
AppWindow::new().unwrap().run().unwrap();
// AppWindow2::new().unwrap().run().unwrap();
// MarcoWindow2::new().unwrap().show().unwrap();
// AppWindow::new().unwrap().show().unwrap();
Ok(())
}
Thanks for reporting this issue.
I'd say it's a bug that the combination of slint_build::compile()
and slint::include_modules!
only applies to the last invocation. Either this is perhaps fixable by including multiple generated files, or the second invocation should produces an error, informing the user that compile
can only be called once.
Serveral months past, is this bug fixed? Or is there any solution to comiple and include mutiple slint files? I also encountered this problem.
One way to fix this could be for the slint_build to have a global static object that remembers that it already wrote a file, and if that's the case, it can generate another file that contains something like
include!("appwindow.slint")
include!("appwidow2.slint")
slint version: 1.1.1 rust version: 1.71.0 OS version: Macos 12.6
When I compile using
slint_build::compile
, the compilation is successful. However, when running main.rs, it gives an error stating that "use of undeclared typeAppWindow
". I also observed that when compiling multiple slint files, only the component compiled last can be used. I’m uncertain whether this is a bug.appwindow.slint:
import { Button, VerticalBox } from "std-widgets.slint"; export component AppWindow inherits Window { in-out property<int> counter: 42; callback request-increase-value(); VerticalBox { Text { text: "Counter: \{root.counter}"; } Button { text: "Increase value"; clicked => { root.request-increase-value(); } } } }
import { Button, VerticalBox } from "std-widgets.slint"; export component AppWindow2 inherits Window { in-out property<int> counter: 42; callback request-increase-value(); VerticalBox { Text { text: "hello world"; } } }
build.rs:
fn main() { // slint_build::compile("ui/appwindow.slint").unwrap(); // slint_build::compile("ui/appwindow2.slint").unwrap(); println!("cargo:warning================================== compile build.rs =================================\n"); if let Ok(_) = slint_build::compile("ui/appwindow.slint") { println!("cargo:warning=compile ui/appwindow.slint success\n"); } if let Ok(_) = slint_build::compile("ui/appwindow2.slint") { println!("cargo:warning=compile ui/appwindow2.slint success\n"); } }
main.rs:
slint::include_modules!(); fn main() -> Result<(), slint::PlatformError> { // let ui = MarcoWindow::new()?; // ui.run() // MarcoWindow2::new().unwrap().run().unwrap(); AppWindow::new().unwrap().run().unwrap(); // AppWindow2::new().unwrap().run().unwrap(); // MarcoWindow2::new().unwrap().show().unwrap(); // AppWindow::new().unwrap().show().unwrap(); Ok(()) }
The following methods can be used:
build.rs
println!("cargo:warning================================== compile build.rs =================================\n");
if slint_build::compile("ui/appwindow.slint").is_ok() {
println!(
"cargo:rustc-env=SLINT_INCLUDE_APP={}/appwindow.rs",
std::env::var("OUT_DIR").unwrap()
);
println!("cargo:warning=compile ui/appwindow.slint success\n");
}
if slint_build::compile("ui/subwindow.slint").is_ok() {
println!(
"cargo:rustc-env=SLINT_INCLUDE_SUB={}/subwindow.rs",
std::env::var("OUT_DIR").unwrap()
);
println!("cargo:warning=compile ui/appwindow2.slint success\n");
}
main.rs
mod win1 {
include!(env!("SLINT_INCLUDE_APP"));
}
mod win2 {
include!(env!("SLINT_INCLUDE_SUB"));
}