From 3d739cc438586240448302fce804ceff3366b9ad Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Thu, 9 Nov 2023 21:20:49 +0530 Subject: [PATCH 1/4] consider remappings while compilation --- libs/remix-solidity/src/compiler/compiler-input.ts | 3 ++- libs/remix-solidity/src/compiler/compiler.ts | 11 ++++++----- libs/remix-solidity/src/compiler/types.ts | 4 +++- .../solidity-compiler/src/lib/compiler-container.tsx | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/libs/remix-solidity/src/compiler/compiler-input.ts b/libs/remix-solidity/src/compiler/compiler-input.ts index 8598c9dfd4..61c8ece472 100644 --- a/libs/remix-solidity/src/compiler/compiler-input.ts +++ b/libs/remix-solidity/src/compiler/compiler-input.ts @@ -17,7 +17,8 @@ export default (sources: Source, opts: CompilerInputOptions): string => { '': ['ast'], '*': ['abi', 'metadata', 'devdoc', 'userdoc', 'storageLayout', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates', 'evm.assembly'] } - } + }, + remappings: opts.remappings || [] } } if (opts.evmVersion) { diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index 2e20b0c857..b2567ea4d5 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -32,6 +32,7 @@ export class Compiler { runs: 200, evmVersion: null, language: 'Solidity', + remappings: [], compilationStartTime: null, target: null, useFileConfiguration: false, @@ -213,12 +214,12 @@ export class Compiler { let input = "" try { if (source && source.sources) { - const { optimize, runs, evmVersion, language, useFileConfiguration, configFileContent } = this.state - + const { optimize, runs, evmVersion, language, remappings, useFileConfiguration, configFileContent } = this.state + console.log('remappings---->', remappings) if (useFileConfiguration) { input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent)) } else { - input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) + input = compilerInput(source.sources, { optimize, runs, evmVersion, language, remappings }) } result = JSON.parse(remoteCompiler.compile(input, { import: missingInputsCallback })) @@ -331,7 +332,7 @@ export class Compiler { this.state.compileJSON = (source: SourceWithTarget, timeStamp: number) => { if (source && source.sources) { - const { optimize, runs, evmVersion, language, useFileConfiguration, configFileContent } = this.state + const { optimize, runs, evmVersion, language, remappings, useFileConfiguration, configFileContent } = this.state jobs.push({ sources: source }) let input = "" @@ -339,7 +340,7 @@ export class Compiler { if (useFileConfiguration) { input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent)) } else { - input = compilerInput(source.sources, { optimize, runs, evmVersion, language }) + input = compilerInput(source.sources, { optimize, runs, evmVersion, language, remappings }) } } catch (exception) { this.onCompilationFinished({ error: { formattedMessage: exception.message } }, [], source, "", this.state.currentVersion) diff --git a/libs/remix-solidity/src/compiler/types.ts b/libs/remix-solidity/src/compiler/types.ts index d86e7b0b74..6a6a74e7ce 100644 --- a/libs/remix-solidity/src/compiler/types.ts +++ b/libs/remix-solidity/src/compiler/types.ts @@ -147,7 +147,8 @@ export interface CompilerInputOptions { [fileName: string]: Record }, evmVersion?: EVMVersion, - language?: Language + language?: Language, + remappings?: string[] } export type EVMVersion = 'homestead' | 'tangerineWhistle' | 'spuriousDragon' | 'byzantium' | 'constantinople' | 'petersburg' | 'istanbul' | 'berlin' | 'london' | 'paris' | null @@ -168,6 +169,7 @@ export interface CompilerState { runs: number evmVersion: EVMVersion| null, language: Language, + remappings: string[] compilationStartTime: number| null, target: string | null, useFileConfiguration: boolean, diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 579e1d7a40..8b464838e0 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -59,6 +59,7 @@ export const CompilerContainer = (props: CompilerContainerProps) => { compiledFileName: '', includeNightlies: false, language: 'Solidity', + remappings: [], evmVersion: '', createFileOnce: true }) From 5e8614e048032a14e0dc5689b1ef605e4add4330 Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 10 Nov 2023 12:30:24 +0530 Subject: [PATCH 2/4] consider remappings from file --- .../solidity-compiler/src/lib/logic/compileTabLogic.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts index 9f36b48e9c..e6e7beb0a5 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts @@ -106,10 +106,15 @@ export class CompileTabLogic { compileFile (target) { if (!target) throw new Error('No target provided for compiliation') return new Promise((resolve, reject) => { - this.api.readFile(target).then((content) => { + this.api.readFile(target).then(async(content) => { const sources = { [target]: { content } } this.event.emit('removeAnnotations') this.event.emit('startingCompilation') + if(!this.useFileConfiguration && await this.api.fileExists('remappings.txt')) { + this.api.readFile('remappings.txt').then( remappings => { + this.compiler.set('remappings', remappings.split('\n')) + }) + } if (this.configFilePath) { this.api.readFile(this.configFilePath).then( contentConfig => { this.compiler.set('configFileContent', contentConfig) From 38feabf5f2792fd0f21678b9eea369e38e70380b Mon Sep 17 00:00:00 2001 From: aniket-engg Date: Fri, 10 Nov 2023 22:02:03 +0530 Subject: [PATCH 3/4] consider remappings for use config file option too --- libs/remix-solidity/src/compiler/compiler.ts | 6 ++++-- .../solidity-compiler/src/lib/logic/compileTabLogic.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index b2567ea4d5..7c1c5fa1e3 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -215,7 +215,6 @@ export class Compiler { try { if (source && source.sources) { const { optimize, runs, evmVersion, language, remappings, useFileConfiguration, configFileContent } = this.state - console.log('remappings---->', remappings) if (useFileConfiguration) { input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent)) } else { @@ -338,7 +337,10 @@ export class Compiler { try { if (useFileConfiguration) { - input = compilerInputForConfigFile(source.sources, JSON.parse(configFileContent)) + let compilerInput = JSON.parse(configFileContent) + if (compilerInput.settings.remappings?.length) compilerInput.settings.remappings.push(...remappings) + else compilerInput.settings.remappings = remappings + input = compilerInputForConfigFile(source.sources, compilerInput) } else { input = compilerInput(source.sources, { optimize, runs, evmVersion, language, remappings }) } diff --git a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts index e6e7beb0a5..941296597e 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/logic/compileTabLogic.ts @@ -110,7 +110,7 @@ export class CompileTabLogic { const sources = { [target]: { content } } this.event.emit('removeAnnotations') this.event.emit('startingCompilation') - if(!this.useFileConfiguration && await this.api.fileExists('remappings.txt')) { + if(await this.api.fileExists('remappings.txt')) { this.api.readFile('remappings.txt').then( remappings => { this.compiler.set('remappings', remappings.split('\n')) }) From c9b99c838fa651995bcc90700e20d4184cb0b4d2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 10 Nov 2023 21:33:17 +0100 Subject: [PATCH 4/4] linting --- libs/remix-solidity/src/compiler/compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index 7c1c5fa1e3..a99154c08a 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -337,7 +337,7 @@ export class Compiler { try { if (useFileConfiguration) { - let compilerInput = JSON.parse(configFileContent) + const compilerInput = JSON.parse(configFileContent) if (compilerInput.settings.remappings?.length) compilerInput.settings.remappings.push(...remappings) else compilerInput.settings.remappings = remappings input = compilerInputForConfigFile(source.sources, compilerInput)