in uniffi_bindgen/src/bindings/swift/mod.rs [84:137]
fn write_bindings(
&self,
settings: &GenerationSettings,
components: &[Component<Self::Config>],
) -> Result<()> {
for Component { ci, config, .. } in components {
let Bindings {
header,
library,
modulemap,
} = generate_bindings(config, ci)?;
let source_file = settings
.out_dir
.join(format!("{}.swift", config.module_name()));
fs::write(&source_file, library)?;
let header_file = settings.out_dir.join(config.header_filename());
fs::write(header_file, header)?;
if let Some(modulemap) = modulemap {
let modulemap_file = settings.out_dir.join(config.modulemap_filename());
fs::write(modulemap_file, modulemap)?;
}
if settings.try_format_code {
let commands_to_try = [
// Available in Xcode 16.
vec!["xcrun", "swift-format"],
// The official swift-format command name.
vec!["swift-format"],
// Shortcut for the swift-format command.
vec!["swift", "format"],
vec!["swiftformat"],
];
let successful_output = commands_to_try.into_iter().find_map(|command| {
Command::new(command[0])
.args(&command[1..])
.arg(source_file.as_str())
.output()
.ok()
});
if successful_output.is_none() {
println!(
"Warning: Unable to auto-format {} using swift-format. Please make sure it is installed.",
source_file.as_str()
);
}
}
}
Ok(())
}