Skip to content

Commit bf24e5a

Browse files
authored
add content hash to string table if available (#4)
1 parent 7941710 commit bf24e5a

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

src/code-generator-static-impl.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ std::string pass_as_string(T&& v) {
229229
`);
230230

231231
if (this.#stringTable) {
232-
implContent.push(`#include "${includePathPrefix}/string_table.h"`);
232+
const hash = templateImplementationHash.get("string_table.h");
233+
implContent.push(`#include "${includePathPrefix}/string_table.h" // ${hash}`);
233234
}
234235
implContent.push("");
235236
implContent.push("// Include template implementations");
@@ -241,12 +242,6 @@ std::string pass_as_string(T&& v) {
241242
}
242243
const baseName = name.slice(0, -templateExt.length);
243244
const hash = templateImplementationHash.get(name);
244-
if (!hash) {
245-
throw new WgslTemplateBuildError(
246-
`Missing hash for template implementation "${name}"`,
247-
"output-validation-failed"
248-
);
249-
}
250245
implContent.push(`#include "${includePathPrefix}generated/${baseName}.h" // ${hash}`);
251246
}
252247

@@ -325,7 +320,14 @@ std::string pass_as_string(T&& v) {
325320
templateImplementationHash.set(name, createHash("sha256").update(content).digest("hex"));
326321
}
327322

328-
// STEP.2. Generate implementation index_impl.h
323+
// STEP.2. Generate the string table if needed
324+
if (this.#stringTable) {
325+
const content = this.#buildGenerateStringTable();
326+
result.set("string_table.h", content);
327+
templateImplementationHash.set("string_table.h", createHash("sha256").update(content).digest("hex"));
328+
}
329+
330+
// STEP.3. Generate implementation index_impl.h
329331
result.set(
330332
"index_impl.h",
331333
this.#buildGenerateIndexImpl(
@@ -336,14 +338,9 @@ std::string pass_as_string(T&& v) {
336338
)
337339
);
338340

339-
// STEP.3. Generate the index.h
341+
// STEP.4. Generate the index.h
340342
result.set("index.h", this.#buildGenerateIndex(repo));
341343

342-
// STEP.4. Generate the string table if needed
343-
if (this.#stringTable) {
344-
result.set("string_table.h", this.#buildGenerateStringTable());
345-
}
346-
347344
return {
348345
basePath: repo.basePath,
349346
templates: result,

test/testcases/build-basic/expected/static-cpp/index_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ std::string pass_as_string(T&& v) {
3131
}
3232
} // namespace wgsl_detail
3333

34-
#include "/string_table.h"
34+
#include "/string_table.h" // 16d2563fc58e81b41c9b3be4a1c9a9e0a4458c7ff6849b4359f77a6ec7f3d23c
3535

3636
// Include template implementations
3737

0 commit comments

Comments
 (0)