Skip to content

Commit 9279809

Browse files
committed
Merge branch 'v-next' into isolated
2 parents cc85c59 + 5124992 commit 9279809

File tree

21 files changed

+428
-163
lines changed

21 files changed

+428
-163
lines changed

.changeset/breezy-feet-impress.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"hardhat": patch
3+
---
4+
5+
Print error's `cause` when showing stack traces

.changeset/nine-lies-press.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nomicfoundation/hardhat-utils": patch
3+
"hardhat": patch
4+
---
5+
6+
Add preferWasm flag to config. Default to wasm on production profile. Support linux-aarch64 native compiler ([#5993](https://github.com/NomicFoundation/hardhat/issues/5993))

.changeset/tricky-toys-fetch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"hardhat": patch
33
---
44

5-
Added `isolated` config option to the build profile configuration (https://github.com/NomicFoundation/hardhat/issues/7125)
5+
Added `isolated` config option to the build profile configuration (https://github.com/NomicFoundation/hardhat/issues/7125) and remove the `--isolated` flag.

v-next/hardhat-utils/src/crypto.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { keccak256 as keccak256Impl } from "ethereum-cryptography/keccak";
2+
import { sha256 as sha256Impl } from "ethereum-cryptography/sha256";
23

34
/**
45
* Computes the Keccak-256 hash of the input bytes.
@@ -10,6 +11,16 @@ export async function keccak256(bytes: Uint8Array): Promise<Uint8Array> {
1011
return keccak256Impl(bytes);
1112
}
1213

14+
/**
15+
* Computes the SHA-256 hash of the input bytes.
16+
*
17+
* @param bytes The input bytes to hash.
18+
* @returns The SHA-256 hash of the input bytes.
19+
*/
20+
export async function sha256(bytes: Uint8Array): Promise<Uint8Array> {
21+
return sha256Impl(bytes);
22+
}
23+
1324
/**
1425
* Creates a non-cryptographic hash-based identifier for the given input.
1526
*

v-next/hardhat-verify/test/solc-versions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe("solc-versions", () => {
2929
],
3030
overrides: {},
3131
isolated: false,
32+
preferWasm: false,
3233
};
3334
const expected = ["0.8.18", "0.7.2", "0.4.11"];
3435

@@ -52,6 +53,7 @@ describe("solc-versions", () => {
5253
},
5354
},
5455
isolated: false,
56+
preferWasm: false,
5557
};
5658
const expected = ["0.5.5", "0.6.4"];
5759

@@ -84,6 +86,7 @@ describe("solc-versions", () => {
8486
},
8587
},
8688
isolated: false,
89+
preferWasm: false,
8790
};
8891
const expected = ["0.8.18", "0.7.2", "0.5.5", "0.6.4"];
8992

@@ -108,6 +111,7 @@ describe("solc-versions", () => {
108111
},
109112
},
110113
isolated: false,
114+
preferWasm: false,
111115
};
112116
const expected = ["0.8.18", "0.8.18"];
113117

@@ -136,6 +140,7 @@ describe("solc-versions", () => {
136140
},
137141
},
138142
isolated: false,
143+
preferWasm: false,
139144
};
140145

141146
await assertRejectsWithHardhatError(
@@ -166,6 +171,7 @@ describe("solc-versions", () => {
166171
},
167172
},
168173
isolated: false,
174+
preferWasm: false,
169175
};
170176

171177
await assertRejectsWithHardhatError(

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/build-system.ts

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import type { CompileCache } from "./cache.js";
2+
import type { Compiler } from "./compiler/compiler.js";
23
import type { DependencyGraphImplementation } from "./dependency-graph.js";
34
import type { Artifact } from "../../../../types/artifacts.js";
4-
import type {
5-
SolcConfig,
6-
SolidityBuildProfileConfig,
7-
SolidityConfig,
8-
} from "../../../../types/config.js";
5+
import type { SolcConfig, SolidityConfig } from "../../../../types/config.js";
96
import type { HookManager } from "../../../../types/hooks.js";
107
import type {
118
SolidityBuildSystem,
@@ -17,6 +14,7 @@ import type {
1714
RunCompilationJobOptions,
1815
GetCompilationJobsResult,
1916
EmitArtifactsResult,
17+
RunCompilationJobResult,
2018
} from "../../../../types/solidity/build-system.js";
2119
import type { CompilationJob } from "../../../../types/solidity/compilation-job.js";
2220
import type {
@@ -77,6 +75,7 @@ interface CompilationResult {
7775
compilationJob: CompilationJob;
7876
compilerOutput: CompilerOutput;
7977
cached: boolean;
78+
compiler: Compiler;
8079
}
8180

8281
export interface SolidityBuildSystemOptions {
@@ -130,9 +129,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
130129
await this.#downloadConfiguredCompilers(options?.quiet);
131130

132131
const buildProfileName = options?.buildProfile ?? DEFAULT_BUILD_PROFILE;
133-
const buildProfile = this.#getBuildProfile(buildProfileName);
134-
135-
const isolated = this.#isIsolated(buildProfile.isolated, options?.isolated);
132+
const { buildProfile } = this.#getBuildProfile(buildProfileName);
136133

137134
const compilationJobsResult = await this.getCompilationJobs(
138135
rootFilePaths,
@@ -158,21 +155,19 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
158155
),
159156
);
160157

161-
const runCompilationJobOptions: RunCompilationJobOptions = {
162-
quiet: options?.quiet,
163-
};
164158
const results: CompilationResult[] = await pMap(
165159
runnableCompilationJobs,
166160
async (runnableCompilationJob) => {
167-
const compilerOutput = await this.runCompilationJob(
161+
const { output, compiler } = await this.runCompilationJob(
168162
runnableCompilationJob,
169-
runCompilationJobOptions,
163+
options,
170164
);
171165

172166
return {
173167
compilationJob: runnableCompilationJob,
174-
compilerOutput,
168+
compilerOutput: output,
175169
cached: false,
170+
compiler,
176171
};
177172
},
178173
{
@@ -217,7 +212,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
217212
indexedIndividualJobs,
218213
compilationResult,
219214
emitArtifactsResult,
220-
isolated,
215+
buildProfile.isolated,
221216
);
222217
}),
223218
);
@@ -305,8 +300,9 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
305300
readSourceFileFactory(this.#hooks),
306301
);
307302

308-
const buildProfileName = options?.buildProfile ?? DEFAULT_BUILD_PROFILE;
309-
const buildProfile = this.#getBuildProfile(buildProfileName);
303+
const { buildProfileName, buildProfile } = this.#getBuildProfile(
304+
options?.buildProfile,
305+
);
310306

311307
log(`Using build profile ${buildProfileName}`);
312308

@@ -336,15 +332,19 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
336332
subgraphsWithConfig.push([configOrError, subgraph]);
337333
}
338334

339-
// build version => longVersion map
335+
// get longVersion and isWasm from the compiler for each version
340336
const solcVersionToLongVersion = new Map<string, string>();
337+
const versionIsWasm = new Map<string, boolean>();
341338
for (const [solcConfig] of subgraphsWithConfig) {
342339
let solcLongVersion = solcVersionToLongVersion.get(solcConfig.version);
343340

344341
if (solcLongVersion === undefined) {
345-
const compiler = await getCompiler(solcConfig.version);
342+
const compiler = await getCompiler(solcConfig.version, {
343+
preferWasm: buildProfile.preferWasm,
344+
});
346345
solcLongVersion = compiler.longVersion;
347346
solcVersionToLongVersion.set(solcConfig.version, solcLongVersion);
347+
versionIsWasm.set(solcConfig.version, compiler.isSolcJs);
348348
}
349349
}
350350

@@ -387,18 +387,25 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
387387
// Select which files to compile
388388
const rootFilesToCompile: Set<string> = new Set();
389389

390-
const isolated = this.#isIsolated(buildProfile.isolated, options?.isolated);
390+
const isolated = buildProfile.isolated;
391391

392392
for (const [rootFile, compilationJob] of indexedIndividualJobs.entries()) {
393393
const jobHash = await compilationJob.getBuildId();
394394
const cacheResult = this.#compileCache[rootFile];
395+
const isWasm = versionIsWasm.get(compilationJob.solcConfig.version);
396+
397+
assertHardhatInvariant(
398+
isWasm !== undefined,
399+
`Version ${compilationJob.solcConfig.version} not present in isWasm map`,
400+
);
395401

396402
// If there's no cache for the root file, or the compilation job changed, or using force flag, or isolated mode changed, compile it
397403
if (
398404
options?.force === true ||
399405
cacheResult === undefined ||
400406
cacheResult.jobHash !== jobHash ||
401-
cacheResult.isolated !== isolated
407+
cacheResult.isolated !== isolated ||
408+
cacheResult.wasm !== isWasm
402409
) {
403410
rootFilesToCompile.add(rootFile);
404411
continue;
@@ -504,10 +511,26 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
504511
return { compilationJobsPerFile, indexedIndividualJobs };
505512
}
506513

514+
#getBuildProfile(buildProfileName: string = DEFAULT_BUILD_PROFILE) {
515+
const buildProfile =
516+
this.#options.solidityConfig.profiles[buildProfileName];
517+
518+
if (buildProfile === undefined) {
519+
throw new HardhatError(
520+
HardhatError.ERRORS.CORE.SOLIDITY.BUILD_PROFILE_NOT_FOUND,
521+
{
522+
buildProfileName,
523+
},
524+
);
525+
}
526+
527+
return { buildProfileName, buildProfile };
528+
}
529+
507530
public async runCompilationJob(
508531
runnableCompilationJob: CompilationJob,
509532
options?: RunCompilationJobOptions,
510-
): Promise<CompilerOutput> {
533+
): Promise<RunCompilationJobResult> {
511534
await this.#downloadConfiguredCompilers(options?.quiet);
512535

513536
let numberOfFiles = 0;
@@ -518,8 +541,11 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
518541
const numberOfRootFiles =
519542
runnableCompilationJob.dependencyGraph.getRoots().size;
520543

544+
const { buildProfile } = this.#getBuildProfile(options?.buildProfile);
545+
521546
const compiler = await getCompiler(
522547
runnableCompilationJob.solcConfig.version,
548+
{ preferWasm: buildProfile.preferWasm },
523549
);
524550

525551
log(
@@ -531,7 +557,10 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
531557
"The long version of the compiler should match the long version of the compilation job",
532558
);
533559

534-
return compiler.compile(await runnableCompilationJob.getSolcInput());
560+
const output = await compiler.compile(
561+
await runnableCompilationJob.getSolcInput(),
562+
);
563+
return { output, compiler };
535564
}
536565

537566
public async remapCompilerError(
@@ -815,34 +844,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
815844
this.#downloadedCompilers = true;
816845
}
817846

818-
#getBuildProfile(
819-
buildProfileNameOption?: string,
820-
): SolidityBuildProfileConfig {
821-
const buildProfileName = buildProfileNameOption ?? DEFAULT_BUILD_PROFILE;
822-
const buildProfile =
823-
this.#options.solidityConfig.profiles[buildProfileName];
824-
825-
if (buildProfile === undefined) {
826-
throw new HardhatError(
827-
HardhatError.ERRORS.CORE.SOLIDITY.BUILD_PROFILE_NOT_FOUND,
828-
{
829-
buildProfileName,
830-
},
831-
);
832-
}
833-
834-
return buildProfile;
835-
}
836-
837-
#isIsolated(
838-
isolatedBuildProfile: boolean,
839-
isolatedOption?: boolean,
840-
): boolean {
841-
// NOTE: Run in isolated mode if it has been explicitly requested or the build profile demands it
842-
// TODO: Consider allowing overriding the build profile's isolated mode via options
843-
return isolatedBuildProfile || isolatedOption === true;
844-
}
845-
846847
#getAllCompilerVersions(): Set<string> {
847848
return new Set(
848849
Object.values(this.#options.solidityConfig.profiles)
@@ -932,6 +933,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
932933
buildInfoPath: emitArtifactsResult.buildInfoPath,
933934
buildInfoOutputPath: emitArtifactsResult.buildInfoOutputPath,
934935
typeFilePath,
936+
wasm: result.compiler.isSolcJs,
935937
};
936938
}
937939
}

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/cache.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface CompileCacheEntry {
2121
buildInfoOutputPath: string;
2222
artifactPaths: string[];
2323
typeFilePath: string;
24+
wasm: boolean;
2425
}
2526

2627
const CACHE_FILE_NAME = `compile-cache.json`;

v-next/hardhat/src/internal/builtin-plugins/solidity/build-system/compiler/compiler.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ export class SolcJsCompiler implements Compiler {
137137
const compilerFileUrl = pathToFileURL(this.compilerPath);
138138
// NOTE: The script path passed to a tsx/esm loader is an exception to the
139139
// above rule since the tsx/esm loader doesn't support URLs with a scheme.
140-
if (scriptPath.endsWith(".ts")) {
141-
args.push(scriptPath);
142-
} else {
143-
args.push(scriptFileUrl);
144-
}
140+
args.push(scriptPath);
145141
args.push(compilerFileUrl.href);
146142
} else {
147143
args.push(scriptPath, this.compilerPath);

0 commit comments

Comments
 (0)