diff --git a/lib/core/engine.js b/lib/core/engine.js index efef0f3a..c167b5f8 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -182,7 +182,7 @@ class Engine { compiler.compile_contracts(contractFiles, cb); }); - this.registerModule('solidity'); + this.registerModule('solidity', {useIpc: options.useIpc}); this.registerModule('vyper'); this.registerModule('profiler'); this.registerModule('deploytracker'); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index c0d77188..3bfc7583 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -3,12 +3,13 @@ let SolcW = require('./solcW.js'); class Solidity { - constructor(embark, _options) { + constructor(embark, options) { this.logger = embark.logger; this.events = embark.events; this.contractDirectories = embark.config.contractDirectories; this.solcAlreadyLoaded = false; this.solcW = null; + this.useIpc = options.useIpc; embark.registerCompiler(".sol", this.compile_solidity.bind(this)); } @@ -48,7 +49,7 @@ class Solidity { if (self.solcAlreadyLoaded) { return callback(); } - self.solcW = new SolcW({logger: self.logger, events: self.events}); + self.solcW = new SolcW({logger: self.logger, events: self.events, useIpc: self.useIpc}); self.logger.info(__("loading solc compiler") + ".."); self.solcW.load_compiler(function (err) { diff --git a/lib/modules/solidity/solcW.js b/lib/modules/solidity/solcW.js index f13d2490..95ca8f5c 100644 --- a/lib/modules/solidity/solcW.js +++ b/lib/modules/solidity/solcW.js @@ -3,18 +3,37 @@ let fs = require('../../core/fs.js'); let currentSolcVersion = require('../../../package.json').dependencies.solc; const ProcessLauncher = require('../../process/processLauncher'); const uuid = require('uuid/v1'); +let ipc = require('node-ipc') +let socketPath = "/tmp/embark.sock" class SolcW { constructor(options) { this.logger = options.logger; this.events = options.events; + this.useIpc = options.useIpc; this.compilerLoaded = false; this.solcProcess = null; } load_compiler(done) { const self = this; + if (self.useIpc) { + // try to connect, if it can't then continue + self.compilerLoaded = true; + + ipc.config.silent = true; + + function connecting(socket) { + ipc.of['embark'].on('connect',function() { + done(); + }); + } + + ipc.connectTo('embark', socketPath, connecting); + + return; + } if (this.compilerLoaded) { return done(); } @@ -30,6 +49,23 @@ class SolcW { done(); }); + ipc.config.silent = true; + + function _connecting() { + ipc.server.on( + 'message', + function(data, socket) { + self.compile(data.message, (result) => { + ipc.server.emit(socket, 'message', {action: 'compilation', message: result}); + }); + } + ); + } + + ipc.serve(socketPath, _connecting) + ipc.server.start() + this.logger.info(`pid ${process.pid} listening on ${socketPath}`); + this.events.request("version:get:solc", function(solcVersion) { if (solcVersion === currentSolcVersion) { self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'}); @@ -51,6 +87,18 @@ class SolcW { compile(jsonObj, done) { const id = uuid(); + let a = new Date(); + console.dir("doing compile"); + + if (this.useIpc) { + ipc.of['embark'].once('message', function(msg) { + done(msg.message); + }); + + ipc.of['embark'].emit('message', {action: 'compile', message: jsonObj}); + return; + } + this.solcProcess.once('result', 'compilation-' + id, (msg) => { done(JSON.parse(msg.output)); }); diff --git a/lib/tests/test.js b/lib/tests/test.js index a935327f..d75cddce 100644 --- a/lib/tests/test.js +++ b/lib/tests/test.js @@ -64,7 +64,8 @@ class Test { web3: this.web3 }); this.engine.startService("deployment", { - trackContracts: false + trackContracts: false, + useIpc: true }); this.engine.startService("codeGenerator"); } diff --git a/package.json b/package.json index 6d013652..cd660c0a 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "ipfs-api": "17.2.4", "live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git", "merge": "^1.2.0", + "node-ipc": "^9.1.1", "os-locale": "^2.1.0", "p-iteration": "^1.1.7", "parse-json": "^4.0.0", diff --git a/test_apps/test_app/config/storage.json b/test_apps/test_app/config/storage.json index 2209629d..51677b6c 100644 --- a/test_apps/test_app/config/storage.json +++ b/test_apps/test_app/config/storage.json @@ -3,7 +3,7 @@ "enabled": true, "ipfs_bin": "ipfs", - "available_providers": ["ipfs", "swarm"], + "available_providers": ["ipfs"], "upload": { "provider": "ipfs", @@ -18,13 +18,6 @@ ] }, "development": { - "enabled": true, - "upload": { - "provider": "swarm", - "host": "localhost", - "port": 8500, - "getUrl": "http://localhost:8500/bzzr:/" - } }, "livenet": { "enabled": true,