Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prompt xcframework_name to avoid duplicate target names error in Xcode #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ To bundle the previously created Rust library as Swift Package, run:
```
cargo swift package
```
This command interactively prompts you for swift package name and target platforms.
This command interactively prompts you for swift package name, xcframework name, and target platforms.
If some required toolchains for the selected target platforms are missing, cargo swift will ask you if it should install them automatically.

That's it! You can now include the created package in an iOS or macOS app via Swift Package Manager.
Expand Down
30 changes: 25 additions & 5 deletions src/commands/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub fn run(
platforms: Option<Vec<Platform>>,
build_target: Option<&str>,
package_name: Option<String>,
xcframework_name: String,
xcframework_name: Option<String>,
disable_warnings: bool,
config: Config,
mode: Mode,
Expand Down Expand Up @@ -101,7 +101,7 @@ pub fn run(
platforms.clone(),
build_target,
None,
xcframework_name.clone(),
None,
disable_warnings,
&config,
mode,
Expand All @@ -121,7 +121,7 @@ fn run_for_crate(
platforms: Option<Vec<Platform>>,
build_target: Option<&str>,
package_name: Option<String>,
xcframework_name: String,
xcframework_name: Option<String>,
disable_warnings: bool,
config: &Config,
mode: Mode,
Expand Down Expand Up @@ -149,8 +149,12 @@ fn run_for_crate(
}

let crate_name = current_crate.name.to_lowercase();
let package_name =
package_name.unwrap_or_else(|| prompt_package_name(&crate_name, config.accept_all));
let package_name = package_name.unwrap_or_else(|| prompt_package_name(&crate_name, config.accept_all));
let xcframework_name = xcframework_name.unwrap_or_else(|| prompt_xcframework_name(&crate_name, config.accept_all));

if package_name == xcframework_name {
Err("Package name and XCFramework name must be different to avoid duplicate target names in XCode!")?;
}

let platforms = platforms.unwrap_or_else(|| prompt_platforms(config.accept_all));

Expand Down Expand Up @@ -482,6 +486,22 @@ fn prompt_package_name(crate_name: &str, accept_all: bool) -> String {
.unwrap()
}

fn prompt_xcframework_name(crate_name: &str, accept_all: bool) -> String {
let crate_name = format!("{}XCFramework", crate_name);
let default = crate_name.to_case(Case::UpperCamel);

if accept_all {
return default;
}

let theme = prompt_theme();
Input::with_theme(&theme)
.with_prompt("XCFramework Name")
.default(default)
.interact_text()
.unwrap()
}

fn pick_lib_type(
options: &[LibType],
suggested: Option<LibType>,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ enum Action {
#[arg(short = 'n', long = "name")]
package_name: Option<String>,

#[arg(long, default_value = "RustFramework")]
xcframework_name: String,
#[arg(short ='f', long = "xcframework")]
xcframework_name: Option<String>,

#[arg(short, long)]
/// Build package optimized for release (default: debug)
Expand Down