Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/cpp/cbindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ namespace slint::platform::key_codes {{
i_slint_common::for_each_special_keys!(print_key_codes);
writeln!(enums_pub, "}}")?;

enums_priv.flush()?;
enums_pub.flush()?;
Ok(())
}

Expand Down Expand Up @@ -184,6 +186,8 @@ fn builtin_structs(path: &Path) -> anyhow::Result<()> {
i_slint_common::for_each_builtin_structs!(print_structs);
writeln!(structs_priv, "}}")?;
writeln!(structs_pub, "}}")?;
structs_priv.flush()?;
structs_pub.flush()?;
Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions api/rs/build/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ pub fn compile_with_output_path(
}
}

code_formatter.sink.flush().map_err(CompileError::SaveError)?;

Ok(dependencies)
}

Expand Down
1 change: 1 addition & 0 deletions internal/compiler/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ fn widget_library() -> &'static [(&'static str, &'static BuiltinDirectory<'stati
}

writeln!(file, "]\n}}")?;
file.flush()?;

println!("cargo:rustc-env=SLINT_WIDGETS_LIBRARY={}", output_file_path.display());

Expand Down
4 changes: 3 additions & 1 deletion internal/compiler/generator/cpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,9 @@ pub fn generate(

for (cpp_file_name, cpp_file) in config.cpp_files.iter().zip(cpp_files) {
use std::io::Write;
write!(&mut BufWriter::new(std::fs::File::create(&cpp_file_name)?), "{cpp_file}")?;
let mut cpp_writer = BufWriter::new(std::fs::File::create(&cpp_file_name)?);
write!(&mut cpp_writer, "{cpp_file}")?;
cpp_writer.flush()?;
Copy link
Contributor

@ubruhin ubruhin Aug 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually BufWriter could even be removed here I guess, as the whole file is written at once(?) Same applies to two other locations. EDIT: Hmm well maybe I'm wrong, I don't know exactly what's the type of cpp_file and how it gets written to the stream.

And btw, in my fork I still have the patch from #9092 included, so what I've actually tested is the combination of those two changes. Generally I'd still vote to implement the atomic file writes as long as there's no serious drawback (I didn't check the details about it).

}

Ok(file)
Expand Down
4 changes: 3 additions & 1 deletion internal/compiler/generator/cpp_live_reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ pub fn generate(
let cpp_files = file.split_off_cpp_files(config.header_include, config.cpp_files.len());
for (cpp_file_name, cpp_file) in config.cpp_files.iter().zip(cpp_files) {
use std::io::Write;
write!(&mut BufWriter::new(std::fs::File::create(&cpp_file_name)?), "{cpp_file}")?;
let mut cpp_writer = BufWriter::new(std::fs::File::create(&cpp_file_name)?);
write!(&mut cpp_writer, "{cpp_file}")?;
cpp_writer.flush()?;
}

Ok(file)
Expand Down
2 changes: 2 additions & 0 deletions tests/doctests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-changed={}", path.display());
}

tests_file.flush()?;

println!("cargo:rustc-env=TEST_FUNCTIONS={}", tests_file_path.to_string_lossy());
println!("cargo:rustc-env=SLINT_ENABLE_EXPERIMENTAL_FEATURES=1");

Expand Down
2 changes: 2 additions & 0 deletions tests/driver/cpp/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
)?;
}

tests_file.flush()?;

println!("cargo:rustc-env=TEST_FUNCTIONS={}", tests_file_path.to_string_lossy());
println!("cargo:rustc-env=SLINT_ENABLE_EXPERIMENTAL_FEATURES=1");
Ok(())
Expand Down
4 changes: 4 additions & 0 deletions tests/driver/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ fn main() -> std::io::Result<()> {
x.source.replace('\n', "\n ")
)?;
}

output.flush()?;
}

generated_file.flush()?;

// By default resources are embedded. The WASM example builds provide test coverage for that. This switch
// provides test coverage for the non-embedding case, compiling tests without embedding the images.
if !live_reload {
Expand Down
4 changes: 4 additions & 0 deletions tests/screenshots/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,12 @@ fn main() -> std::io::Result<()> {
Ok(())
}}",
)?;

output.flush()?;
}

generated_file.flush()?;

//Make sure to use a consistent style
println!("cargo:rustc-env=SLINT_STYLE=fluent");
println!("cargo:rustc-env=SLINT_ENABLE_EXPERIMENTAL_FEATURES=1");
Expand Down
10 changes: 4 additions & 6 deletions tools/compiler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,9 @@ fn main() -> std::io::Result<()> {
if args.output == std::path::Path::new("-") {
generator::generate(format, &mut std::io::stdout(), &doc, &loader.compiler_config)?;
} else {
generator::generate(
format,
&mut BufWriter::new(std::fs::File::create(&args.output)?),
&doc,
&loader.compiler_config,
)?;
let mut file_writer = BufWriter::new(std::fs::File::create(&args.output)?);
generator::generate(format, &mut file_writer, &doc, &loader.compiler_config)?;
file_writer.flush()?;
}

if let Some(depfile) = args.depfile {
Expand All @@ -223,6 +220,7 @@ fn main() -> std::io::Result<()> {
}

writeln!(f)?;
f.flush()?;
}
diag.print_warnings_and_exit_on_error();
Ok(())
Expand Down
5 changes: 3 additions & 2 deletions tools/lsp/fmt/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub fn run(files: &[std::path::PathBuf], inplace: bool) -> std::io::Result<()> {

if inplace {
let file = BufWriter::new(std::fs::File::create(&path)?);
process_file(source, path, file)?
process_file(source, path, file)?;
} else {
process_file(source, path, std::io::stdout())?
}
Expand All @@ -53,7 +53,8 @@ fn process_rust_file(source: String, mut file: impl Write) -> std::io::Result<()
diag.print();
}
}
file.write_all(&source.as_bytes()[last..])
file.write_all(&source.as_bytes()[last..])?;
file.flush()
}

/// FIXME! this is duplicated with the updater
Expand Down
1 change: 1 addition & 0 deletions tools/updater/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ fn process_file(
file.write_all(&source.as_bytes()[len..])?;
diag.print();
}
file.flush()?;
Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions xtask/src/slintdocs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ description: {0} content
v.key, v.description
)?;
}

file.flush()?;
}
Ok(())
}
Expand Down Expand Up @@ -260,6 +262,8 @@ description: {0} content
f.key, f.type_name, f.description
)?;
}

file.flush()?;
}

Ok(())
Expand Down
Loading