1
1
import type { CompileCache } from "./cache.js" ;
2
+ import type { Compiler } from "./compiler/compiler.js" ;
2
3
import type { DependencyGraphImplementation } from "./dependency-graph.js" ;
3
4
import type { Artifact } from "../../../../types/artifacts.js" ;
4
5
import type { SolcConfig , SolidityConfig } from "../../../../types/config.js" ;
@@ -13,6 +14,7 @@ import type {
13
14
RunCompilationJobOptions ,
14
15
GetCompilationJobsResult ,
15
16
EmitArtifactsResult ,
17
+ RunCompilationJobResult ,
16
18
} from "../../../../types/solidity/build-system.js" ;
17
19
import type { CompilationJob } from "../../../../types/solidity/compilation-job.js" ;
18
20
import type {
@@ -76,6 +78,7 @@ interface CompilationResult {
76
78
compilationJob : CompilationJob ;
77
79
compilerOutput : CompilerOutput ;
78
80
cached : boolean ;
81
+ compiler : Compiler ;
79
82
}
80
83
81
84
export interface SolidityBuildSystemOptions {
@@ -155,15 +158,16 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
155
158
const results : CompilationResult [ ] = await pMap (
156
159
runnableCompilationJobs ,
157
160
async ( runnableCompilationJob ) => {
158
- const compilerOutput = await this . runCompilationJob (
161
+ const { output , compiler } = await this . runCompilationJob (
159
162
runnableCompilationJob ,
160
163
options ,
161
164
) ;
162
165
163
166
return {
164
167
compilationJob : runnableCompilationJob ,
165
- compilerOutput,
168
+ compilerOutput : output ,
166
169
cached : false ,
170
+ compiler,
167
171
} ;
168
172
} ,
169
173
{
@@ -330,17 +334,19 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
330
334
subgraphsWithConfig . push ( [ configOrError , subgraph ] ) ;
331
335
}
332
336
333
- // build version => longVersion map
337
+ // get longVersion and isWasm from the compiler for each version
334
338
const solcVersionToLongVersion = new Map < string , string > ( ) ;
339
+ const versionIsWasm = new Map < string , boolean > ( ) ;
335
340
for ( const [ solcConfig ] of subgraphsWithConfig ) {
336
341
let solcLongVersion = solcVersionToLongVersion . get ( solcConfig . version ) ;
337
342
338
343
if ( solcLongVersion === undefined ) {
339
344
const compiler = await getCompiler ( solcConfig . version , {
340
- preferWasm : false ,
345
+ preferWasm : buildProfile . preferWasm ,
341
346
} ) ;
342
347
solcLongVersion = compiler . longVersion ;
343
348
solcVersionToLongVersion . set ( solcConfig . version , solcLongVersion ) ;
349
+ versionIsWasm . set ( solcConfig . version , compiler . isSolcJs ) ;
344
350
}
345
351
}
346
352
@@ -386,13 +392,20 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
386
392
for ( const [ rootFile , compilationJob ] of indexedIndividualJobs . entries ( ) ) {
387
393
const jobHash = await compilationJob . getBuildId ( ) ;
388
394
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
+ ) ;
389
401
390
402
// If there's no cache for the root file, or the compilation job changed, or using force flag, or isolated mode changed, compile it
391
403
if (
392
404
options ?. force === true ||
393
405
cacheResult === undefined ||
394
406
cacheResult . jobHash !== jobHash ||
395
- cacheResult . isolated !== isolated
407
+ cacheResult . isolated !== isolated ||
408
+ cacheResult . wasm !== isWasm
396
409
) {
397
410
rootFilesToCompile . add ( rootFile ) ;
398
411
continue ;
@@ -517,7 +530,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
517
530
public async runCompilationJob (
518
531
runnableCompilationJob : CompilationJob ,
519
532
options ?: RunCompilationJobOptions ,
520
- ) : Promise < CompilerOutput > {
533
+ ) : Promise < RunCompilationJobResult > {
521
534
await this . #downloadConfiguredCompilers( options ?. quiet ) ;
522
535
523
536
let numberOfFiles = 0 ;
@@ -544,7 +557,10 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
544
557
"The long version of the compiler should match the long version of the compilation job" ,
545
558
) ;
546
559
547
- return compiler . compile ( await runnableCompilationJob . getSolcInput ( ) ) ;
560
+ const output = await compiler . compile (
561
+ await runnableCompilationJob . getSolcInput ( ) ,
562
+ ) ;
563
+ return { output, compiler } ;
548
564
}
549
565
550
566
public async remapCompilerError (
@@ -917,6 +933,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
917
933
buildInfoPath : emitArtifactsResult . buildInfoPath ,
918
934
buildInfoOutputPath : emitArtifactsResult . buildInfoOutputPath ,
919
935
typeFilePath,
936
+ wasm : result . compiler . isSolcJs ,
920
937
} ;
921
938
}
922
939
}
0 commit comments