Set output directory and compile options

circom-desktop
ioedeveloper 3 months ago
parent 80bb08cd80
commit 5fb32ec438
  1. 32
      apps/circuit-compiler/src/app/services/circomPluginClient.ts
  2. 15
      apps/remixdesktop/src/plugins/circomElectronBasePlugin.ts
  3. 10
      apps/remixdesktop/src/tools/circom.ts

@ -137,8 +137,27 @@ export class CircomPluginClient extends PluginClient {
async compile(path: string, compilationConfig?: CompilationConfig): Promise<void> { async compile(path: string, compilationConfig?: CompilationConfig): Promise<void> {
if (isElectron()) { if (isElectron()) {
this.internalEvents.emit('circuit_compiling_start')
this.emit('statusChanged', { key: 'loading', title: 'Compiling...', type: 'info' })
// @ts-ignore
this.call('terminal', 'log', { type: 'log', value: 'Compiling ' + path })
// @ts-ignore // @ts-ignore
return await this.call('circom', 'compile', path) await this.call('circom', 'run', path, {
prime: this._compilationConfig.prime,
wasm: ""
})
// const fileContent = this.lastParsedFiles[path]
// const searchComponentName = fileContent.match(/component\s+main\s*(?:{[^{}]*})?\s*=\s*([A-Za-z_]\w*)\s*\(.*\)/)
// if (searchComponentName) {
// const componentName = searchComponentName[1]
// const signals = circuitApi.input_signals(componentName)
// this.internalEvents.emit('circuit_compiling_done', signals)
// } else {
this.internalEvents.emit('circuit_compiling_done', [])
this.emit('statusChanged', { key: 'succeed', title: 'circuit compiled successfully', type: 'success' })
// }
} else { } else {
this.internalEvents.emit('circuit_compiling_start') this.internalEvents.emit('circuit_compiling_start')
this.emit('statusChanged', { key: 'loading', title: 'Compiling...', type: 'info' }) this.emit('statusChanged', { key: 'loading', title: 'Compiling...', type: 'info' })
@ -204,8 +223,17 @@ export class CircomPluginClient extends PluginClient {
async generateR1cs (path: string, compilationConfig?: CompilationConfig): Promise<void> { async generateR1cs (path: string, compilationConfig?: CompilationConfig): Promise<void> {
if (isElectron()) { if (isElectron()) {
this.internalEvents.emit('circuit_generating_r1cs_start')
this.emit('statusChanged', { key: 'loading', title: 'Generating...', type: 'info' })
// @ts-ignore // @ts-ignore
return await this.call('circom', 'generateR1cs', path) this.call('terminal', 'log', { type: 'log', value: 'Generating R1CS for ' + path })
// @ts-ignore
await this.call('circom', 'run', path, {
prime: this._compilationConfig.prime,
r1cs: ""
})
this.internalEvents.emit('circuit_generating_r1cs_done')
this.emit('statusChanged', { key: 'succeed', title: 'r1cs generated successfully', type: 'success' })
} else { } else {
const [parseErrors, filePathToId] = await this.parse(path) const [parseErrors, filePathToId] = await this.parse(path)

@ -1,6 +1,6 @@
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron"
import { Profile } from "@remixproject/plugin-utils" import { Profile } from "@remixproject/plugin-utils"
import { circomCli } from "../tools/circom" import { circomCli, extractParentFromKey } from "../tools/circom"
import path from "path" import path from "path"
const profile: Profile = { const profile: Profile = {
@ -22,7 +22,7 @@ const clientProfile: Profile = {
name: 'circom', name: 'circom',
displayName: 'circom', displayName: 'circom',
description: 'Circom Language Compiler', description: 'Circom Language Compiler',
methods: ['parse', 'compile', 'generateR1cs'] methods: ['install', 'run',]
} }
class CircomElectronPluginClient extends ElectronBasePluginClient { class CircomElectronPluginClient extends ElectronBasePluginClient {
@ -41,13 +41,18 @@ class CircomElectronPluginClient extends ElectronBasePluginClient {
} }
} }
async compile(filePath: string) { async run(filePath: string, options: Record<string, string>) {
if (!this.isCircomInstalled) await this.install() if (!this.isCircomInstalled) await this.install()
// @ts-ignore // @ts-ignore
const wd = await this.call('fs', 'getWorkingDir') const wd = await this.call('fs', 'getWorkingDir')
// @ts-ignore
const outputDirExists = await this.call('fs', 'exists', extractParentFromKey(filePath) + '/.bin')
// @ts-ignore
if (!outputDirExists) await this.call('fs', 'mkdir', extractParentFromKey(filePath) + '/.bin')
filePath = path.join(wd, filePath)
const depPath = path.join(wd, '.deps/https/raw.githubusercontent.com/iden3/') const depPath = path.join(wd, '.deps/https/raw.githubusercontent.com/iden3/')
const outputDir = extractParentFromKey(filePath) + '/.bin'
filePath = path.join(wd, filePath) await circomCli.run(`${filePath} -l ${depPath} -o ${outputDir}`, options)
await circomCli.run(`${filePath} -l ${depPath}`)
} }
} }

@ -84,9 +84,19 @@ export const circomCli = {
async run (filePath: string, options?: Record<string, string>) { async run (filePath: string, options?: Record<string, string>) {
const cmd = `${CIRCOM_INSTALLATION_PATH} ${filePath} ${Object.keys(options || {}).map((key) => `--${key} ${options[key]}`).join(' ')}` const cmd = `${CIRCOM_INSTALLATION_PATH} ${filePath} ${Object.keys(options || {}).map((key) => `--${key} ${options[key]}`).join(' ')}`
console.log('cmd: ', cmd)
const { stdout, stderr } = await execAsync(cmd) const { stdout, stderr } = await execAsync(cmd)
if (stderr) return console.error(stderr) if (stderr) return console.error(stderr)
console.log(stdout) console.log(stdout)
} }
} }
export const extractParentFromKey = (key: string):string => {
if (!key) return
const keyPath = key.split('/')
keyPath.pop()
return keyPath.join('/')
}
Loading…
Cancel
Save