From 373a9f801dd24609ec95a6a38823474559e34201 Mon Sep 17 00:00:00 2001 From: dk1a Date: Mon, 13 Nov 2023 11:46:25 +0300 Subject: [PATCH 1/4] fix(cli): hack around foundry issue 6241 --- packages/cli/src/runDeploy.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index 62c658598f..a452566934 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -18,6 +18,7 @@ import { WorldDeploy } from "./deploy/common"; import { tablegen } from "@latticexyz/store/codegen"; import { worldgen } from "@latticexyz/world/node"; import { getExistingContracts } from "./utils/getExistingContracts"; +import { rm } from "node:fs/promises"; export const deployOptions = { configPath: { type: "string", desc: "Path to the config file" }, @@ -63,6 +64,10 @@ export async function runDeploy(opts: DeployOptions): Promise { 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 + await rm(path.join(outDir, "IWorld.sol"), { recursive: true, force: true }); + await forge(["build"], { profile }); await execa("mud", ["abi-ts"], { stdio: "inherit" }); } From 5a410491da56a862da32b639f066082b9115a206 Mon Sep 17 00:00:00 2001 From: dk1a Date: Mon, 13 Nov 2023 16:44:22 +0300 Subject: [PATCH 2/4] modify cache file instead --- packages/cli/src/runDeploy.ts | 20 +++++++++++++++++--- packages/common/src/foundry/index.ts | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index a452566934..a8cd080db4 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -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"; @@ -18,7 +25,6 @@ import { WorldDeploy } from "./deploy/common"; import { tablegen } from "@latticexyz/store/codegen"; import { worldgen } from "@latticexyz/world/node"; import { getExistingContracts } from "./utils/getExistingContracts"; -import { rm } from "node:fs/promises"; export const deployOptions = { configPath: { type: "string", desc: "Path to the config file" }, @@ -66,7 +72,15 @@ export async function runDeploy(opts: DeployOptions): Promise { 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 - await rm(path.join(outDir, "IWorld.sol"), { recursive: true, force: true }); + const forgeConfig = await getForgeConfig(profile); + if (forgeConfig.cache) { + const cacheFilePath = path.join(forgeConfig.cache_path, "solidity-files-cache.json"); + const worldInterfacePath = path.join(outPath, "world", "IWorld.sol"); + + const solidityFilesCache = JSON.parse(readFileSync(cacheFilePath, "utf8")); + solidityFilesCache["files"][worldInterfacePath]["contentHash"] = "00000000000000000000000000000000"; + writeFileSync(cacheFilePath, JSON.stringify(solidityFilesCache, undefined, 2)); + } await forge(["build"], { profile }); await execa("mud", ["abi-ts"], { stdio: "inherit" }); diff --git a/packages/common/src/foundry/index.ts b/packages/common/src/foundry/index.ts index 8ff7d8b199..b7f29ee61a 100644 --- a/packages/common/src/foundry/index.ts +++ b/packages/common/src/foundry/index.ts @@ -7,6 +7,8 @@ export interface ForgeConfig { script: string; out: string; libs: string[]; + cache: boolean; + cache_path: string; eth_rpc_url: string | null; // compiler From 86c5f236aaf9a4becf5346a6367a4f42e5939cbd Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 1 Dec 2023 12:33:39 +0000 Subject: [PATCH 3/4] don't die when cache doesn't exist yet --- packages/cli/src/runDeploy.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/runDeploy.ts b/packages/cli/src/runDeploy.ts index a8cd080db4..36689081b3 100644 --- a/packages/cli/src/runDeploy.ts +++ b/packages/cli/src/runDeploy.ts @@ -25,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" }, @@ -75,11 +78,13 @@ export async function runDeploy(opts: DeployOptions): Promise { const forgeConfig = await getForgeConfig(profile); if (forgeConfig.cache) { const cacheFilePath = path.join(forgeConfig.cache_path, "solidity-files-cache.json"); - const worldInterfacePath = path.join(outPath, "world", "IWorld.sol"); - - const solidityFilesCache = JSON.parse(readFileSync(cacheFilePath, "utf8")); - solidityFilesCache["files"][worldInterfacePath]["contentHash"] = "00000000000000000000000000000000"; - writeFileSync(cacheFilePath, JSON.stringify(solidityFilesCache, undefined, 2)); + 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 }); From 91472091654f6692060f564951326ddd31408d99 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 1 Dec 2023 04:34:49 -0800 Subject: [PATCH 4/4] Create odd-bags-compete.md --- .changeset/odd-bags-compete.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/odd-bags-compete.md diff --git a/.changeset/odd-bags-compete.md b/.changeset/odd-bags-compete.md new file mode 100644 index 0000000000..e0899b05a0 --- /dev/null +++ b/.changeset/odd-bags-compete.md @@ -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)