diff --git a/.changeset/spotty-tomatoes-press.md b/.changeset/spotty-tomatoes-press.md new file mode 100644 index 0000000000..aa01d9212d --- /dev/null +++ b/.changeset/spotty-tomatoes-press.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Updated the compilation logs to include the targeted EVM versions. diff --git a/packages/hardhat-core/src/builtin-tasks/compile.ts b/packages/hardhat-core/src/builtin-tasks/compile.ts index 1c92dd36ea..91eb11fbb5 100644 --- a/packages/hardhat-core/src/builtin-tasks/compile.ts +++ b/packages/hardhat-core/src/builtin-tasks/compile.ts @@ -40,6 +40,7 @@ import { getFullyQualifiedName } from "../utils/contract-names"; import { localPathToSourceName } from "../utils/source-names"; import { getAllFilesMatching } from "../internal/util/fs-utils"; +import { getEvmVersionFromSolcVersion } from "../internal/solidity/compiler/solc-info"; import { TASK_COMPILE, TASK_COMPILE_GET_COMPILATION_TASKS, @@ -1291,15 +1292,43 @@ subtask(TASK_COMPILE_SOLIDITY_LOG_COMPILATION_RESULT) .setAction( async ({ compilationJobs }: { compilationJobs: CompilationJob[] }) => { let count = 0; + const evmVersions = new Set(); + const unknownEvmVersions = new Set(); + for (const job of compilationJobs) { count += job .getResolvedFiles() .filter((file) => job.emitsArtifacts(file)).length; + + const solcVersion = job.getSolcConfig().version; + const evmTarget = + job.getSolcConfig().settings?.evmVersion ?? + getEvmVersionFromSolcVersion(solcVersion); + + if (evmTarget !== undefined) { + evmVersions.add(evmTarget); + } else { + unknownEvmVersions.add( + `unknown evm version for solc version ${solcVersion}` + ); + } } + const targetVersionsList = Array.from(evmVersions) + // Alphabetically sort evm versions. The unknown ones are added at the end + .sort() + .concat(Array.from(unknownEvmVersions).sort()); + if (count > 0) { console.log( - `Compiled ${count} Solidity ${pluralize(count, "file")} successfully` + `Compiled ${count} Solidity ${pluralize( + count, + "file" + )} successfully (evm ${pluralize( + targetVersionsList.length, + "target", + "targets" + )}: ${targetVersionsList.join(", ")}).` ); } } diff --git a/packages/hardhat-core/src/internal/solidity/compiler/solc-info.ts b/packages/hardhat-core/src/internal/solidity/compiler/solc-info.ts new file mode 100644 index 0000000000..72f39ebac7 --- /dev/null +++ b/packages/hardhat-core/src/internal/solidity/compiler/solc-info.ts @@ -0,0 +1,67 @@ +const defaultEvmTargets: { [key: string]: string } = { + "0.5.1": "byzantium", + "0.5.2": "byzantium", + "0.5.3": "byzantium", + "0.5.4": "byzantium", + "0.5.5": "petersburg", + "0.5.6": "petersburg", + "0.5.7": "petersburg", + "0.5.8": "petersburg", + "0.5.9": "petersburg", + "0.5.10": "petersburg", + "0.5.11": "petersburg", + "0.5.12": "petersburg", + "0.5.13": "petersburg", + "0.5.14": "istanbul", + "0.5.15": "istanbul", + "0.5.16": "istanbul", + "0.5.17": "istanbul", + "0.6.0": "istanbul", + "0.6.1": "istanbul", + "0.6.2": "istanbul", + "0.6.3": "istanbul", + "0.6.4": "istanbul", + "0.6.5": "istanbul", + "0.6.6": "istanbul", + "0.6.7": "istanbul", + "0.6.8": "istanbul", + "0.6.9": "istanbul", + "0.6.10": "istanbul", + "0.6.11": "istanbul", + "0.6.12": "istanbul", + "0.7.0": "istanbul", + "0.7.1": "istanbul", + "0.7.2": "istanbul", + "0.7.3": "istanbul", + "0.7.4": "istanbul", + "0.7.5": "istanbul", + "0.7.6": "istanbul", + "0.8.0": "istanbul", + "0.8.1": "istanbul", + "0.8.2": "istanbul", + "0.8.3": "istanbul", + "0.8.4": "istanbul", + "0.8.5": "berlin", + "0.8.6": "berlin", + "0.8.7": "london", + "0.8.8": "london", + "0.8.9": "london", + "0.8.10": "london", + "0.8.11": "london", + "0.8.12": "london", + "0.8.13": "london", + "0.8.14": "london", + "0.8.15": "london", + "0.8.16": "london", + "0.8.17": "london", + "0.8.18": "paris", + "0.8.19": "paris", + "0.8.20": "shanghai", + "0.8.21": "shanghai", +}; + +export function getEvmVersionFromSolcVersion( + solcVersion: string +): string | undefined { + return defaultEvmTargets[solcVersion]; +} diff --git a/packages/hardhat-core/test/builtin-tasks/compile.ts b/packages/hardhat-core/test/builtin-tasks/compile.ts index ab08b2258c..32e180bdaf 100644 --- a/packages/hardhat-core/test/builtin-tasks/compile.ts +++ b/packages/hardhat-core/test/builtin-tasks/compile.ts @@ -2,7 +2,7 @@ import { assert, expect } from "chai"; import ci from "ci-info"; import * as fsExtra from "fs-extra"; import * as path from "path"; - +import sinon from "sinon"; import { TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOBS_FAILURE_REASONS, TASK_COMPILE_SOLIDITY_READ_FILE, @@ -141,6 +141,25 @@ describe("compile task", function () { }); }); + describe("project with multiple different evm versions", function () { + useFixtureProject("compilation-multiple-files-different-evm-versions"); + useEnvironment(); + + it("should compile and show a message listing all the evm versions used", async function () { + const spyFunctionConsoleLog = sinon.stub(console, "log"); + + await this.env.run("compile"); + + assert( + spyFunctionConsoleLog.calledWith( + "Compiled 4 Solidity files successfully (evm targets: paris, petersburg, shanghai, unknown evm version for solc version 0.4.11)." + ) + ); + + spyFunctionConsoleLog.restore(); + }); + }); + describe("TASK_COMPILE_SOLIDITY_READ_FILE", function () { describe("Import folder", () => { const folderName = "compilation-single-file"; diff --git a/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/.gitignore b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/.gitignore new file mode 100644 index 0000000000..e7f801166c --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/.gitignore @@ -0,0 +1,2 @@ +artifacts/ +cache/ diff --git a/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/A.sol b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/A.sol new file mode 100644 index 0000000000..908062c928 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/A.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.21; + +contract A {} diff --git a/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/B.sol b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/B.sol new file mode 100644 index 0000000000..a326bf8103 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/B.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.20; + +contract B {} diff --git a/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/C.sol b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/C.sol new file mode 100644 index 0000000000..65be83cf9d --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/C.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.4.11; + +contract C {} diff --git a/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/D.sol b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/D.sol new file mode 100644 index 0000000000..b16a6fddbb --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/contracts/D.sol @@ -0,0 +1,4 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.5.5; + +contract D {} diff --git a/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/hardhat.config.js new file mode 100644 index 0000000000..e432b997ba --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-multiple-files-different-evm-versions/hardhat.config.js @@ -0,0 +1,24 @@ +module.exports = { + solidity: { + compilers: [ + { + version: "0.4.11", // Value not present in solc-info.ts file + }, + { + version: "0.5.5", // Value taken from solc-info.ts file + }, + { + version: "0.8.20", + settings: { + evmVersion: "paris", // Overwrite default value in solc-info.ts file + }, + }, + { + version: "0.8.21", + settings: { + evmVersion: "shanghai", // Same as default value in solc-info.ts file + }, + }, + ], + }, +};