Skip to content

Commit

Permalink
feat(generic): error on using cargo-only options
Browse files Browse the repository at this point in the history
These options aren't valid when performing generic builds, and we should
give the user a warning about that as far ahead of time as we can.

Fixes #1526.
  • Loading branch information
mistydemeo committed Dec 10, 2024
1 parent c6275cc commit 9383bc1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
27 changes: 25 additions & 2 deletions cargo-dist/src/build/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use crate::{
};

impl<'a> DistGraphBuilder<'a> {
pub(crate) fn compute_generic_builds(&mut self, workspace_idx: WorkspaceIdx) -> Vec<BuildStep> {
pub(crate) fn compute_generic_builds(
&mut self,
workspace_idx: WorkspaceIdx,
) -> DistResult<Vec<BuildStep>> {
// For now we can be really simplistic and just do a workspace build for every
// target-triple we have a binary-that-needs-a-real-build for.
let mut targets = SortedMap::<TripleName, Vec<BinaryIdx>>::new();
Expand Down Expand Up @@ -60,7 +63,15 @@ impl<'a> DistGraphBuilder<'a> {
}));
}
}
builds

if !builds.is_empty() {
let options = cargo_only_options(&self.inner);
if !options.is_empty() {
return Err(DistError::CargoOnlyBuildOptions { options });
}
}

Ok(builds)
}

pub(crate) fn compute_extra_builds(&mut self) -> Vec<BuildStep> {
Expand Down Expand Up @@ -119,6 +130,18 @@ fn platform_appropriate_cxx(target: &TripleNameRef) -> &str {
}
}

fn cargo_only_options(dist_graph: &DistGraph) -> Vec<String> {
let mut out = vec![];
if dist_graph.config.builds.cargo.cargo_auditable {
out.push("cargo-auditable".to_owned());
}
if dist_graph.config.builds.cargo.cargo_cyclonedx {
out.push("cargo-cyclonedx".to_owned());
}

out
}

fn run_build(
dist_graph: &DistGraph,
build_command: &[String],
Expand Down
8 changes: 8 additions & 0 deletions cargo-dist/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ pub enum DistError {
target: Triple,
},

/// Generic build with Cargo-only build options
#[error("You're building a generic package but have a Cargo-only option enabled")]
#[diagnostic(help("Please disable the following from your configuration: {}", options.join(", ")))]
CargoOnlyBuildOptions {
/// The names of the invalid options
options: Vec<String>,
},

/// missing "build-command" for a package that needs one
#[error("dist package was missing a build-command\n{manifest}")]
#[diagnostic(help(
Expand Down
6 changes: 4 additions & 2 deletions cargo-dist/src/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2650,8 +2650,10 @@ impl<'pkg_graph> DistGraphBuilder<'pkg_graph> {
for workspace_idx in self.workspaces.all_workspace_indices() {
let workspace_kind = self.workspaces.workspace(workspace_idx).kind;
let builds = match workspace_kind {
axoproject::WorkspaceKind::Javascript => self.compute_generic_builds(workspace_idx),
axoproject::WorkspaceKind::Generic => self.compute_generic_builds(workspace_idx),
axoproject::WorkspaceKind::Javascript => {
self.compute_generic_builds(workspace_idx)?
}
axoproject::WorkspaceKind::Generic => self.compute_generic_builds(workspace_idx)?,
axoproject::WorkspaceKind::Rust => self.compute_cargo_builds(workspace_idx)?,
};
local_build_steps.extend(builds);
Expand Down

0 comments on commit 9383bc1

Please sign in to comment.