Skip to content

Commit

Permalink
[naga xtask] Add and use ValidateSubcommand::all.
Browse files Browse the repository at this point in the history
Add an `all` method to `ValidateSubcommand`, so that we can just use
matches elsewhere, and let the compile catch missing or duplicated
cases for us.
  • Loading branch information
ErichDonGubler authored and jimblandy committed Dec 27, 2023
1 parent 71f18fd commit e45a86f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
13 changes: 13 additions & 0 deletions naga/xtask/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ impl ValidateSubcommand {
}
}
}

pub(crate) fn all() -> impl Iterator<Item = Self> {
[
Self::Spirv,
Self::Metal,
Self::Glsl,
Self::Dot,
Self::Wgsl,
Self::Hlsl(ValidateHlslCommand::Dxc),
Self::Hlsl(ValidateHlslCommand::Fxc),
]
.into_iter()
}
}

#[derive(Debug)]
Expand Down
39 changes: 21 additions & 18 deletions naga/xtask/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,27 @@ fn collect_validation_jobs(jobs: &mut Vec<Job>, cmd: ValidateSubcommand) -> anyh
});
}
ValidateSubcommand::All => {
collect_validation_jobs(jobs, ValidateSubcommand::Wgsl)?;
collect_validation_jobs(jobs, ValidateSubcommand::Spirv)?;
collect_validation_jobs(jobs, ValidateSubcommand::Glsl)?;
collect_validation_jobs(jobs, ValidateSubcommand::Dot)?;

#[cfg(any(target_os = "macos", target_os = "ios"))]
collect_validation_jobs(jobs, ValidateSubcommand::Metal)?;

// The FXC compiler is only available on Windows.
//
// The DXC compiler can be built and run on any platform,
// but they don't make Linux releases and it's not clear
// what Git commit actually works on Linux, so restrict
// that to Windows as well.
#[cfg(windows)]
{
collect_validation_jobs(jobs, ValidateSubcommand::Hlsl(ValidateHlslCommand::Dxc))?;
collect_validation_jobs(jobs, ValidateSubcommand::Hlsl(ValidateHlslCommand::Fxc))?;
for subcmd in ValidateSubcommand::all() {
let should_validate = match &subcmd {
ValidateSubcommand::Wgsl
| ValidateSubcommand::Spirv
| ValidateSubcommand::Glsl
| ValidateSubcommand::Dot => true,
ValidateSubcommand::Metal => cfg!(any(target_os = "macos", target_os = "ios")),
// The FXC compiler is only available on Windows.
//
// The DXC compiler can be built and run on any platform,
// but they don't make Linux releases and it's not clear
// what Git commit actually works on Linux, so restrict
// that to Windows as well.
ValidateSubcommand::Hlsl(
ValidateHlslCommand::Dxc | ValidateHlslCommand::Fxc,
) => cfg!(os = "windows"),
ValidateSubcommand::All => continue,
};
if should_validate {
collect_validation_jobs(jobs, subcmd)?;
}
}
}
};
Expand Down

0 comments on commit e45a86f

Please sign in to comment.