Skip to content

Commit

Permalink
Resolve dependecy directory for circom compilation in desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
ioedeveloper committed Aug 29, 2024
1 parent 9b87647 commit 91f66ec
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 75 deletions.
131 changes: 67 additions & 64 deletions apps/circuit-compiler/src/app/services/circomPluginClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,81 +59,76 @@ export class CircomPluginClient extends PluginClient {
}

async parse(path: string, fileContent?: string): Promise<[CompilerReport[], Record<string, string>]> {
if (isElectron()) {
if (!fileContent) {
// @ts-ignore
return await this.call('circom', 'parse', path)
} else {
if (!fileContent) {
// @ts-ignore
fileContent = await this.call('fileManager', 'readFile', path)
}
this.lastParsedFiles = await this.resolveDependencies(path, fileContent)
const parsedOutput = this.compiler ? this.compiler.parse(path, this.lastParsedFiles) : parse(path, this.lastParsedFiles)
fileContent = await this.call('fileManager', 'readFile', path)
}
this.lastParsedFiles = await this.resolveDependencies(path, fileContent)
const parsedOutput = this.compiler ? this.compiler.parse(path, this.lastParsedFiles) : parse(path, this.lastParsedFiles)

try {
const result: CompilerReport[] = JSON.parse(parsedOutput.report())
const mapReportFilePathToId: Record<string, string> = {}
try {
const result: CompilerReport[] = JSON.parse(parsedOutput.report())
const mapReportFilePathToId: Record<string, string> = {}

if (result.length === 0) {
// @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path])
} else {
const markers = []
if (result.length === 0) {
// @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path])
} else {
const markers = []

for (const report of result) {
for (const label in report.labels) {
const file_id = report.labels[label].file_id
for (const report of result) {
for (const label in report.labels) {
const file_id = report.labels[label].file_id

mapReportFilePathToId[file_id] = parsedOutput.get_report_name(parseInt(file_id))
if (file_id === '0') {
mapReportFilePathToId[file_id] = parsedOutput.get_report_name(parseInt(file_id))
if (file_id === '0') {
// @ts-ignore
const startPosition: { lineNumber: number; column: number } = await this.call(
'editor',
// @ts-ignore
const startPosition: { lineNumber: number; column: number } = await this.call(
'editor',
// @ts-ignore
'getPositionAt',
report.labels[label].range.start
)
'getPositionAt',
report.labels[label].range.start
)
// @ts-ignore
const endPosition: { lineNumber: number; column: number } = await this.call(
'editor',
// @ts-ignore
const endPosition: { lineNumber: number; column: number } = await this.call(
'editor',
// @ts-ignore
'getPositionAt',
report.labels[label].range.end
)

markers.push({
message: report.message,
severity: report.type.toLowerCase(),
position: {
start: {
line: startPosition.lineNumber,
column: startPosition.column,
},
end: {
line: endPosition.lineNumber,
column: endPosition.column,
},
'getPositionAt',
report.labels[label].range.end
)

markers.push({
message: report.message,
severity: report.type.toLowerCase(),
position: {
start: {
line: startPosition.lineNumber,
column: startPosition.column,
},
file: path,
})
}
end: {
line: endPosition.lineNumber,
column: endPosition.column,
},
},
file: path,
})
}
}

if (markers.length > 0) {
// @ts-ignore
await this.call('editor', 'addErrorMarker', markers)
} else {
// @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path])
this.emit('statusChanged', { key: 'none' })
}
}

return [result, mapReportFilePathToId]
} catch (e) {
throw new Error(e)
if (markers.length > 0) {
// @ts-ignore
await this.call('editor', 'addErrorMarker', markers)
} else {
// @ts-ignore
await this.call('editor', 'clearErrorMarkers', [path])
this.emit('statusChanged', { key: 'none' })
}
}

return [result, mapReportFilePathToId]
} catch (e) {
throw new Error(e)
}
}

Expand Down Expand Up @@ -320,7 +315,7 @@ export class CircomPluginClient extends PluginClient {
path = `.deps/https/raw.githubusercontent.com/iden3/circomlib/${version[0]}/${splitInclude.slice(2).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
} else {
path = `.deps/https/raw.githubusercontent.com/iden3/circomlib/master/${splitInclude.slice(1).join('/')}`
path = `.deps/https/raw.githubusercontent.com/iden3/circomlib/${splitInclude.slice(1).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
}
} catch (e) {
Expand All @@ -330,7 +325,15 @@ export class CircomPluginClient extends PluginClient {
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
} else {
path = `https://raw.githubusercontent.com/iden3/circomlib/master/${splitInclude.slice(1).join('/')}`
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
const { content } = await this.call('contentImport', 'resolve', path)

if (content) {
dependencyContent = await this.call('contentImport', 'resolveAndSave', path, null)
const savePath = `.deps/https/raw.githubusercontent.com/iden3/${include}`

// @ts-ignore
await this.call('fileManager', 'writeFile', savePath, dependencyContent)
}
}
}
} else {
Expand Down
13 changes: 3 additions & 10 deletions apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,9 @@ class CircomElectronPluginClient extends ElectronBasePluginClient {
if (!this.isCircomInstalled) await this.install()
// @ts-ignore
const wd = await this.call('fs', 'getWorkingDir')
filePath = path.join(wd, filePath)
console.log('Running circom compilation for ', filePath)
await circomCli.run(filePath)
}
const depPath = path.join(wd, '.deps/https/raw.githubusercontent.com/iden3/')

parse(): void {
console.log('parsing circom electron plugin...')
}

generateR1cs(): void {
console.log('generating r1cs circom electron plugin...')
filePath = path.join(wd, filePath)
await circomCli.run(`${filePath} -l ${depPath}`)
}
}
2 changes: 1 addition & 1 deletion apps/remixdesktop/src/tools/circom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function downloadFile(url: string, dest: string) {
return new Promise((resolve, reject) => {
writer.on('finish', () => {
if (process.platform !== 'win32') {
// Make the file executable
// Sets permission to make the file executable
fs.chmod(dest, 0o755, (err) => {
if (err) {
reject(`Error making file executable: ${err}`)
Expand Down

0 comments on commit 91f66ec

Please sign in to comment.