Skip to content

Commit

Permalink
fix(cli): always rebuild IWorld ABI (#1929)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
dk1a and holic authored Dec 1, 2023
1 parent 9ef3f9a commit 2699630
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/odd-bags-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/cli": patch
---

Deploys will now always rebuild `IWorld.sol` interface (a workaround for https://github.com/foundry-rs/foundry/issues/6241)
26 changes: 25 additions & 1 deletion packages/cli/src/runDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ import { privateKeyToAccount } from "viem/accounts";
import { loadConfig } from "@latticexyz/config/node";
import { StoreConfig } from "@latticexyz/store";
import { WorldConfig } from "@latticexyz/world";
import { forge, getOutDirectory, getRemappings, getRpcUrl, getSrcDirectory } from "@latticexyz/common/foundry";
import {
forge,
getForgeConfig,
getOutDirectory,
getRemappings,
getRpcUrl,
getSrcDirectory,
} from "@latticexyz/common/foundry";
import chalk from "chalk";
import { execa } from "execa";
import { MUDError } from "@latticexyz/common/errors";
Expand All @@ -18,6 +25,9 @@ import { WorldDeploy } from "./deploy/common";
import { tablegen } from "@latticexyz/store/codegen";
import { worldgen } from "@latticexyz/world/node";
import { getExistingContracts } from "./utils/getExistingContracts";
import { debug as parentDebug } from "./debug";

const debug = parentDebug.extend("runDeploy");

export const deployOptions = {
configPath: { type: "string", desc: "Path to the config file" },
Expand Down Expand Up @@ -63,6 +73,20 @@ export async function runDeploy(opts: DeployOptions): Promise<WorldDeploy> {
if (!opts.skipBuild) {
const outPath = path.join(srcDir, config.codegenDirectory);
await Promise.all([tablegen(config, outPath, remappings), worldgen(config, getExistingContracts(srcDir), outPath)]);

// TODO remove when https://github.com/foundry-rs/foundry/issues/6241 is resolved
const forgeConfig = await getForgeConfig(profile);
if (forgeConfig.cache) {
const cacheFilePath = path.join(forgeConfig.cache_path, "solidity-files-cache.json");
if (existsSync(cacheFilePath)) {
debug("Unsetting cached content hash of IWorld.sol to force it to regenerate");
const solidityFilesCache = JSON.parse(readFileSync(cacheFilePath, "utf8"));
const worldInterfacePath = path.join(outPath, "world", "IWorld.sol");
solidityFilesCache["files"][worldInterfacePath]["contentHash"] = "";
writeFileSync(cacheFilePath, JSON.stringify(solidityFilesCache, null, 2));
}
}

await forge(["build"], { profile });
await execa("mud", ["abi-ts"], { stdio: "inherit" });
}
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/foundry/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ export interface ForgeConfig {
script: string;
out: string;
libs: string[];
cache: boolean;
cache_path: string;
eth_rpc_url: string | null;

// compiler
Expand Down

0 comments on commit 2699630

Please sign in to comment.