Skip to content

Commit

Permalink
Rename fields.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 28, 2023
1 parent a23fa17 commit 1c0734f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 43 deletions.
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,10 @@ 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"

[workspace.metadata.dist.custom-runners]
aarch64-unknown-linux-gnu = "buildjet-16vcpu-ubuntu-2204-arm"

# The profile that 'cargo dist' will build with
[profile.dist]
inherits = "release"
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 @@ -273,9 +273,9 @@ pub struct DistMetadata {
#[serde(skip_serializing_if = "Option::is_none")]
pub hosting: Option<Vec<HostingStyle>>,

/// 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 @@ -312,7 +312,7 @@ impl DistMetadata {
ssldotcom_windows_sign: _,
msvc_crt_static: _,
hosting: _,
custom_runners: _,
github_custom_runners: _,
} = self;
if let Some(include) = include {
for include in include {
Expand Down Expand Up @@ -358,7 +358,7 @@ impl DistMetadata {
ssldotcom_windows_sign,
msvc_crt_static,
hosting,
custom_runners,
github_custom_runners,
} = self;

// Check for global settings on local packages
Expand Down Expand Up @@ -450,8 +450,8 @@ impl DistMetadata {
if publish_jobs.is_none() {
*publish_jobs = workspace_config.publish_jobs.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 @@ -251,7 +251,7 @@ fn get_new_dist_metadata(
ssldotcom_windows_sign: None,
msvc_crt_static: None,
hosting: None,
custom_runners: None,
github_custom_runners: None,
}
};

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

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

// 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 @@ -307,7 +307,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 @@ -197,8 +197,8 @@ pub struct DistGraph {
pub msvc_crt_static: bool,
/// List of hosting providers to use
pub hosting: Option<HostingInfo>,
/// 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 @@ -712,7 +712,7 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
allow_dirty,
msvc_crt_static,
hosting,
custom_runners: _,
github_custom_runners: _,
} = &workspace_metadata;

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

0 comments on commit 1c0734f

Please sign in to comment.