Skip to content

Commit f63d001

Browse files
committed
fix(vulkan): ensure we use the proper spec name in the generated file
Signed-off-by: Steven Noonan <steven@uplinklabs.net>
1 parent 8e7e53f commit f63d001

3 files changed

Lines changed: 38 additions & 18 deletions

File tree

src/cli.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,30 @@ impl Cli {
129129

130130
/// Normalize an API name to its canonical short form.
131131
///
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.
132+
/// The Khronos XML uses `"vulkan"` in feature and extension `api=` / `supported=`
133+
/// attributes, but the CLI convention (and GLAD's convention) is `"vk"`. This
134+
/// function maps the long form to the short form so the rest of the codebase
135+
/// can use a single canonical name. All other API names pass through unchanged.
136136
pub fn canonical_api_name(name: &str) -> &str {
137137
match name {
138138
"vulkan" => "vk",
139139
other => other,
140140
}
141141
}
142142

143+
/// Map a canonical short API name back to the XML-canonical form.
144+
///
145+
/// Used when the name will appear in generated symbol names (e.g.
146+
/// `kExtIdx_vulkan`, `gloam_vk_find_extensions_vulkan`), where the XML
147+
/// convention is the appropriate one. `spec_name` ("vk") controls file
148+
/// stems; this controls symbol suffixes.
149+
pub fn xml_api_name(name: &str) -> &str {
150+
match name {
151+
"vk" => "vulkan",
152+
other => other,
153+
}
154+
}
155+
143156
/// One parsed entry from the `--api` argument.
144157
#[derive(Debug, Clone)]
145158
pub struct ApiRequest {

src/resolve.rs

Lines changed: 9 additions & 2 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, canonical_api_name};
13+
use crate::cli::{ApiRequest, Cli, canonical_api_name, xml_api_name};
1414
use crate::fetch;
1515
use crate::ir::{RawCommand, RawSpec};
1616
use crate::parse;
@@ -335,7 +335,14 @@ fn resolve_feature_set(
335335
_ => spec_name.as_str(),
336336
};
337337

338-
let api_names: Vec<String> = requests.iter().map(|r| r.name.clone()).collect();
338+
// api_names uses the XML-canonical form ("vulkan" not "vk") because
339+
// these flow into generated C symbol suffixes (kExtIdx_vulkan, etc.)
340+
// and IndexMap keys used by the templates. File stems come from
341+
// spec_name ("vk"), not from here.
342+
let api_names: Vec<String> = requests
343+
.iter()
344+
.map(|r| xml_api_name(&r.name).to_string())
345+
.collect();
339346

340347
// ------------------------------------------------------------------
341348
// Step 1: Determine which features (versions) are selected.

tests/generate_vulkan.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn vulkan_13_generates_expected_files() {
111111
.assert()
112112
.success();
113113

114-
assert_c_output_exists(dir.path(), "vk");
114+
assert_c_output_exists(dir.path(), "vulkan");
115115
try_compile_c(dir.path());
116116
}
117117

@@ -130,7 +130,7 @@ fn vulkan_13_with_loader_generates_and_compiles() {
130130
.assert()
131131
.success();
132132

133-
assert_c_output_exists(dir.path(), "vk");
133+
assert_c_output_exists(dir.path(), "vulkan");
134134
try_compile_c(dir.path());
135135
}
136136

@@ -149,7 +149,7 @@ fn vulkan_13_with_alias_generates_and_compiles() {
149149
.assert()
150150
.success();
151151

152-
assert_c_output_exists(dir.path(), "vk");
152+
assert_c_output_exists(dir.path(), "vulkan");
153153
try_compile_c(dir.path());
154154
}
155155

@@ -169,7 +169,7 @@ fn vulkan_13_all_flags_generates_and_compiles() {
169169
.assert()
170170
.success();
171171

172-
assert_c_output_exists(dir.path(), "vk");
172+
assert_c_output_exists(dir.path(), "vulkan");
173173
try_compile_c(dir.path());
174174
}
175175

@@ -180,15 +180,15 @@ fn vulkan_latest_version_generates() {
180180
gloam()
181181
.args([
182182
"--api",
183-
"vk",
183+
"vulkan",
184184
"--out-path",
185185
dir.path().to_str().unwrap(),
186186
"c",
187187
])
188188
.assert()
189189
.success();
190190

191-
assert_c_output_exists(dir.path(), "vk");
191+
assert_c_output_exists(dir.path(), "vulkan");
192192
try_compile_c(dir.path());
193193
}
194194

@@ -208,7 +208,7 @@ fn vulkan_long_name_normalizes_to_vk_stem() {
208208
.assert()
209209
.success();
210210

211-
assert_c_output_exists(dir.path(), "vk");
211+
assert_c_output_exists(dir.path(), "vulkan");
212212
try_compile_c(dir.path());
213213
}
214214

@@ -230,7 +230,7 @@ fn vulkan_header_has_context_and_scope_enum() {
230230
.assert()
231231
.success();
232232

233-
let header = read_header(dir.path(), "vk");
233+
let header = read_header(dir.path(), "vulkan");
234234

235235
assert!(
236236
header.contains("GloamVulkanContext"),
@@ -266,7 +266,7 @@ fn vulkan_header_has_core_commands() {
266266
.assert()
267267
.success();
268268

269-
let header = read_header(dir.path(), "vk");
269+
let header = read_header(dir.path(), "vulkan");
270270

271271
// Fundamental Vulkan entry points that must always be present.
272272
assert!(
@@ -303,7 +303,7 @@ fn vulkan_header_has_version_macros() {
303303
.assert()
304304
.success();
305305

306-
let header = read_header(dir.path(), "vk");
306+
let header = read_header(dir.path(), "vulkan");
307307

308308
assert!(
309309
header.contains("VK_VERSION_1_0 1"),
@@ -339,7 +339,7 @@ fn vulkan_10_does_not_have_13_features() {
339339
.assert()
340340
.success();
341341

342-
let header = read_header(dir.path(), "vk");
342+
let header = read_header(dir.path(), "vulkan");
343343

344344
assert!(
345345
header.contains("VK_VERSION_1_0 1"),
@@ -372,7 +372,7 @@ fn vulkan_with_extension_filter_generates() {
372372
.assert()
373373
.success();
374374

375-
let header = read_header(dir.path(), "vk");
375+
let header = read_header(dir.path(), "vulkan");
376376
assert!(
377377
header.contains("KHR_swapchain"),
378378
"VK_KHR_swapchain should be present when explicitly requested"

0 commit comments

Comments
 (0)