From 69d5b26f834d8094efc3adaa1f5041d8820c61c8 Mon Sep 17 00:00:00 2001 From: Antonius Naumann Date: Sat, 25 Nov 2023 00:20:05 +0100 Subject: [PATCH] Add flag to suppress xcode warnings in generated code --- Cargo.toml | 8 ++++---- src/commands/package.rs | 10 +++++++--- src/main.rs | 6 ++++++ src/swiftpackage.rs | 4 ++-- src/templating.rs | 2 +- templates/Package.swift | 2 +- 6 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e51a0d9..3134bda 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ cargo_metadata = "0.18.1" clap = { version = "4.4.8", features = ["derive"] } convert_case = "0.6.0" nonempty = "0.9.0" -serde = { version = "1.0.192", features = ["derive"] } +serde = { version = "1.0.193", features = ["derive"] } # Templating askama = "0.12.1" @@ -30,13 +30,13 @@ askama = "0.12.1" # Terminal UI console = "0.15.7" dialoguer = { version = "0.11.0", default-features = false } -execute = "0.2.12" +execute = "0.2.13" indicatif = "0.17.7" # FFI Bindings -uniffi_bindgen = { version = "0.25.1" } +uniffi_bindgen = { version = "0.25.2" } # Allow testing with the latest dev version of UniFFI -# uniffi_bindgen = { version = "0.24.3", git = "https://github.com/mozilla/uniffi-rs.git" } +# uniffi_bindgen = { version = "0.25.2", git = "https://github.com/mozilla/uniffi-rs.git" } # Error Handling anyhow = "1.0.75" diff --git a/src/commands/package.rs b/src/commands/package.rs index 1cd12fc..b44ac4c 100644 --- a/src/commands/package.rs +++ b/src/commands/package.rs @@ -51,6 +51,7 @@ impl From for Option { pub fn run( platforms: Option>, package_name: Option, + disable_warnings: bool, config: Config, mode: Mode, lib_type_arg: LibTypeArg, @@ -66,6 +67,7 @@ pub fn run( crates[0], platforms.clone(), package_name, + disable_warnings, &config, mode, lib_type_arg, @@ -82,6 +84,7 @@ pub fn run( current_crate, platforms.clone(), None, + disable_warnings, &config, mode, lib_type_arg.clone(), @@ -96,6 +99,7 @@ fn run_for_crate( current_crate: &Package, platforms: Option>, package_name: Option, + disable_warnings: bool, config: &Config, mode: Mode, lib_type_arg: LibTypeArg, @@ -145,7 +149,7 @@ fn run_for_crate( recreate_output_dir(&package_name).expect("Could not create package output directory!"); create_xcframework_with_output(&targets, &lib.name, &package_name, mode, lib_type, config)?; - create_package_with_output(&package_name, &lib.name, config)?; + create_package_with_output(&package_name, &lib.name, disable_warnings, config)?; Ok(()) } @@ -394,11 +398,11 @@ fn create_xcframework_with_output( .map_err(|e| format!("Failed to create XCFramework due to the following error: \n {e}").into()) } -fn create_package_with_output(package_name: &str, namespace: &str, config: &Config) -> Result<()> { +fn create_package_with_output(package_name: &str, namespace: &str, disable_warnings: bool, config: &Config) -> Result<()> { run_step( config, format!("Creating Swift Package '{package_name}'..."), - || create_swiftpackage(package_name, namespace), + || create_swiftpackage(package_name, namespace, disable_warnings), )?; let spinner = config.silent.not().then(|| { diff --git a/src/main.rs b/src/main.rs index 66f7388..05b2730 100644 --- a/src/main.rs +++ b/src/main.rs @@ -80,6 +80,10 @@ enum Action { #[arg(long, ignore_case = true, default_value_t = package::LibTypeArg::Automatic)] /// Chose the how the library should be build. By default, this will be derived from the lib type provided in Cargo.toml lib_type: package::LibTypeArg, + + #[arg(long)] + /// Disable warnings in generated Swift package code + suppress_warnings: bool, }, } @@ -99,11 +103,13 @@ fn main() -> ExitCode { Action::Package { platforms, package_name, + suppress_warnings, release, lib_type, } => package::run( platforms, package_name, + suppress_warnings, config, if release { Mode::Release } else { Mode::Debug }, lib_type, diff --git a/src/swiftpackage.rs b/src/swiftpackage.rs index 0d1c5ad..9230f57 100644 --- a/src/swiftpackage.rs +++ b/src/swiftpackage.rs @@ -6,12 +6,12 @@ use crate::{recreate_dir, templating, Result}; /// Create artifacts for a swift package given the package name /// /// **Note**: This method assumes that a directory with the package name and the .xcframework already exists -pub fn create_swiftpackage(package_name: &str, namespace: &str) -> Result<()> { +pub fn create_swiftpackage(package_name: &str, namespace: &str, disable_warnings: bool) -> Result<()> { // TODO: Instead of assuming the directory and the xcframework, let this manage directory // recreation and let it copy the xcframework let package_manifest = templating::PackageSwift { package_name, - enable_warnings: false, + disable_warnings, }; write( diff --git a/src/templating.rs b/src/templating.rs index ff148a4..77b58a8 100644 --- a/src/templating.rs +++ b/src/templating.rs @@ -32,5 +32,5 @@ pub(crate) struct LibUdl<'a> { #[template(path = "Package.swift", escape = "none")] pub(crate) struct PackageSwift<'a> { pub(crate) package_name: &'a str, - pub(crate) enable_warnings: bool, + pub(crate) disable_warnings: bool, } diff --git a/templates/Package.swift b/templates/Package.swift index 638e940..f620f61 100644 --- a/templates/Package.swift +++ b/templates/Package.swift @@ -23,7 +23,7 @@ let package = Package( name: "{{ package_name }}", dependencies: [ .target(name: "RustFramework") - ]{% if !enable_warnings %}, + ]{% if disable_warnings %}, swiftSettings: [ .unsafeFlags(["-suppress-warnings"]), ]