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 {
@@ -152,21 +155,19 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
152
155
) ,
153
156
) ;
154
157
155
- const runCompilationJobOptions : RunCompilationJobOptions = {
156
- quiet : options ?. quiet ,
157
- } ;
158
158
const results : CompilationResult [ ] = await pMap (
159
159
runnableCompilationJobs ,
160
160
async ( runnableCompilationJob ) => {
161
- const compilerOutput = await this . runCompilationJob (
161
+ const { output , compiler } = await this . runCompilationJob (
162
162
runnableCompilationJob ,
163
- runCompilationJobOptions ,
163
+ options ,
164
164
) ;
165
165
166
166
return {
167
167
compilationJob : runnableCompilationJob ,
168
- compilerOutput,
168
+ compilerOutput : output ,
169
169
cached : false ,
170
+ compiler,
170
171
} ;
171
172
} ,
172
173
{
@@ -301,22 +302,15 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
301
302
readSourceFileFactory ( this . #hooks) ,
302
303
) ;
303
304
304
- const buildProfileName = options ?. buildProfile ?? DEFAULT_BUILD_PROFILE ;
305
-
306
- if ( this . #options. solidityConfig . profiles [ buildProfileName ] === undefined ) {
307
- throw new HardhatError (
308
- HardhatError . ERRORS . CORE . SOLIDITY . BUILD_PROFILE_NOT_FOUND ,
309
- {
310
- buildProfileName,
311
- } ,
312
- ) ;
313
- }
305
+ const { buildProfileName, buildProfile } = this . #getBuildProfile(
306
+ options ?. buildProfile ,
307
+ ) ;
314
308
315
309
log ( `Using build profile ${ buildProfileName } ` ) ;
316
310
317
311
const solcConfigSelector = new SolcConfigSelector (
318
312
buildProfileName ,
319
- this . #options . solidityConfig . profiles [ buildProfileName ] ,
313
+ buildProfile ,
320
314
dependencyGraph ,
321
315
) ;
322
316
@@ -340,15 +334,19 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
340
334
subgraphsWithConfig . push ( [ configOrError , subgraph ] ) ;
341
335
}
342
336
343
- // build version => longVersion map
337
+ // get longVersion and isWasm from the compiler for each version
344
338
const solcVersionToLongVersion = new Map < string , string > ( ) ;
339
+ const versionIsWasm = new Map < string , boolean > ( ) ;
345
340
for ( const [ solcConfig ] of subgraphsWithConfig ) {
346
341
let solcLongVersion = solcVersionToLongVersion . get ( solcConfig . version ) ;
347
342
348
343
if ( solcLongVersion === undefined ) {
349
- const compiler = await getCompiler ( solcConfig . version ) ;
344
+ const compiler = await getCompiler ( solcConfig . version , {
345
+ preferWasm : buildProfile . preferWasm ,
346
+ } ) ;
350
347
solcLongVersion = compiler . longVersion ;
351
348
solcVersionToLongVersion . set ( solcConfig . version , solcLongVersion ) ;
349
+ versionIsWasm . set ( solcConfig . version , compiler . isSolcJs ) ;
352
350
}
353
351
}
354
352
@@ -394,13 +392,20 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
394
392
for ( const [ rootFile , compilationJob ] of indexedIndividualJobs . entries ( ) ) {
395
393
const jobHash = await compilationJob . getBuildId ( ) ;
396
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
+ ) ;
397
401
398
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
399
403
if (
400
404
options ?. force === true ||
401
405
cacheResult === undefined ||
402
406
cacheResult . jobHash !== jobHash ||
403
- cacheResult . isolated !== isolated
407
+ cacheResult . isolated !== isolated ||
408
+ cacheResult . wasm !== isWasm
404
409
) {
405
410
rootFilesToCompile . add ( rootFile ) ;
406
411
continue ;
@@ -506,10 +511,26 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
506
511
return { compilationJobsPerFile, indexedIndividualJobs } ;
507
512
}
508
513
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
+
509
530
public async runCompilationJob (
510
531
runnableCompilationJob : CompilationJob ,
511
532
options ?: RunCompilationJobOptions ,
512
- ) : Promise < CompilerOutput > {
533
+ ) : Promise < RunCompilationJobResult > {
513
534
await this . #downloadConfiguredCompilers( options ?. quiet ) ;
514
535
515
536
let numberOfFiles = 0 ;
@@ -520,8 +541,11 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
520
541
const numberOfRootFiles =
521
542
runnableCompilationJob . dependencyGraph . getRoots ( ) . size ;
522
543
544
+ const { buildProfile } = this . #getBuildProfile( options ?. buildProfile ) ;
545
+
523
546
const compiler = await getCompiler (
524
547
runnableCompilationJob . solcConfig . version ,
548
+ { preferWasm : buildProfile . preferWasm } ,
525
549
) ;
526
550
527
551
log (
@@ -533,7 +557,10 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
533
557
"The long version of the compiler should match the long version of the compilation job" ,
534
558
) ;
535
559
536
- return compiler . compile ( await runnableCompilationJob . getSolcInput ( ) ) ;
560
+ const output = await compiler . compile (
561
+ await runnableCompilationJob . getSolcInput ( ) ,
562
+ ) ;
563
+ return { output, compiler } ;
537
564
}
538
565
539
566
public async remapCompilerError (
@@ -906,6 +933,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
906
933
buildInfoPath : emitArtifactsResult . buildInfoPath ,
907
934
buildInfoOutputPath : emitArtifactsResult . buildInfoOutputPath ,
908
935
typeFilePath,
936
+ wasm : result . compiler . isSolcJs ,
909
937
} ;
910
938
}
911
939
}
0 commit comments