From 3bafed5558cb06fea47ed702c3c49da45bc09e59 Mon Sep 17 00:00:00 2001 From: Nirjal Bhurtel Date: Thu, 31 Jul 2025 16:36:45 +0200 Subject: [PATCH] Add option to select rust format edition in varlink generator This allows changing the format edition via build.rs --- varlink_generator/src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/varlink_generator/src/lib.rs b/varlink_generator/src/lib.rs index 626c15c..06a93b6 100644 --- a/varlink_generator/src/lib.rs +++ b/varlink_generator/src/lib.rs @@ -80,6 +80,7 @@ pub struct GeneratorOptions { pub float_type: Option<&'static str>, pub string_type: Option<&'static str>, pub preamble: Option, + pub fmt_style_edition: Option<&'static str>, } impl<'short, 'long: 'short> ToRustString<'short, 'long> for VType<'long> { @@ -1059,6 +1060,7 @@ pub fn cargo_build_tosource + ?Sized>(input_path: &T, rustfmt: bo /// true, /// &varlink_generator::GeneratorOptions { /// int_type: Some("i128"), +/// fmt_style_edition: Some("2024"), /// ..Default::default() /// }, /// ); @@ -1110,10 +1112,13 @@ pub fn cargo_build_tosource_options + ?Sized>( } if rustfmt { - if let Err(e) = Command::new("rustfmt") - .arg(rust_path.to_str().unwrap()) - .output() - { + let mut cmd = Command::new("rustfmt"); + + if let Some(ref v) = options.fmt_style_edition { + cmd.args(["--style-edition", v]); + } + + if let Err(e) = cmd.arg(rust_path.to_str().unwrap()).output() { eprintln!( "Could not run rustfmt on file `{}` {}", rust_path.display(),