Skip to content

Commit

Permalink
Add support for revive JS compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
smiasojed committed Jan 24, 2025
1 parent ea53854 commit 9b54d42
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 141 deletions.
232 changes: 97 additions & 135 deletions apps/remix-ide/src/assets/js/soljson.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/remix-solidity/src/compiler/compiler-utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as semver from 'semver'
/* global Worker */

export const baseURLBin = './assets/js'
export const baseURLBin = 'https://remix-backend.polkadot.io/wasm'
export const baseURLWasm = baseURLBin

export const pathToURL = {}
Expand Down
54 changes: 54 additions & 0 deletions libs/remix-solidity/src/compiler/revive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {CompilerInput} from './types'

export default function setupReviveMethods (resolc: any): any {
var compile = function compile(input: CompilerInput, readCallback: (path: string) => { error: string } | undefined): string {
const revive = resolc.createRevive();
revive.soljson = resolc.Module;
revive.writeToStdin(input);
revive.callMain(['--standard-json']);

let result = revive.readFromStdout() || revive.readFromStderr();
let data = JSON.parse(result);
if (data.errors) {
data.errors.forEach((err) => {
if (
err.message &&
(err.message.includes('File not found') || err.message.includes('File not supplied initially'))
) {
// Modify the messages to notify remix that additional sources are needed
err.message = err.message.replace(
/(File not found|File not supplied initially)/,
'Deferred import',
);
err.formattedMessage = err.formattedMessage.replace(
/(File not found|File not supplied initially)/,
'Deferred import',
);
const match = err.message.match(/Source "(.*?)"/);
if (match) {
readCallback(match[1])
}
}
});
}
return JSON.stringify(data)
}

var license = function license(): string {

const revive = resolc.createRevive();
revive.callMain(['--license']);
return revive.readFromStdout() || revive.readFromStderr();
}

var version = function version(): string {
const version = resolc.Module.cwrap("solidity_version", "string", [])()
return version
}

return {
version: version,
license: license,
compile: compile,
}
}
14 changes: 10 additions & 4 deletions libs/remix-solidity/src/lib/es-web-worker/compiler-worker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import setupReviveMethods from './../../compiler/revive'
import setupMethods from 'solc/wrapper'
import { CompilerInput, MessageToWorker } from './../../compiler/types'
let compileJSON: ((input: CompilerInput) => string) | null = (input) => { return '' }
Expand All @@ -9,27 +10,32 @@ self.onmessage = (e: MessageEvent) => {
case 'loadVersion':
{
try {
let compiler;
(self as any).importScripts(data.data)
const compiler = setupMethods(self)
if (typeof (self as any).createRevive === "function") {
compiler = setupReviveMethods(self)
}
else {
compiler = setupMethods(self)
}
compileJSON = (input) => {
try {
const missingInputsCallback = (path) => {
missingInputs.push(path)
return { error: 'Deferred import' }
}
return compiler.compile(input, { import: missingInputsCallback })
return compiler.compile(input, missingInputsCallback)
} catch (exception) {
return JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception })
}
}

self.postMessage({
cmd: 'versionLoaded',
data: compiler.version(),
license: compiler.license()
})
} catch(e) {
throw new Error('Remix initialization failed. Please reload the Remix IDE in your browser.')
throw new Error('Remix initialization failed. Please reload the Remix IDE in your browser.' + e)
}
break
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"description": "Ethereum Remix Monorepo",
"main": "index.js",
"defaultVersion": "soljson-v0.8.28+commit.7893614.Revive-v0.1.0-dev-5.js",
"defaultVersion": "soljson-v0.8.28-js+commit.7893614a-revive-0.1.0-dev.8.js",
"keywords": [
"ethereum",
"solidity",
Expand Down

0 comments on commit 9b54d42

Please sign in to comment.