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
- import type {
5
- SolcConfig ,
6
- SolidityBuildProfileConfig ,
7
- SolidityConfig ,
8
- } from "../../../../types/config.js" ;
5
+ import type { SolcConfig , SolidityConfig } from "../../../../types/config.js" ;
9
6
import type { HookManager } from "../../../../types/hooks.js" ;
10
7
import type {
11
8
SolidityBuildSystem ,
@@ -17,6 +14,7 @@ import type {
17
14
RunCompilationJobOptions ,
18
15
GetCompilationJobsResult ,
19
16
EmitArtifactsResult ,
17
+ RunCompilationJobResult ,
20
18
} from "../../../../types/solidity/build-system.js" ;
21
19
import type { CompilationJob } from "../../../../types/solidity/compilation-job.js" ;
22
20
import type {
@@ -77,6 +75,7 @@ interface CompilationResult {
77
75
compilationJob : CompilationJob ;
78
76
compilerOutput : CompilerOutput ;
79
77
cached : boolean ;
78
+ compiler : Compiler ;
80
79
}
81
80
82
81
export interface SolidityBuildSystemOptions {
@@ -130,9 +129,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
130
129
await this . #downloadConfiguredCompilers( options ?. quiet ) ;
131
130
132
131
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 ) ;
136
133
137
134
const compilationJobsResult = await this . getCompilationJobs (
138
135
rootFilePaths ,
@@ -158,21 +155,19 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
158
155
) ,
159
156
) ;
160
157
161
- const runCompilationJobOptions : RunCompilationJobOptions = {
162
- quiet : options ?. quiet ,
163
- } ;
164
158
const results : CompilationResult [ ] = await pMap (
165
159
runnableCompilationJobs ,
166
160
async ( runnableCompilationJob ) => {
167
- const compilerOutput = await this . runCompilationJob (
161
+ const { output , compiler } = await this . runCompilationJob (
168
162
runnableCompilationJob ,
169
- runCompilationJobOptions ,
163
+ options ,
170
164
) ;
171
165
172
166
return {
173
167
compilationJob : runnableCompilationJob ,
174
- compilerOutput,
168
+ compilerOutput : output ,
175
169
cached : false ,
170
+ compiler,
176
171
} ;
177
172
} ,
178
173
{
@@ -217,7 +212,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
217
212
indexedIndividualJobs ,
218
213
compilationResult ,
219
214
emitArtifactsResult ,
220
- isolated ,
215
+ buildProfile . isolated ,
221
216
) ;
222
217
} ) ,
223
218
) ;
@@ -305,8 +300,9 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
305
300
readSourceFileFactory ( this . #hooks) ,
306
301
) ;
307
302
308
- const buildProfileName = options ?. buildProfile ?? DEFAULT_BUILD_PROFILE ;
309
- const buildProfile = this . #getBuildProfile( buildProfileName ) ;
303
+ const { buildProfileName, buildProfile } = this . #getBuildProfile(
304
+ options ?. buildProfile ,
305
+ ) ;
310
306
311
307
log ( `Using build profile ${ buildProfileName } ` ) ;
312
308
@@ -336,15 +332,19 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
336
332
subgraphsWithConfig . push ( [ configOrError , subgraph ] ) ;
337
333
}
338
334
339
- // build version => longVersion map
335
+ // get longVersion and isWasm from the compiler for each version
340
336
const solcVersionToLongVersion = new Map < string , string > ( ) ;
337
+ const versionIsWasm = new Map < string , boolean > ( ) ;
341
338
for ( const [ solcConfig ] of subgraphsWithConfig ) {
342
339
let solcLongVersion = solcVersionToLongVersion . get ( solcConfig . version ) ;
343
340
344
341
if ( solcLongVersion === undefined ) {
345
- const compiler = await getCompiler ( solcConfig . version ) ;
342
+ const compiler = await getCompiler ( solcConfig . version , {
343
+ preferWasm : buildProfile . preferWasm ,
344
+ } ) ;
346
345
solcLongVersion = compiler . longVersion ;
347
346
solcVersionToLongVersion . set ( solcConfig . version , solcLongVersion ) ;
347
+ versionIsWasm . set ( solcConfig . version , compiler . isSolcJs ) ;
348
348
}
349
349
}
350
350
@@ -387,18 +387,25 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
387
387
// Select which files to compile
388
388
const rootFilesToCompile : Set < string > = new Set ( ) ;
389
389
390
- const isolated = this . #isIsolated ( buildProfile . isolated , options ?. isolated ) ;
390
+ const isolated = buildProfile . isolated ;
391
391
392
392
for ( const [ rootFile , compilationJob ] of indexedIndividualJobs . entries ( ) ) {
393
393
const jobHash = await compilationJob . getBuildId ( ) ;
394
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
+ ) ;
395
401
396
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
397
403
if (
398
404
options ?. force === true ||
399
405
cacheResult === undefined ||
400
406
cacheResult . jobHash !== jobHash ||
401
- cacheResult . isolated !== isolated
407
+ cacheResult . isolated !== isolated ||
408
+ cacheResult . wasm !== isWasm
402
409
) {
403
410
rootFilesToCompile . add ( rootFile ) ;
404
411
continue ;
@@ -504,10 +511,26 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
504
511
return { compilationJobsPerFile, indexedIndividualJobs } ;
505
512
}
506
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
+
507
530
public async runCompilationJob (
508
531
runnableCompilationJob : CompilationJob ,
509
532
options ?: RunCompilationJobOptions ,
510
- ) : Promise < CompilerOutput > {
533
+ ) : Promise < RunCompilationJobResult > {
511
534
await this . #downloadConfiguredCompilers( options ?. quiet ) ;
512
535
513
536
let numberOfFiles = 0 ;
@@ -518,8 +541,11 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
518
541
const numberOfRootFiles =
519
542
runnableCompilationJob . dependencyGraph . getRoots ( ) . size ;
520
543
544
+ const { buildProfile } = this . #getBuildProfile( options ?. buildProfile ) ;
545
+
521
546
const compiler = await getCompiler (
522
547
runnableCompilationJob . solcConfig . version ,
548
+ { preferWasm : buildProfile . preferWasm } ,
523
549
) ;
524
550
525
551
log (
@@ -531,7 +557,10 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
531
557
"The long version of the compiler should match the long version of the compilation job" ,
532
558
) ;
533
559
534
- return compiler . compile ( await runnableCompilationJob . getSolcInput ( ) ) ;
560
+ const output = await compiler . compile (
561
+ await runnableCompilationJob . getSolcInput ( ) ,
562
+ ) ;
563
+ return { output, compiler } ;
535
564
}
536
565
537
566
public async remapCompilerError (
@@ -815,34 +844,6 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
815
844
this . #downloadedCompilers = true ;
816
845
}
817
846
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
-
846
847
#getAllCompilerVersions( ) : Set < string > {
847
848
return new Set (
848
849
Object . values ( this . #options. solidityConfig . profiles )
@@ -932,6 +933,7 @@ export class SolidityBuildSystemImplementation implements SolidityBuildSystem {
932
933
buildInfoPath : emitArtifactsResult . buildInfoPath ,
933
934
buildInfoOutputPath : emitArtifactsResult . buildInfoOutputPath ,
934
935
typeFilePath,
936
+ wasm : result . compiler . isSolcJs ,
935
937
} ;
936
938
}
937
939
}
0 commit comments