From 2e567aa78ca5574d269701269feae96c42bde6ad Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 27 Jun 2023 09:56:16 +0100 Subject: [PATCH] Compile circuit using editor play button --- .../circuit-compiler/src/app/actions/index.ts | 15 +------- apps/circuit-compiler/src/app/app.tsx | 36 ++++--------------- .../src/app/components/compiler.ts | 30 ++++++++++++++++ .../src/app/services/circomPluginClient.ts | 22 +++++------- .../src/example/simple.circom | 3 +- apps/circuit-compiler/src/profile.json | 4 +-- apps/circuit-compiler/webpack.config.js | 2 ++ .../src/lib/compiler-container.tsx | 8 ----- libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx | 6 +++- pkg/index.js | 0 yarn.lock | 4 +-- 11 files changed, 58 insertions(+), 72 deletions(-) create mode 100644 apps/circuit-compiler/src/app/components/compiler.ts create mode 100644 pkg/index.js diff --git a/apps/circuit-compiler/src/app/actions/index.ts b/apps/circuit-compiler/src/app/actions/index.ts index 8201a298f1..923e24b4ab 100644 --- a/apps/circuit-compiler/src/app/actions/index.ts +++ b/apps/circuit-compiler/src/app/actions/index.ts @@ -1,14 +1 @@ -import { Dispatch } from 'react' -import { CircomPluginClient } from '../services/circomPluginClient' - -const plugin = new CircomPluginClient() - -export const initCircomPluginActions = () => async (dispatch: Dispatch) => { - plugin.internalEvents.on('connectionChanged', (connected: boolean) => { - dispatch({ type: 'SET_REMIXD_CONNECTION_STATUS', payload: connected }) - }) -} - -export function activateRemixd () { - plugin.activateRemixDeamon() -} \ No newline at end of file +import { Dispatch } from 'react' \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/app.tsx b/apps/circuit-compiler/src/app/app.tsx index ef447282d8..fb4c519d94 100644 --- a/apps/circuit-compiler/src/app/app.tsx +++ b/apps/circuit-compiler/src/app/app.tsx @@ -1,21 +1,20 @@ -import React, { useEffect, useReducer } from 'react' +import React, { useEffect, useReducer, useState } from 'react' import { RenderIf, RenderIfNot } from '@remix-ui/helper' import { Alert, Button, Tabs, Tab } from 'react-bootstrap' import { AppContext } from './contexts' import { appInitialState, appReducer } from './reducers' -import { activateRemixd, initCircomPluginActions } from './actions' +import { CircomPluginClient } from './services/circomPluginClient' function App() { const [appState, dispatch] = useReducer(appReducer, appInitialState) + const [plugin, setPlugin] = useState(null) useEffect(() => { - initCircomPluginActions()(dispatch) - }, []) + const plugin = new CircomPluginClient() - const handleConnectRemixd = () => { - activateRemixd() - } + setPlugin(plugin) + }, []) const value = { appState, @@ -25,29 +24,6 @@ function App() { return (
- - - Requirements! -
    -
  1. Circuit Compiler requires that you have Rust lang installed on your machine.
  2. -
  3. Remix-IDE is connected to your local file system.
  4. -
-
- -
-
-
- -
- - - - -
-
) diff --git a/apps/circuit-compiler/src/app/components/compiler.ts b/apps/circuit-compiler/src/app/components/compiler.ts new file mode 100644 index 0000000000..7264a6ade6 --- /dev/null +++ b/apps/circuit-compiler/src/app/components/compiler.ts @@ -0,0 +1,30 @@ +// const compile = () => { +// const currentFile = api.currentFile + +// if (currentFile.endsWith('.circom')) return compileCircuit() +// if (!isSolFileSelected()) return +// _setCompilerVersionFromPragma(currentFile) +// let externalCompType +// if (hhCompilation) externalCompType = 'hardhat' +// else if (truffleCompilation) externalCompType = 'truffle' +// compileTabLogic.runCompiler(externalCompType) +// } + +// const compileAndRun = () => { +// const currentFile = api.currentFile + +// if (currentFile.endsWith('.circom')) return compileCircuit() +// if (!isSolFileSelected()) return +// _setCompilerVersionFromPragma(currentFile) +// let externalCompType +// if (hhCompilation) externalCompType = 'hardhat' +// else if (truffleCompilation) externalCompType = 'truffle' +// api.runScriptAfterCompilation(currentFile) +// compileTabLogic.runCompiler(externalCompType) +// } + +// const compileCircuit = () => { +// const currentFile = api.currentFile + +// console.log('Compiling circuit ' + currentFile) +// } \ No newline at end of file diff --git a/apps/circuit-compiler/src/app/services/circomPluginClient.ts b/apps/circuit-compiler/src/app/services/circomPluginClient.ts index d5bcb1869f..1cc13350b2 100644 --- a/apps/circuit-compiler/src/app/services/circomPluginClient.ts +++ b/apps/circuit-compiler/src/app/services/circomPluginClient.ts @@ -1,5 +1,6 @@ import { PluginClient } from '@remixproject/plugin' import { createClient } from '@remixproject/plugin-webview' +import { parse_circuit_browser } from 'apps/circuit-compiler/pkg/circom' import EventManager from 'events' export class CircomPluginClient extends PluginClient { @@ -10,7 +11,7 @@ export class CircomPluginClient extends PluginClient { super() createClient(this) this.internalEvents = new EventManager() - this.methods = ["sendAsync", "init", "deactivate"] + this.methods = ["init", "compile"] this.onload() } @@ -18,20 +19,13 @@ export class CircomPluginClient extends PluginClient { console.log('initializing circom plugin...') } - onActivation(): void { - this.subscribeToEvents() - } + async compile (path: string) { + console.log('compiling circuit ' + path) + const fileContent = await this.call('fileManager', 'readFile', path) - activateRemixDeamon (): void { - this.call('manager', 'activatePlugin', 'remixd') - } + console.log('file content: ' + fileContent) + const compilationResult = parse_circuit_browser(fileContent, 0) - subscribeToEvents (): void { - this.on('filePanel', 'setWorkspace', (workspace: { name: string, isLocalhost: boolean }) => { - if (this.connected !== workspace.isLocalhost) { - this.connected = workspace.isLocalhost - this.internalEvents.emit('connectionChanged', this.connected) - } - }) + console.log('compilation result: ' + compilationResult) } } diff --git a/apps/circuit-compiler/src/example/simple.circom b/apps/circuit-compiler/src/example/simple.circom index d9432fd9c2..9a2120df7a 100644 --- a/apps/circuit-compiler/src/example/simple.circom +++ b/apps/circuit-compiler/src/example/simple.circom @@ -7,4 +7,5 @@ template Multiplier2() { c <== a*b; } - component main = Multiplier2(); \ No newline at end of file + component main = Multiplier2(); + \ No newline at end of file diff --git a/apps/circuit-compiler/src/profile.json b/apps/circuit-compiler/src/profile.json index 4f54bcee38..4ef16749ed 100644 --- a/apps/circuit-compiler/src/profile.json +++ b/apps/circuit-compiler/src/profile.json @@ -4,8 +4,8 @@ "displayName": "Circuit Compiler", "events": [], "version": "2.0.0", - "methods": ["sendAsync", "init"], - "canActivate": ["remixd"], + "methods": ["init", "compile"], + "canActivate": [], "url": "", "description": "Enables circuit compilation and computing a witness for ZK proofs", "icon": "https://docs.circom.io/assets/images/favicon.png", diff --git a/apps/circuit-compiler/webpack.config.js b/apps/circuit-compiler/webpack.config.js index 51de9dd815..fecff4fa70 100644 --- a/apps/circuit-compiler/webpack.config.js +++ b/apps/circuit-compiler/webpack.config.js @@ -86,5 +86,7 @@ module.exports = composePlugins(withNx(), (config) => { ignored: /node_modules/ } + config.experiments.syncWebAssembly = true + return config; }); 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 757d643df3..1e5c960d5c 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -514,7 +514,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const compile = () => { const currentFile = api.currentFile - if (currentFile.endsWith('.circom')) return compileCircuit() if (!isSolFileSelected()) return _setCompilerVersionFromPragma(currentFile) let externalCompType @@ -526,7 +525,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => { const compileAndRun = () => { const currentFile = api.currentFile - if (currentFile.endsWith('.circom')) return compileCircuit() if (!isSolFileSelected()) return _setCompilerVersionFromPragma(currentFile) let externalCompType @@ -536,12 +534,6 @@ export const CompilerContainer = (props: CompilerContainerProps) => { compileTabLogic.runCompiler(externalCompType) } - const compileCircuit = () => { - const currentFile = api.currentFile - - console.log('Compiling circuit ' + currentFile) - } - const _updateVersionSelector = (version, customUrl = '') => { // update selectedversion of previous one got filtered out let selectedVersion = version diff --git a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx index 95e8adf240..cc5a20129f 100644 --- a/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx +++ b/libs/remix-ui/tabs/src/lib/remix-ui-tabs.tsx @@ -167,7 +167,7 @@ export const TabsUI = (props: TabsUIProps) => {