Skip to content

Commit

Permalink
Add flag to suppress xcode warnings in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniusnaumann committed Nov 24, 2023
1 parent fa001d2 commit 69d5b26
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ 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"

# 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"
Expand Down
10 changes: 7 additions & 3 deletions src/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl From<LibTypeArg> for Option<LibType> {
pub fn run(
platforms: Option<Vec<Platform>>,
package_name: Option<String>,
disable_warnings: bool,
config: Config,
mode: Mode,
lib_type_arg: LibTypeArg,
Expand All @@ -66,6 +67,7 @@ pub fn run(
crates[0],
platforms.clone(),
package_name,
disable_warnings,
&config,
mode,
lib_type_arg,
Expand All @@ -82,6 +84,7 @@ pub fn run(
current_crate,
platforms.clone(),
None,
disable_warnings,
&config,
mode,
lib_type_arg.clone(),
Expand All @@ -96,6 +99,7 @@ fn run_for_crate(
current_crate: &Package,
platforms: Option<Vec<Platform>>,
package_name: Option<String>,
disable_warnings: bool,
config: &Config,
mode: Mode,
lib_type_arg: LibTypeArg,
Expand Down Expand Up @@ -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(())
}
Expand Down Expand Up @@ -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(|| {
Expand Down
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/swiftpackage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/templating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion templates/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let package = Package(
name: "{{ package_name }}",
dependencies: [
.target(name: "RustFramework")
]{% if !enable_warnings %},
]{% if disable_warnings %},
swiftSettings: [
.unsafeFlags(["-suppress-warnings"]),
]
Expand Down

0 comments on commit 69d5b26

Please sign in to comment.