Skip to content

Commit e08a6f9

Browse files
committed
Add wasm to cache entry, chmod binary on arm64
1 parent 942b0a7 commit e08a6f9

File tree

5 files changed

+38
-9
lines changed

5 files changed

+38
-9
lines changed

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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";
45
import type { SolcConfig, SolidityConfig } from "../../../../types/config.js";
@@ -13,6 +14,7 @@ import type {
1314
RunCompilationJobOptions,
1415
GetCompilationJobsResult,
1516
EmitArtifactsResult,
17+
RunCompilationJobResult,
1618
} from "../../../../types/solidity/build-system.js";
1719
import type { CompilationJob } from "../../../../types/solidity/compilation-job.js";
1820
import type {
@@ -76,6 +78,7 @@ interface CompilationResult {
7678
compilationJob: CompilationJob;
7779
compilerOutput: CompilerOutput;
7880
cached: boolean;
81+
compiler: Compiler;
7982
}
8083

8184
export interface SolidityBuildSystemOptions {
@@ -155,15 +158,16 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
155158
const results: CompilationResult[] = await pMap(
156159
runnableCompilationJobs,
157160
async (runnableCompilationJob) => {
158-
const compilerOutput = await this.runCompilationJob(
161+
const { output, compiler } = await this.runCompilationJob(
159162
runnableCompilationJob,
160163
options,
161164
);
162165

163166
return {
164167
compilationJob: runnableCompilationJob,
165-
compilerOutput,
168+
compilerOutput: output,
166169
cached: false,
170+
compiler,
167171
};
168172
},
169173
{
@@ -330,17 +334,19 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
330334
subgraphsWithConfig.push([configOrError, subgraph]);
331335
}
332336

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

338343
if (solcLongVersion === undefined) {
339344
const compiler = await getCompiler(solcConfig.version, {
340-
preferWasm: false,
345+
preferWasm: buildProfile.preferWasm,
341346
});
342347
solcLongVersion = compiler.longVersion;
343348
solcVersionToLongVersion.set(solcConfig.version, solcLongVersion);
349+
versionIsWasm.set(solcConfig.version, compiler.isSolcJs);
344350
}
345351
}
346352

@@ -386,13 +392,20 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
386392
for (const [rootFile, compilationJob] of indexedIndividualJobs.entries()) {
387393
const jobHash = await compilationJob.getBuildId();
388394
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+
);
389401

390402
// If there's no cache for the root file, or the compilation job changed, or using force flag, or isolated mode changed, compile it
391403
if (
392404
options?.force === true ||
393405
cacheResult === undefined ||
394406
cacheResult.jobHash !== jobHash ||
395-
cacheResult.isolated !== isolated
407+
cacheResult.isolated !== isolated ||
408+
cacheResult.wasm !== isWasm
396409
) {
397410
rootFilesToCompile.add(rootFile);
398411
continue;
@@ -517,7 +530,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
517530
public async runCompilationJob(
518531
runnableCompilationJob: CompilationJob,
519532
options?: RunCompilationJobOptions,
520-
): Promise<CompilerOutput> {
533+
): Promise<RunCompilationJobResult> {
521534
await this.#downloadConfiguredCompilers(options?.quiet);
522535

523536
let numberOfFiles = 0;
@@ -544,7 +557,10 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
544557
"The long version of the compiler should match the long version of the compilation job",
545558
);
546559

547-
return compiler.compile(await runnableCompilationJob.getSolcInput());
560+
const output = await compiler.compile(
561+
await runnableCompilationJob.getSolcInput(),
562+
);
563+
return { output, compiler };
548564
}
549565

550566
public async remapCompilerError(
@@ -917,6 +933,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
917933
buildInfoPath: emitArtifactsResult.buildInfoPath,
918934
buildInfoOutputPath: emitArtifactsResult.buildInfoOutputPath,
919935
typeFilePath,
936+
wasm: result.compiler.isSolcJs,
920937
};
921938
}
922939
}

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/downloader.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ export class CompilerDownloaderImplementation implements CompilerDownloader {
412412

413413
if (
414414
this.#platform === CompilerPlatform.LINUX ||
415+
this.#platform === CompilerPlatform.LINUX_ARM64 ||
415416
this.#platform === CompilerPlatform.MACOS
416417
) {
417418
await chmod(downloadPath, 0o755);

v-next/hardhat/src/internal/builtin-plugins/solidity/hook-handlers/hre.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type {
1111
GetCompilationJobsOptions,
1212
GetCompilationJobsResult,
1313
RunCompilationJobOptions,
14+
RunCompilationJobResult,
1415
SolidityBuildSystem,
1516
} from "../../../../types/solidity/build-system.js";
1617
import type { CompilationJob } from "../../../../types/solidity/compilation-job.js";
@@ -56,7 +57,7 @@ class LazySolidityBuildSystem implements SolidityBuildSystem {
5657
public async runCompilationJob(
5758
compilationJob: CompilationJob,
5859
options?: RunCompilationJobOptions,
59-
): Promise<CompilerOutput> {
60+
): Promise<RunCompilationJobResult> {
6061
const buildSystem = await this.#getBuildSystem();
6162
return buildSystem.runCompilationJob(compilationJob, options);
6263
}

v-next/hardhat/src/types/solidity/build-system.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { CompilationJob } from "./compilation-job.js";
22
import type { CompilerOutput, CompilerOutputError } from "./compiler-io.js";
33
import type { SolidityBuildInfo } from "./solidity-artifacts.js";
4+
import type { Compiler } from "../../internal/builtin-plugins/solidity/build-system/compiler/compiler.js";
45

56
/**
67
* The options of the `build` method.
@@ -175,6 +176,14 @@ export interface EmitArtifactsResult {
175176
buildInfoOutputPath: string;
176177
}
177178

179+
/**
180+
* Result object for the `runCompilationJob` method
181+
*/
182+
export interface RunCompilationJobResult {
183+
output: CompilerOutput;
184+
compiler: Compiler;
185+
}
186+
178187
/**
179188
* The Solidity build system.
180189
*/
@@ -236,7 +245,7 @@ export interface SolidityBuildSystem {
236245
runCompilationJob(
237246
compilationJob: CompilationJob,
238247
options?: RunCompilationJobOptions,
239-
): Promise<CompilerOutput>;
248+
): Promise<RunCompilationJobResult>;
240249

241250
/**
242251
* Remaps the given compiler error paths from input source names to fs paths.

0 commit comments

Comments
 (0)