Skip to content

Commit 6150ddc

Browse files
committed
fix(cli): treat --api vk= and --api vulkan= as equivalent
Also generate the same output stem ("vk") for consistency. Signed-off-by: Steven Noonan <steven@uplinklabs.net>
1 parent 325c6d9 commit 6150ddc

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

src/cli.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ impl Cli {
127127
// ApiRequest
128128
// ---------------------------------------------------------------------------
129129

130+
/// Normalize an API name to its canonical short form.
131+
///
132+
/// The Khronos XML uses `"vulkan"` in feature and extension `api=`
133+
/// / `supported=` attributes, but the CLI convention is `"vk"`. This function
134+
/// maps the long form to the short form so the rest of the codebase can use
135+
/// a single canonical name. All other API names pass through unchanged.
136+
pub fn canonical_api_name(name: &str) -> &str {
137+
match name {
138+
"vulkan" => "vk",
139+
other => other,
140+
}
141+
}
142+
130143
/// One parsed entry from the `--api` argument.
131144
#[derive(Debug, Clone)]
132145
pub struct ApiRequest {
@@ -165,7 +178,7 @@ impl ApiRequest {
165178
.transpose()?;
166179

167180
Ok(Self {
168-
name: name.to_string(),
181+
name: canonical_api_name(name).to_string(),
169182
profile: profile.map(str::to_string),
170183
version,
171184
})
@@ -227,6 +240,22 @@ mod tests {
227240
assert_eq!(r.version, Some(Version::new(1, 3)));
228241
}
229242

243+
#[test]
244+
fn parse_vulkan_normalizes_to_vk() {
245+
// "vulkan" is the XML-canonical name; "vk" is the CLI-canonical name.
246+
// Both must produce the same ApiRequest.
247+
let r = ApiRequest::parse("vulkan=1.3").unwrap();
248+
assert_eq!(r.name, "vk", "vulkan should normalize to vk");
249+
assert_eq!(r.version, Some(Version::new(1, 3)));
250+
}
251+
252+
#[test]
253+
fn parse_vulkan_bare_normalizes_to_vk() {
254+
let r = ApiRequest::parse("vulkan").unwrap();
255+
assert_eq!(r.name, "vk");
256+
assert!(r.version.is_none());
257+
}
258+
230259
#[test]
231260
fn parse_bare_name_no_version() {
232261
let r = ApiRequest::parse("egl").unwrap();

src/resolve.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use anyhow::Result;
1010
use indexmap::IndexMap;
1111
use serde::Serialize;
1212

13-
use crate::cli::{ApiRequest, Cli};
13+
use crate::cli::{ApiRequest, Cli, canonical_api_name};
1414
use crate::fetch;
1515
use crate::ir::{RawCommand, RawSpec};
1616
use crate::parse;
@@ -649,7 +649,7 @@ fn select_features<'a>(raw: &'a RawSpec, requests: &[ApiRequest]) -> Vec<Selecte
649649
for req in requests {
650650
let max_ver = req.version.clone();
651651
for feat in &raw.features {
652-
if feat.api != req.name {
652+
if canonical_api_name(&feat.api) != canonical_api_name(&req.name) {
653653
continue;
654654
}
655655
if let Some(ref mv) = max_ver
@@ -702,7 +702,13 @@ fn select_extensions<'a>(
702702
want_promoted: bool,
703703
want_predecessors: bool,
704704
) -> Vec<SelectedExt<'a>> {
705-
let api_set: HashSet<&str> = requests.iter().map(|r| r.name.as_str()).collect();
705+
let mut api_set: HashSet<&str> = requests.iter().map(|r| r.name.as_str()).collect();
706+
// The Khronos XML uses "vulkan" in supported= attributes, but our
707+
// canonical name is "vk". Insert the XML form so contains() lookups
708+
// against XML-sourced strings succeed.
709+
if api_set.contains("vk") {
710+
api_set.insert("vulkan");
711+
}
706712
// WGL mandatory extensions (spec gotcha #9).
707713
let wgl_mandatory: HashSet<&str> = if spec_name == "wgl" {
708714
["WGL_ARB_extensions_string", "WGL_EXT_extensions_string"]
@@ -783,7 +789,8 @@ fn select_extensions<'a>(
783789
.iter()
784790
.filter(|s| api_set.contains(s.as_str()))
785791
.any(|api| {
786-
let Some(core_cmds) = per_api_core_cmds.get(api.as_str()) else {
792+
let Some(core_cmds) = per_api_core_cmds.get(canonical_api_name(api.as_str()))
793+
else {
787794
return false;
788795
};
789796
ext.requires
@@ -1086,7 +1093,12 @@ fn build_ext_pfn_ranges(
10861093
let relevant_exts: Vec<(usize, &SelectedExt)> = exts
10871094
.iter()
10881095
.enumerate()
1089-
.filter(|(_, e)| e.raw.supported.iter().any(|s| s == api))
1096+
.filter(|(_, e)| {
1097+
e.raw
1098+
.supported
1099+
.iter()
1100+
.any(|s| canonical_api_name(s) == canonical_api_name(api))
1101+
})
10901102
.collect();
10911103

10921104
for (_orig_idx, ext) in &relevant_exts {
@@ -1913,7 +1925,9 @@ fn api_profile_matches(
19131925
target_prof: Option<&str>,
19141926
) -> bool {
19151927
if let Some(a) = elem_api
1916-
&& !a.split(',').any(|x| x.trim() == target_api)
1928+
&& !a
1929+
.split(',')
1930+
.any(|x| canonical_api_name(x.trim()) == canonical_api_name(target_api))
19171931
{
19181932
return false;
19191933
}

0 commit comments

Comments
 (0)