Skip to content

Commit fb2745a

Browse files
authored
fix(world): support generating libraries for systems without function registration (#3670)
1 parent ab837ce commit fb2745a

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

.changeset/poor-apples-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/world": patch
3+
---
4+
5+
Support generating libraries for systems without function registration.

packages/world/ts/node/render-solidity/worldgen.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export async function worldgen({
2626

2727
const systems = (await resolveSystems({ rootDir, config }))
2828
// TODO: move to codegen option or generate "system manifest" and codegen from that
29-
.filter((system) => system.deploy.registerWorldFunctions)
29+
.filter((system) => system.deploy.registerWorldFunctions || config.codegen.generateSystemLibraries)
3030
.map((system) => {
3131
const interfaceName = `I${system.label}`;
3232
const libraryName = `${system.label}Lib`;
@@ -61,12 +61,14 @@ export async function worldgen({
6161

6262
const outputPath = path.join(worldgenOutDir, config.codegen.worldInterfaceName + ".sol");
6363

64-
const worldImports = systems.map(
65-
(system): ImportDatum => ({
66-
symbol: system.interfaceName,
67-
path: "./" + path.relative(path.dirname(outputPath), system.interfacePath),
68-
}),
69-
);
64+
const worldImports = systems
65+
.filter((system) => system.deploy.registerWorldFunctions)
66+
.map(
67+
(system): ImportDatum => ({
68+
symbol: system.interfaceName,
69+
path: "./" + path.relative(path.dirname(outputPath), system.interfacePath),
70+
}),
71+
);
7072

7173
const storeImportPath = config.codegen.storeImportPath.startsWith(".")
7274
? "./" + path.relative(path.dirname(outputPath), path.join(rootDir, config.codegen.storeImportPath))
@@ -80,24 +82,27 @@ export async function worldgen({
8082
const source = await fs.readFile(path.join(rootDir, system.sourcePath), "utf8");
8183
// get external functions from a contract
8284
const { functions, errors, symbolImports } = contractToInterface(source, system.label);
83-
const interfaceImports = symbolImports.map(
84-
({ symbol, path: importPath }): ImportDatum => ({
85-
symbol,
86-
path: importPath.startsWith(".")
87-
? "./" + path.relative(worldgenOutDir, path.join(rootDir, path.dirname(system.sourcePath), importPath))
88-
: importPath,
89-
}),
90-
);
9185

92-
const systemInterface = renderSystemInterface({
93-
name: system.interfaceName,
94-
functionPrefix: system.namespace === "" ? "" : `${system.namespace}__`,
95-
functions,
96-
errors,
97-
imports: interfaceImports,
98-
});
99-
// write to file
100-
await formatAndWriteSolidity(systemInterface, system.interfacePath, "Generated system interface");
86+
if (system.deploy.registerWorldFunctions) {
87+
const interfaceImports = symbolImports.map(
88+
({ symbol, path: importPath }): ImportDatum => ({
89+
symbol,
90+
path: importPath.startsWith(".")
91+
? "./" + path.relative(worldgenOutDir, path.join(rootDir, path.dirname(system.sourcePath), importPath))
92+
: importPath,
93+
}),
94+
);
95+
96+
const systemInterface = renderSystemInterface({
97+
name: system.interfaceName,
98+
functionPrefix: system.namespace === "" ? "" : `${system.namespace}__`,
99+
functions,
100+
errors,
101+
imports: interfaceImports,
102+
});
103+
// write to file
104+
await formatAndWriteSolidity(systemInterface, system.interfacePath, "Generated system interface");
105+
}
101106

102107
if (config.codegen.generateSystemLibraries) {
103108
const systemImport = {

0 commit comments

Comments
 (0)