Skip to content

Commit

Permalink
Print the evm versions used when compiling (#4414)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherDedominici authored Oct 6, 2023
1 parent 78dd09b commit 03edea6
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-tomatoes-press.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Updated the compilation logs to include the targeted EVM versions.
31 changes: 30 additions & 1 deletion packages/hardhat-core/src/builtin-tasks/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1291,15 +1292,43 @@ subtask(TASK_COMPILE_SOLIDITY_LOG_COMPILATION_RESULT)
.setAction(
async ({ compilationJobs }: { compilationJobs: CompilationJob[] }) => {
let count = 0;
const evmVersions = new Set<string>();
const unknownEvmVersions = new Set<string>();

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(", ")}).`
);
}
}
Expand Down
67 changes: 67 additions & 0 deletions packages/hardhat-core/src/internal/solidity/compiler/solc-info.ts
Original file line number Diff line number Diff line change
@@ -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];
}
21 changes: 20 additions & 1 deletion packages/hardhat-core/test/builtin-tasks/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
artifacts/
cache/
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;

contract A {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.20;

contract B {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.4.11;

contract C {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.5.5;

contract D {}
Original file line number Diff line number Diff line change
@@ -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
},
},
],
},
};

0 comments on commit 03edea6

Please sign in to comment.