parent
1a5686e33c
commit
7b3c51f661
@ -0,0 +1,12 @@ |
||||
import { ElectronPlugin } from '@remixproject/engine-electron' |
||||
|
||||
export class circomPlugin extends ElectronPlugin { |
||||
constructor() { |
||||
super({ |
||||
displayName: 'circom', |
||||
name: 'circom', |
||||
description: 'circom language compiler', |
||||
}) |
||||
this.methods = [] |
||||
} |
||||
} |
@ -0,0 +1,52 @@ |
||||
import { ElectronBasePlugin, ElectronBasePluginClient } from "@remixproject/plugin-electron" |
||||
import { Profile } from "@remixproject/plugin-utils" |
||||
import { circomCli } from "../tools/circom" |
||||
|
||||
const profile: Profile = { |
||||
displayName: 'circom', |
||||
name: 'circom', |
||||
description: 'Circom language compiler' |
||||
} |
||||
|
||||
export class CircomElectronPlugin extends ElectronBasePlugin { |
||||
clients: CircomElectronPluginClient[] = [] |
||||
|
||||
constructor() { |
||||
super(profile, clientProfile, CircomElectronPluginClient) |
||||
this.methods = [...super.methods] |
||||
} |
||||
|
||||
async onActivation(): Promise<void> { |
||||
console.log('activating to exec') |
||||
if (!(await circomCli.isCargoInstalled())) await circomCli.installRustup() |
||||
if (!(await circomCli.isCircomInstalled())) await circomCli.installCircom() |
||||
} |
||||
} |
||||
|
||||
const clientProfile: Profile = { |
||||
name: 'circom', |
||||
displayName: 'circom', |
||||
description: 'Circom Language Compiler', |
||||
methods: ['parse', 'compile', 'generateR1cs'] |
||||
} |
||||
|
||||
class CircomElectronPluginClient extends ElectronBasePluginClient { |
||||
circomIsInstalled: boolean = false |
||||
|
||||
constructor(webContentsId: number, profile: Profile) { |
||||
super(webContentsId, profile) |
||||
this.onload() |
||||
} |
||||
|
||||
async compile() { |
||||
console.log('compiling circom circuit...') |
||||
} |
||||
|
||||
parse(): void { |
||||
console.log('parsing circom electron plugin...') |
||||
} |
||||
|
||||
generateR1cs(): void { |
||||
console.log('generating r1cs circom electron plugin...') |
||||
} |
||||
} |
@ -0,0 +1,55 @@ |
||||
import { app } from 'electron' |
||||
import { promisify } from 'util' |
||||
import { exec } from 'child_process' |
||||
import { gitProxy } from './git' |
||||
import path from 'path' |
||||
import { existsSync } from 'fs' |
||||
|
||||
const execAsync = promisify(exec) |
||||
|
||||
export const circomCli = { |
||||
async installRustup () { |
||||
try { |
||||
console.log('installing rustup') |
||||
const { stdout } = await execAsync(`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y`) |
||||
|
||||
console.log('stdout: ', stdout) |
||||
} catch (e) { |
||||
console.error(e) |
||||
} |
||||
}, |
||||
|
||||
async installCircom () { |
||||
try { |
||||
const appPath = app.getAppPath() |
||||
const targetPath = path.join(appPath, 'bin') |
||||
|
||||
console.log('cloning circom repo to ' + targetPath) |
||||
if (!existsSync(`${targetPath}/circom`)) await gitProxy.clone('https://github.com/iden3/circom.git', targetPath) |
||||
console.log('builing circom with cargo') |
||||
await execAsync(`cd ${targetPath}/circom && cargo build --release && cargo install --path circom`) |
||||
} catch (e) { |
||||
console.error(e) |
||||
} |
||||
}, |
||||
|
||||
async isCircomInstalled () { |
||||
try { |
||||
await execAsync(`circom --version`) |
||||
|
||||
return true |
||||
} catch (e) { |
||||
return false |
||||
} |
||||
}, |
||||
|
||||
async isCargoInstalled () { |
||||
try { |
||||
await execAsync(`cargo version`) |
||||
|
||||
return true |
||||
} catch (e) { |
||||
return false |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue