diff --git a/cargo-dist/src/init.rs b/cargo-dist/src/init.rs index fca5ebeb4..16c24f41f 100644 --- a/cargo-dist/src/init.rs +++ b/cargo-dist/src/init.rs @@ -1,7 +1,5 @@ -use std::ops::Not; - -use axoproject::errors::AxoprojectError; use axoproject::WorkspaceInfo; +use axoproject::{errors::AxoprojectError, platforms::triple_to_display_name}; use camino::Utf8PathBuf; use cargo_dist_schema::PrRunMode; use semver::Version; @@ -205,7 +203,7 @@ fn get_new_dist_metadata( ci: None, installers: None, tap: None, - targets: cfg.targets.is_empty().not().then(|| cfg.targets.clone()), + targets: None, dist: None, include: None, auto_includes: None, @@ -301,6 +299,63 @@ fn get_new_dist_metadata( } } + { + // Start with builtin targets + let default_platforms = crate::default_desktop_targets(); + let mut known = default_platforms.clone(); + // If the config doesn't have targets at all, generate them + let config_vals = meta.targets.as_deref().unwrap_or(&default_platforms); + let cli_vals = cfg.targets.as_slice(); + // Add anything custom they did to the list (this will do some reordering if they hand-edited) + for val in config_vals.iter().chain(cli_vals) { + if !known.contains(val) { + known.push(val.clone()); + } + } + + // Prettify/sort things + let desc = move |triple: &str| -> String { + let pretty = triple_to_display_name(triple).unwrap_or("[unknown]"); + format!("{pretty} - {triple}") + }; + known.sort_by_cached_key(|k| desc(k).to_uppercase()); + + let mut defaults = vec![]; + let mut keys = vec![]; + for item in &known { + // If this target is in their config, keep it + // If they passed it on the CLI, flip it on + let config_had_it = config_vals.contains(item); + let cli_had_it = cli_vals.contains(item); + + let default = config_had_it || cli_had_it; + defaults.push(default); + + keys.push(desc(item)); + } + + // Prompt the user + let prompt = r#"what platforms do you want to build for?"#; + let selected = if args.yes { + defaults + .iter() + .enumerate() + .filter_map(|(idx, enabled)| enabled.then_some(idx)) + .collect() + } else { + let res = MultiSelect::with_theme(&theme) + .items(&keys) + .defaults(&defaults) + .with_prompt(prompt) + .interact()?; + eprintln!(); + res + }; + + // Apply the results + meta.targets = Some(selected.into_iter().map(|i| known[i].clone()).collect()); + } + // Enable CI backends { // FIXME: when there is more than one option this should be a proper @@ -339,10 +394,7 @@ fn get_new_dist_metadata( } // Prompt the user - let prompt = r#"enable Github CI integration? - this creates a CI action which automates creating a Github Release, - builds all your binaries/archives, and then uploads them to the Release - it also unlocks the ability to generate installers which fetch those artifacts"#; + let prompt = r#"enable Github CI and Releases?"#; let default = defaults[github_key]; let github_selected = if args.yes { diff --git a/cargo-dist/src/lib.rs b/cargo-dist/src/lib.rs index fa6444906..48a4c7d39 100644 --- a/cargo-dist/src/lib.rs +++ b/cargo-dist/src/lib.rs @@ -753,3 +753,20 @@ fn generate_installer(dist: &DistGraph, style: &InstallerImpl) -> Result<()> { } Ok(()) } + +/// Get the default list of targets +pub fn default_desktop_targets() -> Vec { + vec![ + // Everyone can build x64! + axoproject::platforms::TARGET_X64_LINUX_GNU.to_owned(), + axoproject::platforms::TARGET_ARM64_LINUX_GNU.to_owned(), + axoproject::platforms::TARGET_X64_MAC.to_owned(), + // Apple is really easy to cross from Apple + axoproject::platforms::TARGET_ARM64_MAC + .to_owned() + .to_owned(), + // other cross-compiles not yet supported + // axoproject::platforms::TARGET_X64_WINDOWS.to_owned(), + // axoproject::platforms::TARGET_ARM64_WINDOWS.to_owned(), + ] +} diff --git a/cargo-dist/src/main.rs b/cargo-dist/src/main.rs index 16aba48d8..7c5f4bafd 100644 --- a/cargo-dist/src/main.rs +++ b/cargo-dist/src/main.rs @@ -202,18 +202,12 @@ fn cmd_plan(cli: &Cli, _args: &PlanArgs) -> Result<(), miette::Report> { } fn cmd_init(cli: &Cli, args: &InitArgs) -> Result<(), miette::Report> { - // This command is more automagic, so provide default targets if none are chosen - let targets = if cli.target.is_empty() { - default_desktop_targets() - } else { - cli.target.clone() - }; let config = cargo_dist::config::Config { needs_coherent_announcement_tag: false, artifact_mode: cargo_dist::config::ArtifactMode::All, no_local_paths: cli.no_local_paths, allow_all_dirty: cli.allow_dirty, - targets, + targets: cli.target.clone(), ci: cli.ci.iter().map(|ci| ci.to_lib()).collect(), installers: cli.installer.iter().map(|ins| ins.to_lib()).collect(), announcement_tag: cli.tag.clone(), @@ -254,20 +248,6 @@ fn cmd_generate_ci(cli: &Cli, args: &GenerateCiArgs) -> Result<(), miette::Repor ) } -fn default_desktop_targets() -> Vec { - vec![ - // Everyone can build x64! - "x86_64-unknown-linux-gnu".to_owned(), - "x86_64-apple-darwin".to_owned(), - "x86_64-pc-windows-msvc".to_owned(), - // Apple is really easy to cross from Apple - "aarch64-apple-darwin".to_owned(), - // other cross-compiles not yet supported - // "aarch64-gnu-unknown-linux".to_owned(), - // "aarch64-pc-windows-msvc".to_owned(), - ] -} - fn cmd_help_md(_args: &Cli, _sub_args: &HelpMarkdownArgs) -> Result<(), miette::Report> { let mut out = Term::stdout(); print_help_markdown(&mut out).into_diagnostic()