Skip to content

Commit

Permalink
Rename fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 29, 2023
1 parent 4f80985 commit 93aa664
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 40 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ targets = [
"x86_64-apple-darwin",
"x86_64-unknown-linux-musl",
"x86_64-pc-windows-msvc",
"aarch64-unknown-linux-gnu",
]
# Publish jobs to run in CI
pr-run-mode = "plan"
Expand Down
39 changes: 17 additions & 22 deletions cargo-dist/src/backend/ci/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ impl GithubCiInfo {

// Figure out what Local Artifact tasks we need
let local_runs = if dist.merge_tasks {
distribute_targets_to_runners_merged(local_targets, &dist.custom_runners)
distribute_targets_to_runners_merged(local_targets, &dist.github_custom_runners)
} else {
distribute_targets_to_runners_split(local_targets, &dist.custom_runners)
distribute_targets_to_runners_split(local_targets, &dist.github_custom_runners)
};
for (runner, targets) in local_runs {
use std::fmt::Write;
let install_dist =
install_dist_for_github_runner(&runner, &install_dist_sh, &install_dist_ps1);
install_dist_for_targets(&targets, &install_dist_sh, &install_dist_ps1);
let mut dist_args = String::from("--artifacts=local");
for target in &targets {
write!(dist_args, " --target={target}").unwrap();
Expand Down Expand Up @@ -194,9 +194,9 @@ impl GithubCiInfo {
/// succeed (uploading itself to the draft release).
///
/// In priniciple it does remove some duplicated setup work, so this is ostensibly "cheaper".
fn distribute_targets_to_runners_merged<'a, 'b>(
fn distribute_targets_to_runners_merged<'a>(
targets: SortedSet<&'a TargetTriple>,
custom_runners: &'b HashMap<String, String>,
custom_runners: &HashMap<String, String>,
) -> std::vec::IntoIter<(GithubRunner, Vec<&'a TargetTriple>)> {
let mut groups = SortedMap::<GithubRunner, Vec<&TargetTriple>>::new();
for target in targets {
Expand All @@ -215,9 +215,9 @@ fn distribute_targets_to_runners_merged<'a, 'b>(

/// Given a set of targets we want to build local artifacts for, map them to Github Runners
/// while preferring each target gets its own runner for latency and fault-isolation.
fn distribute_targets_to_runners_split<'a, 'b>(
fn distribute_targets_to_runners_split<'a>(
targets: SortedSet<&'a TargetTriple>,
custom_runners: &'b HashMap<String, String>,
custom_runners: &HashMap<String, String>,
) -> std::vec::IntoIter<(GithubRunner, Vec<&'a TargetTriple>)> {
let mut groups = vec![];
for target in targets {
Expand Down Expand Up @@ -265,25 +265,20 @@ fn github_runner_for_target(
}

/// Select the cargo-dist installer approach for a given Github Runner
fn install_dist_for_github_runner<'a>(
runner: &'a GithubRunner,
fn install_dist_for_targets<'a>(
targets: &'a [&'a TargetTriple],
install_sh: &'a str,
install_ps1: &'a str,
) -> &'a str {
dbg!(runner);

if runner.contains("linux")
|| runner.contains("ubuntu")
|| runner.contains("apple")
|| runner.contains("macos")
|| runner.contains("darwin")
{
install_sh
} else if runner.contains("windows") || runner.contains("msvc") {
install_ps1
} else {
unreachable!("internal error: unknown github runner!?")
for target in targets {
if target.contains("linux") || target.contains("apple") {
return install_sh;
} else if target.contains("windows") {
return install_ps1;
}
}

unreachable!("internal error: unknown target triple!?")
}

fn brewfile_from(packages: &[String]) -> String {
Expand Down
12 changes: 6 additions & 6 deletions cargo-dist/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ pub struct DistMetadata {
#[serde(skip_serializing_if = "Option::is_none")]
pub extra_artifacts: Option<Vec<ExtraArtifact>>,

/// Custom GitHub runners, mapped by triple
/// Custom GitHub runners, mapped by triple target
#[serde(skip_serializing_if = "Option::is_none")]
pub custom_runners: Option<HashMap<String, String>>,
pub github_custom_runners: Option<HashMap<String, String>>,
}

impl DistMetadata {
Expand Down Expand Up @@ -317,7 +317,7 @@ impl DistMetadata {
msvc_crt_static: _,
hosting: _,
extra_artifacts: _,
custom_runners: _,
github_custom_runners: _,
} = self;
if let Some(include) = include {
for include in include {
Expand Down Expand Up @@ -364,7 +364,7 @@ impl DistMetadata {
msvc_crt_static,
hosting,
extra_artifacts,
custom_runners,
github_custom_runners,
} = self;

// Check for global settings on local packages
Expand Down Expand Up @@ -459,8 +459,8 @@ impl DistMetadata {
if extra_artifacts.is_none() {
*extra_artifacts = workspace_config.extra_artifacts.clone();
}
if custom_runners.is_none() {
*custom_runners = workspace_config.custom_runners.clone();
if github_custom_runners.is_none() {
*github_custom_runners = workspace_config.github_custom_runners.clone();
}

// This was historically implemented as extend, but I'm not convinced the
Expand Down
11 changes: 6 additions & 5 deletions cargo-dist/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ fn get_new_dist_metadata(
msvc_crt_static: None,
hosting: None,
extra_artifacts: None,
custom_runners: None,
github_custom_runners: None,
}
};

Expand Down Expand Up @@ -773,7 +773,7 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
msvc_crt_static,
hosting,
extra_artifacts: _,
custom_runners: _,
github_custom_runners: _,
} = &meta;

apply_optional_value(
Expand Down Expand Up @@ -967,11 +967,12 @@ fn apply_dist_to_metadata(metadata: &mut toml_edit::Item, meta: &DistMetadata) {
hosting.as_ref(),
);

// NOTE: HashMap not supported by axoasset
// apply_optional_value(
// table,
// "custom_runners",
// "# Custom GitHub runners to use for builds, mapped by triple\n",
// custom_runners.as_ref(),
// "github-custom-runners",
// "# Custom GitHub runners to use for builds, mapped by triple target\n",
// github_custom_runners.as_ref(),
// );

// Finalize the table
Expand Down
2 changes: 1 addition & 1 deletion cargo-dist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ fn do_generate_preflight_checks(dist: &DistGraph) -> Result<()> {
&& !desired_version.pre.starts_with("github-")
&& !matches!(dist.allow_dirty, DirtyMode::AllowAll)
{
// return Err(miette!("you're running cargo-dist {}, but 'cargo-dist-version = {}' is set in your Cargo.toml\n\nYou should update cargo-dist-version if you want to update to this version", current_version, desired_version));
return Err(miette!("you're running cargo-dist {}, but 'cargo-dist-version = {}' is set in your Cargo.toml\n\nYou should update cargo-dist-version if you want to update to this version", current_version, desired_version));
}
}
if !dist.is_init {
Expand Down
10 changes: 5 additions & 5 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ pub struct DistGraph {
pub hosting: Option<HostingInfo>,
/// Additional artifacts to build and upload
pub extra_artifacts: Vec<ExtraArtifact>,
/// Custom GitHub runners, mapped by triple
pub custom_runners: HashMap<String, String>,
/// Custom GitHub runners, mapped by triple target
pub github_custom_runners: HashMap<String, String>,
}

/// Info about artifacts should be hosted
Expand Down Expand Up @@ -737,7 +737,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
msvc_crt_static,
hosting,
extra_artifacts,
custom_runners: _,
github_custom_runners: _,
} = &workspace_metadata;

let desired_cargo_dist_version = cargo_dist_version.clone();
Expand Down Expand Up @@ -850,8 +850,8 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
msvc_crt_static,
hosting,
extra_artifacts: extra_artifacts.clone().unwrap_or_default(),
custom_runners: workspace_metadata
.custom_runners
github_custom_runners: workspace_metadata
.github_custom_runners
.clone()
.unwrap_or_default(),
},
Expand Down

0 comments on commit 93aa664

Please sign in to comment.