Skip to content

Commit

Permalink
Hide function generation under flag in tgpu-gen (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhawryluk authored Nov 5, 2024
1 parent de53b64 commit c03f370
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/tgpu-gen/gen.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const LENGTH_VAR = 'arrayLength';
* @prop {boolean} toTs
* @prop {'commonjs' | 'esmodule'} moduleSyntax
* @prop {'keep' | 'overwrite'} [existingFileStrategy]
* @prop {boolean} experimentalFunctions
* @prop {Set<string>} [declaredIdentifiers]
* @prop {{tgpu?: boolean, data?: boolean }} [usedImports]
*/
Expand Down Expand Up @@ -106,6 +107,7 @@ export function generate(
outputPath: '',
toTs: true,
moduleSyntax: 'esmodule',
experimentalFunctions: true,
},
) {
const reflect = new WgslReflect(wgsl);
Expand All @@ -116,12 +118,16 @@ export function generate(
reflect.getBindGroups(),
options,
);
const functions = generateFunctions(reflect.functions, wgsl, options);

const functions = options.experimentalFunctions
? generateFunctions(reflect.functions, wgsl, options)
: null;

const imports = generateImports(options);
const exports_ = generateExports(options);

return `/* generated via tgpu-gen by TypeGPU */
${[imports, structs, aliases, bindGroupLayouts, functions, exports_].filter((generated) => generated.trim() !== '').join('\n')}
${[imports, structs, aliases, bindGroupLayouts, functions, exports_].filter((generated) => generated && generated.trim() !== '').join('\n')}
`;
}

Expand Down
2 changes: 2 additions & 0 deletions packages/tgpu-gen/tgpu-gen.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const args = arg({
'--overwrite': Boolean,
'--keep': Boolean,
'--watch': Boolean,
'--experimental-functions': Boolean,

'-v': '--version',
'-h': '--help',
Expand Down Expand Up @@ -177,6 +178,7 @@ const execute = async () => {
outputPath,
toTs,
moduleSyntax,
experimentalFunctions: args['--experimental-functions'] ?? false,
}).catch((error) => {
error.file = file;
throw error;
Expand Down

0 comments on commit c03f370

Please sign in to comment.