started bundling worker with esbuild
This commit is contained in:
parent
55735b4039
commit
f3bf1602d5
6
Makefile
6
Makefile
|
@ -4,6 +4,7 @@ TMP=./tmp/dist
|
||||||
|
|
||||||
buildtsc:
|
buildtsc:
|
||||||
$(TSC) tsconfig.json
|
$(TSC) tsconfig.json
|
||||||
|
npm run esbuild
|
||||||
|
|
||||||
prepare: buildtsc
|
prepare: buildtsc
|
||||||
patch -i meta/electron.diff -o electron.html
|
patch -i meta/electron.diff -o electron.html
|
||||||
|
@ -41,13 +42,10 @@ desktop: distro
|
||||||
meta/electron.diff: index.html electron.html
|
meta/electron.diff: index.html electron.html
|
||||||
-diff -u index.html electron.html > $@
|
-diff -u index.html electron.html > $@
|
||||||
|
|
||||||
web:
|
|
||||||
(ip addr || ifconfig) | grep inet
|
|
||||||
python3 scripts/serveit.py 2>> /dev/null #http.out
|
|
||||||
|
|
||||||
tsweb:
|
tsweb:
|
||||||
(ip addr || ifconfig) | grep inet
|
(ip addr || ifconfig) | grep inet
|
||||||
$(TSC) -w &
|
$(TSC) -w &
|
||||||
|
npm run eswatch &
|
||||||
python3 scripts/serveit.py 2>> /dev/null #http.out
|
python3 scripts/serveit.py 2>> /dev/null #http.out
|
||||||
|
|
||||||
astrolibre.b64.txt: astrolibre.rom
|
astrolibre.b64.txt: astrolibre.rom
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
"electron": "^9.4.0",
|
"electron": "^9.4.0",
|
||||||
"electron-builder": "^22.11.7",
|
"electron-builder": "^22.11.7",
|
||||||
"electron-packager": "^15.2.0",
|
"electron-packager": "^15.2.0",
|
||||||
|
"esbuild": "^0.12.16",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"heapdump": "^0.3.15",
|
"heapdump": "^0.3.15",
|
||||||
"jsdom": "^12.2.0",
|
"jsdom": "^12.2.0",
|
||||||
|
@ -3479,6 +3480,16 @@
|
||||||
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
|
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
|
||||||
"devOptional": true
|
"devOptional": true
|
||||||
},
|
},
|
||||||
|
"node_modules/esbuild": {
|
||||||
|
"version": "0.12.16",
|
||||||
|
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.16.tgz",
|
||||||
|
"integrity": "sha512-XqI9cXP2bmQ6MREIqrYBb13KfYFSERsV1+e5jSVWps8dNlLZK+hln7d0mznzDIpfISsg/AgQW0DW3kSInXWhrg==",
|
||||||
|
"dev": true,
|
||||||
|
"hasInstallScript": true,
|
||||||
|
"bin": {
|
||||||
|
"esbuild": "bin/esbuild"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/escalade": {
|
"node_modules/escalade": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
|
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
|
||||||
|
@ -11823,6 +11834,12 @@
|
||||||
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
|
"integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==",
|
||||||
"devOptional": true
|
"devOptional": true
|
||||||
},
|
},
|
||||||
|
"esbuild": {
|
||||||
|
"version": "0.12.16",
|
||||||
|
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.12.16.tgz",
|
||||||
|
"integrity": "sha512-XqI9cXP2bmQ6MREIqrYBb13KfYFSERsV1+e5jSVWps8dNlLZK+hln7d0mznzDIpfISsg/AgQW0DW3kSInXWhrg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"escalade": {
|
"escalade": {
|
||||||
"version": "3.1.1",
|
"version": "3.1.1",
|
||||||
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
|
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
"electron": "^9.4.0",
|
"electron": "^9.4.0",
|
||||||
"electron-builder": "^22.11.7",
|
"electron-builder": "^22.11.7",
|
||||||
"electron-packager": "^15.2.0",
|
"electron-packager": "^15.2.0",
|
||||||
|
"esbuild": "^0.12.16",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
"heapdump": "^0.3.15",
|
"heapdump": "^0.3.15",
|
||||||
"jsdom": "^12.2.0",
|
"jsdom": "^12.2.0",
|
||||||
|
@ -58,6 +59,8 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc --build tsconfig.json",
|
"build": "tsc --build tsconfig.json",
|
||||||
"test": "npm run test-node",
|
"test": "npm run test-node",
|
||||||
|
"esbuild": "esbuild src/worker/workermain.ts --bundle --minify --sourcemap --target=es2020,chrome58,firefox57,safari11 --outfile=./gen/worker/bundle.js --external:binaryen",
|
||||||
|
"eswatch": "npm run esbuild -- --watch",
|
||||||
"test-one": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000",
|
"test-one": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000",
|
||||||
"test-node": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000 test/cli",
|
"test-node": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000 test/cli",
|
||||||
"test-profile": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000 --prof test/cli",
|
"test-profile": "NODE_PATH=$(pwd) mocha --recursive --timeout 60000 --prof test/cli",
|
||||||
|
|
|
@ -7,7 +7,7 @@ import * as localforage from "localforage";
|
||||||
import { CodeProject, LocalForageFilesystem, OverlayFilesystem, ProjectFilesystem, WebPresetsFileSystem } from "./project";
|
import { CodeProject, LocalForageFilesystem, OverlayFilesystem, ProjectFilesystem, WebPresetsFileSystem } from "./project";
|
||||||
import { WorkerResult, WorkerOutput, VerilogOutput, SourceFile, WorkerError, FileData } from "../common/workertypes";
|
import { WorkerResult, WorkerOutput, VerilogOutput, SourceFile, WorkerError, FileData } from "../common/workertypes";
|
||||||
import { ProjectWindows } from "./windows";
|
import { ProjectWindows } from "./windows";
|
||||||
import { Platform, Preset, DebugSymbols, DebugEvalCondition, isDebuggable, EmuState } from "../common/baseplatform";
|
import { Platform, Preset, DebugSymbols, DebugEvalCondition, isDebuggable, EmuState, BasePlatform } from "../common/baseplatform";
|
||||||
import { PLATFORMS, EmuHalt, Toolbar } from "../common/emu";
|
import { PLATFORMS, EmuHalt, Toolbar } from "../common/emu";
|
||||||
import * as Views from "./views";
|
import * as Views from "./views";
|
||||||
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG, stringToByteArray,
|
import { getFilenameForPath, getFilenamePrefix, highlightDifferences, invertMap, byteArrayToString, compressLZG, stringToByteArray,
|
||||||
|
@ -132,7 +132,7 @@ export function loadScript(scriptfn:string) : Promise<Event> {
|
||||||
}
|
}
|
||||||
|
|
||||||
function newWorker() : Worker {
|
function newWorker() : Worker {
|
||||||
return new Worker("./gen/worker/loader.js");
|
return new Worker("./gen/worker/bundle.js");
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasLocalStorage : boolean = function() {
|
const hasLocalStorage : boolean = function() {
|
||||||
|
@ -946,7 +946,11 @@ function _downloadCassetteFile(e) {
|
||||||
alertError("Please fix errors before exporting.");
|
alertError("Please fix errors before exporting.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
var fn = window['_downloadCassetteFile_' + getBasePlatform(platform_id)];
|
var fn;
|
||||||
|
switch (getBasePlatform(platform_id)) {
|
||||||
|
case 'vcs': fn = _downloadCassetteFile_vcs; break;
|
||||||
|
case 'apple2': fn = _downloadCassetteFile_apple2; break;
|
||||||
|
}
|
||||||
if (fn === undefined) {
|
if (fn === undefined) {
|
||||||
alertError("Cassette export is not supported on this platform.");
|
alertError("Cassette export is not supported on this platform.");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -112,7 +112,7 @@ export class Assembler {
|
||||||
codelen = 0;
|
codelen = 0;
|
||||||
aborted = false;
|
aborted = false;
|
||||||
|
|
||||||
constructor(spec : AssemblerSpec) {
|
constructor(spec? : AssemblerSpec) {
|
||||||
this.spec = spec;
|
this.spec = spec;
|
||||||
if (spec) {
|
if (spec) {
|
||||||
this.preprocessRules();
|
this.preprocessRules();
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
|
|
||||||
var exports : any = {};
|
|
||||||
|
|
||||||
declare function importScripts(path:string);
|
|
||||||
|
|
||||||
importScripts("./workermain.js");
|
|
|
@ -1,86 +0,0 @@
|
||||||
|
|
||||||
// TODO: merge with workertestutils
|
|
||||||
|
|
||||||
var assert = require('assert');
|
|
||||||
var fs = require('fs');
|
|
||||||
var vm = require('vm');
|
|
||||||
|
|
||||||
var worker = {};
|
|
||||||
|
|
||||||
global.includeInThisContext = function(path) {
|
|
||||||
var code = fs.readFileSync(path);
|
|
||||||
vm.runInThisContext(code, path);
|
|
||||||
};
|
|
||||||
|
|
||||||
global.importScripts = function(path) {
|
|
||||||
includeInThisContext('./'+path);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Blob(blob) {
|
|
||||||
this.size = blob.length;
|
|
||||||
this.length = blob.length;
|
|
||||||
this.slice = function(a,b) {
|
|
||||||
var data = blob.slice(a,b);
|
|
||||||
var b = new Blob(data);
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
this.asArrayBuffer = function() {
|
|
||||||
var buf = new ArrayBuffer(blob.length);
|
|
||||||
var arr = new Uint8Array(buf);
|
|
||||||
for (var i=0; i<blob.length; i++)
|
|
||||||
arr[i] = blob[i].charCodeAt(0);
|
|
||||||
return arr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
global.XMLHttpRequest = function() {
|
|
||||||
this.open = function(a,b,c) {
|
|
||||||
if (this.responseType == 'json') {
|
|
||||||
var txt = fs.readFileSync('./'+b);
|
|
||||||
this.response = JSON.parse(txt);
|
|
||||||
} else if (this.responseType == 'blob') {
|
|
||||||
var data = fs.readFileSync('./'+b, {encoding:'binary'});
|
|
||||||
this.response = new Blob(data);
|
|
||||||
} else if (this.responseType == 'arraybuffer') {
|
|
||||||
var data = fs.readFileSync('./'+b, {encoding:'binary'});
|
|
||||||
this.response = new Blob(data).asArrayBuffer();
|
|
||||||
} else {
|
|
||||||
throw new Error("responseType " + this.responseType + " not handled");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.send = function() { }
|
|
||||||
}
|
|
||||||
|
|
||||||
global.FileReaderSync = function() {
|
|
||||||
this.readAsArrayBuffer = function(blob) {
|
|
||||||
return blob.asArrayBuffer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
global.onmessage = null;
|
|
||||||
global.postMessage = null;
|
|
||||||
|
|
||||||
includeInThisContext("./workermain.js");
|
|
||||||
|
|
||||||
global.ab2str = function(buf) {
|
|
||||||
return String.fromCharCode.apply(null, new Uint16Array(buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (require.main == module) {
|
|
||||||
var data = fs.readFileSync(process.argv[2]);
|
|
||||||
var msgs = JSON.parse(data);
|
|
||||||
for (var i=0; i<msgs.length; i++) {
|
|
||||||
var result = handleMessage(msgs[i]);
|
|
||||||
//console.log(result);
|
|
||||||
if (result && result.intermediate) {
|
|
||||||
for (var fn in result.intermediate) {
|
|
||||||
console.log("==="+fn);
|
|
||||||
console.log(result.intermediate[fn]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (var fn in workfs) {
|
|
||||||
if (fn.endsWith('.lstxxx'))
|
|
||||||
console.log(workfs[fn].data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,13 +1,15 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import { WorkerResult, WorkerFileUpdate, WorkerBuildStep, WorkerMessage, WorkerError, Dependency, SourceLine, CodeListing, CodeListingMap, Segment, WorkerOutput, SourceLocation } from "../common/workertypes";
|
import type { WorkerResult, WorkerFileUpdate, WorkerBuildStep, WorkerMessage, WorkerError, Dependency, SourceLine, CodeListing, CodeListingMap, Segment, WorkerOutput, SourceLocation } from "../common/workertypes";
|
||||||
|
import { getBasePlatform, getRootBasePlatform, hex } from "../common/util";
|
||||||
|
import { Assembler } from "./assembler";
|
||||||
|
|
||||||
declare function importScripts(path:string);
|
declare function importScripts(path:string);
|
||||||
declare function postMessage(msg);
|
declare function postMessage(msg);
|
||||||
|
|
||||||
const emglobal : any = (this as any)['window'] || (this as any)['global'] || this;
|
|
||||||
const ENVIRONMENT_IS_WEB = typeof window === 'object';
|
const ENVIRONMENT_IS_WEB = typeof window === 'object';
|
||||||
const ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
|
const ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
|
||||||
|
const emglobal : any = ENVIRONMENT_IS_WORKER ? self : ENVIRONMENT_IS_WEB ? window : global;
|
||||||
|
|
||||||
// simple CommonJS module loader
|
// simple CommonJS module loader
|
||||||
// TODO: relative paths for dependencies
|
// TODO: relative paths for dependencies
|
||||||
|
@ -28,8 +30,6 @@ if (!emglobal['require']) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
import { hex } from "../common/util";
|
|
||||||
|
|
||||||
// WebAssembly module cache
|
// WebAssembly module cache
|
||||||
// TODO: leaks memory even when disabled...
|
// TODO: leaks memory even when disabled...
|
||||||
var _WASM_module_cache = {};
|
var _WASM_module_cache = {};
|
||||||
|
@ -70,20 +70,6 @@ function moduleInstFn(module_id:string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get platform ID without . emulator
|
|
||||||
function getBasePlatform(platform : string) : string {
|
|
||||||
return platform.split('.')[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
// get platform ID without - specialization
|
|
||||||
function getRootPlatform(platform : string) : string {
|
|
||||||
return platform.split('-')[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRootBasePlatform(platform : string) : string {
|
|
||||||
return getRootPlatform(getBasePlatform(platform));
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
var PLATFORM_PARAMS = {
|
var PLATFORM_PARAMS = {
|
||||||
|
@ -1676,22 +1662,21 @@ var jsasm_module_output;
|
||||||
var jsasm_module_key;
|
var jsasm_module_key;
|
||||||
|
|
||||||
function compileJSASM(asmcode:string, platform, options, is_inline) {
|
function compileJSASM(asmcode:string, platform, options, is_inline) {
|
||||||
var _assembler = require('./assembler');
|
var asm = new Assembler(null);
|
||||||
var asm = new _assembler.Assembler();
|
|
||||||
var includes = [];
|
var includes = [];
|
||||||
asm.loadJSON = (filename:string) => {
|
asm.loadJSON = (filename:string) => {
|
||||||
var jsontext = getWorkFileAsString(filename);
|
var jsontext = getWorkFileAsString(filename);
|
||||||
if (!jsontext) throw Error("could not load " + filename);
|
if (!jsontext) throw Error("could not load " + filename);
|
||||||
return JSON.parse(jsontext);
|
return JSON.parse(jsontext);
|
||||||
};
|
};
|
||||||
asm.loadInclude = function(filename) {
|
asm.loadInclude = (filename) => {
|
||||||
if (!filename.startsWith('"') || !filename.endsWith('"'))
|
if (!filename.startsWith('"') || !filename.endsWith('"'))
|
||||||
return 'Expected filename in "double quotes"';
|
return 'Expected filename in "double quotes"';
|
||||||
filename = filename.substr(1, filename.length-2);
|
filename = filename.substr(1, filename.length-2);
|
||||||
includes.push(filename);
|
includes.push(filename);
|
||||||
};
|
};
|
||||||
var loaded_module = false;
|
var loaded_module = false;
|
||||||
asm.loadModule = function(top_module) {
|
asm.loadModule = (top_module : string) => {
|
||||||
// compile last file in list
|
// compile last file in list
|
||||||
loaded_module = true;
|
loaded_module = true;
|
||||||
var key = top_module + '/' + includes;
|
var key = top_module + '/' + includes;
|
||||||
|
@ -1705,6 +1690,7 @@ function compileJSASM(asmcode:string, platform, options, is_inline) {
|
||||||
var voutput = compileVerilator({platform:platform, files:includes, path:main_filename, tool:'verilator'});
|
var voutput = compileVerilator({platform:platform, files:includes, path:main_filename, tool:'verilator'});
|
||||||
if (voutput)
|
if (voutput)
|
||||||
jsasm_module_output = voutput;
|
jsasm_module_output = voutput;
|
||||||
|
return null; // no error
|
||||||
}
|
}
|
||||||
var result = asm.assembleFile(asmcode);
|
var result = asm.assembleFile(asmcode);
|
||||||
if (loaded_module && jsasm_module_output) {
|
if (loaded_module && jsasm_module_output) {
|
||||||
|
@ -1715,13 +1701,16 @@ function compileJSASM(asmcode:string, platform, options, is_inline) {
|
||||||
var asmout = result.output;
|
var asmout = result.output;
|
||||||
// TODO: unify
|
// TODO: unify
|
||||||
result.output = jsasm_module_output.output;
|
result.output = jsasm_module_output.output;
|
||||||
result.output.program_rom = asmout;
|
// TODO: typecheck this garbage
|
||||||
|
(result as any).output.program_rom = asmout;
|
||||||
// TODO: not cpu_platform__DOT__program_rom anymore, make const
|
// TODO: not cpu_platform__DOT__program_rom anymore, make const
|
||||||
result.output.program_rom_variable = jsasm_module_top + "$program_rom";
|
(result as any).output.program_rom_variable = jsasm_module_top + "$program_rom";
|
||||||
result.listings = {};
|
(result as any).listings = {};
|
||||||
result.listings[options.path] = {lines:result.lines};
|
(result as any).listings[options.path] = {lines:result.lines};
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function compileJSASMStep(step:BuildStep) {
|
function compileJSASMStep(step:BuildStep) {
|
||||||
|
|
|
@ -72,7 +72,8 @@ global.FileReaderSync = function() {
|
||||||
global.onmessage = null;
|
global.onmessage = null;
|
||||||
global.postMessage = null;
|
global.postMessage = null;
|
||||||
|
|
||||||
includeInThisContext("gen/worker/workermain.js");
|
//includeInThisContext("gen/worker/workermain.js");
|
||||||
|
require('gen/worker/bundle.js')
|
||||||
|
|
||||||
global.ab2str = function(buf) {
|
global.ab2str = function(buf) {
|
||||||
return String.fromCharCode.apply(null, new Uint16Array(buf));
|
return String.fromCharCode.apply(null, new Uint16Array(buf));
|
||||||
|
|
Loading…
Reference in New Issue