mirror of
https://github.com/speice-io/isomorphic-rust
synced 2024-11-16 21:18:25 -05:00
Remove old binaryen/percy projects
This commit is contained in:
parent
b3b81c2ee5
commit
5b210b3fdf
@ -1,5 +1,10 @@
|
||||
# Electron applications in Rust
|
||||
|
||||
Each app is a starter example, and can be run with `yarn install && yarn start`.
|
||||
It's 2020, and a lot has changed.
|
||||
|
||||
`stdweb` and `yew` examples currently don't run.
|
||||
- With the advent of Webpack 5, the previous issues with using WASM in Electron have been vanquished. I can only assume some form of sorcery was involved. All examples have been updated to use the new version.
|
||||
- `wasm32-unknown-unknown` targets are enabled for stable Rust
|
||||
- The previous [`percy`](https://github.com/chinedufn/percy) example has been removed. While work continues on the project, there haven't been any releases.
|
||||
- A new framework [`seed`](https://github.com/seed-rs/seed) as been added as an example.
|
||||
|
||||
Each app is a starter example, and can be run with `yarn install && yarn start`.
|
@ -1,42 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"development": {
|
||||
"application/javascript": {
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"electron": 2
|
||||
}
|
||||
}
|
||||
],
|
||||
"react"
|
||||
],
|
||||
"plugins": [
|
||||
"transform-async-to-generator"
|
||||
],
|
||||
"sourceMaps": "inline"
|
||||
}
|
||||
},
|
||||
"production": {
|
||||
"application/javascript": {
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"electron": 2
|
||||
}
|
||||
}
|
||||
],
|
||||
"react"
|
||||
],
|
||||
"plugins": [
|
||||
"transform-async-to-generator"
|
||||
],
|
||||
"sourceMaps": "none"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "eslint-config-airbnb",
|
||||
"rules": {
|
||||
"import/extensions": 0,
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"import/no-unresolved": [2, { "ignore": ["electron"] }],
|
||||
"linebreak-style": 0
|
||||
}
|
||||
}
|
5
binaryen/.gitignore
vendored
5
binaryen/.gitignore
vendored
@ -1,5 +0,0 @@
|
||||
node_modules/
|
||||
Cargo.lock
|
||||
target/
|
||||
dist/
|
||||
binaryen/
|
@ -1,15 +0,0 @@
|
||||
[package]
|
||||
authors = ["Bradlee Speice"]
|
||||
categories = ["wasm"]
|
||||
description = "A no-framework WASM Electron app"
|
||||
license = "Apache-2.0/MIT"
|
||||
name = "stdweb_electron"
|
||||
readme = "./README.md"
|
||||
repository = "https://github.com/rustwasm/rust-webpack-template"
|
||||
version = "0.1.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
stdweb = "0.4"
|
@ -1,27 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
DIR="$(dirname $0)"
|
||||
WASM_DIR="$DIR/target/wasm32-unknown-unknown"
|
||||
WASM_NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')"
|
||||
APP_DIR="$DIR/dist/"
|
||||
|
||||
if [ ! -f "$DIR/binaryen/bin/wasm2js" ]; then
|
||||
git clone "https://github.com/WebAssembly/binaryen" "$DIR/binaryen"
|
||||
pushd "$DIR/binaryen"
|
||||
cmake . && make -j8
|
||||
popd
|
||||
fi
|
||||
|
||||
if [ ! -d "$APP_DIR" ]; then
|
||||
mkdir "$APP_DIR"
|
||||
fi
|
||||
cp "$DIR/static/"* "$APP_DIR"
|
||||
|
||||
if [ -z "$(which cargo)" ]; then
|
||||
echo 'Must install `cargo` before proceeding. Please see https://rustup.rs/ for more information.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cargo +nightly build --target=wasm32-unknown-unknown && \
|
||||
"$DIR/binaryen/bin/wasm2js" --pedantic "$WASM_DIR/debug/stdweb_electron.wasm" -o "$APP_DIR/stdweb_electron.js" && \
|
||||
"$DIR/node_modules/webpack-cli/bin/cli.js" --mode=development "$APP_DIR/stdweb_electron.js" -o "$APP_DIR/bundle.js"
|
@ -1,66 +0,0 @@
|
||||
{
|
||||
"name": "electron_percy_wasm",
|
||||
"productName": "electron_percy_wasm",
|
||||
"version": "1.0.0",
|
||||
"description": "My Electron application description",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"prestart": "./build.sh",
|
||||
"start": "electron-forge start",
|
||||
"package": "electron-forge package",
|
||||
"make": "electron-forge make",
|
||||
"lint": "eslint src"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "bspeice",
|
||||
"license": "MIT",
|
||||
"config": {
|
||||
"forge": {
|
||||
"make_targets": {
|
||||
"win32": [
|
||||
"squirrel"
|
||||
],
|
||||
"darwin": [
|
||||
"zip"
|
||||
],
|
||||
"linux": [
|
||||
"deb",
|
||||
"rpm"
|
||||
]
|
||||
},
|
||||
"electronPackagerConfig": {
|
||||
"packageManager": "yarn"
|
||||
},
|
||||
"electronWinstallerConfig": {
|
||||
"name": "electron_percy_wasm"
|
||||
},
|
||||
"electronInstallerDebian": {},
|
||||
"electronInstallerRedhat": {},
|
||||
"github_repository": {
|
||||
"owner": "",
|
||||
"name": ""
|
||||
},
|
||||
"windowsStoreConfig": {
|
||||
"packageName": "",
|
||||
"name": "electron_percy_wasm"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-compile": "^6.4.3",
|
||||
"webpack": "^4.17.1",
|
||||
"webpack-cli": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-plugin-transform-async-to-generator": "^6.24.1",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"electron-forge": "^5.2.2",
|
||||
"electron-prebuilt-compile": "2.0.7",
|
||||
"eslint": "^3",
|
||||
"eslint-config-airbnb": "^15",
|
||||
"eslint-plugin-import": "^2",
|
||||
"eslint-plugin-jsx-a11y": "^5",
|
||||
"eslint-plugin-react": "^7"
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
extern crate stdweb;
|
||||
|
||||
use stdweb::web::document;
|
||||
use stdweb::web::INode;
|
||||
use stdweb::web::IElement;
|
||||
|
||||
pub fn run() {
|
||||
stdweb::initialize();
|
||||
|
||||
let doc = document();
|
||||
let val = doc.create_element("p").unwrap();
|
||||
val.set_attribute("innerHTML", "IT IS ALIVE").unwrap();
|
||||
doc.body().unwrap().append_child(&val);
|
||||
|
||||
stdweb::event_loop();
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
const app = import("./stdweb_electron")
|
||||
app.then(module => {
|
||||
console.log("Finished resolving application bundle")
|
||||
module.run()
|
||||
}, (e) => {
|
||||
console.log("Unable to resolve application bundle: ")
|
||||
console.log(e)
|
||||
})
|
@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Loading...</p>
|
||||
</body>
|
||||
<script src="./bundle.js"/>
|
||||
</html>
|
@ -1,52 +0,0 @@
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow;
|
||||
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
});
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||
|
||||
// Open the DevTools.
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', () => {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
};
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', createWindow);
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', () => {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (mainWindow === null) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and import them here.
|
7750
binaryen/yarn.lock
7750
binaryen/yarn.lock
File diff suppressed because it is too large
Load Diff
@ -1,42 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"development": {
|
||||
"application/javascript": {
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"electron": 2
|
||||
}
|
||||
}
|
||||
],
|
||||
"react"
|
||||
],
|
||||
"plugins": [
|
||||
"transform-async-to-generator"
|
||||
],
|
||||
"sourceMaps": "inline"
|
||||
}
|
||||
},
|
||||
"production": {
|
||||
"application/javascript": {
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"electron": 2
|
||||
}
|
||||
}
|
||||
],
|
||||
"react"
|
||||
],
|
||||
"plugins": [
|
||||
"transform-async-to-generator"
|
||||
],
|
||||
"sourceMaps": "none"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "eslint-config-airbnb",
|
||||
"rules": {
|
||||
"import/extensions": 0,
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"import/no-unresolved": [2, { "ignore": ["electron"] }],
|
||||
"linebreak-style": 0
|
||||
}
|
||||
}
|
4
percy/.gitignore
vendored
4
percy/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
node_modules/
|
||||
Cargo.lock
|
||||
target/
|
||||
dist/
|
@ -1,12 +0,0 @@
|
||||
[package]
|
||||
name = "percy"
|
||||
version = "0.1.0"
|
||||
authors = ["Bradlee Speice <bradlee@speice.io>"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
percy-webapis = "0.0.1"
|
||||
virtual-dom-rs = "0.1"
|
||||
wasm-bindgen = "0.2"
|
@ -1,25 +0,0 @@
|
||||
DIR="$(dirname $0)"
|
||||
WASM_DIR="$DIR/target/wasm32-unknown-unknown"
|
||||
WASM_NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')"
|
||||
APP_DIR="$DIR/dist/"
|
||||
|
||||
if [ ! -d "$APP_DIR" ]; then
|
||||
mkdir "$APP_DIR"
|
||||
fi
|
||||
cp "$DIR/static/"* "$APP_DIR"
|
||||
|
||||
if [ -z "$(which cargo)" ]; then
|
||||
echo 'Must install `cargo` before proceeding. Please see https://rustup.rs/ for more information.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$(which wasm-bindgen)" ]; then
|
||||
echo "Installing wasm-bindgen-cli"
|
||||
cargo install wasm-bindgen-cli
|
||||
fi
|
||||
|
||||
cargo +nightly build --target=wasm32-unknown-unknown && \
|
||||
wasm-bindgen "$WASM_DIR/debug/$WASM_NAME.wasm" --out-dir "$APP_DIR" --no-typescript && \
|
||||
# Have to use --mode=development so we can patch out the call to instantiateStreaming
|
||||
"$DIR/node_modules/webpack-cli/bin/cli.js" --mode=development "$APP_DIR/app_loader.js" -o "$APP_DIR/bundle.js" && \
|
||||
sed -i 's/.*instantiateStreaming.*//g' "$APP_DIR/bundle.js"
|
@ -1,66 +0,0 @@
|
||||
{
|
||||
"name": "electron_percy_wasm",
|
||||
"productName": "electron_percy_wasm",
|
||||
"version": "1.0.0",
|
||||
"description": "My Electron application description",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"prestart": "./build.sh",
|
||||
"start": "electron-forge start",
|
||||
"package": "electron-forge package",
|
||||
"make": "electron-forge make",
|
||||
"lint": "eslint src"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "bspeice",
|
||||
"license": "MIT",
|
||||
"config": {
|
||||
"forge": {
|
||||
"make_targets": {
|
||||
"win32": [
|
||||
"squirrel"
|
||||
],
|
||||
"darwin": [
|
||||
"zip"
|
||||
],
|
||||
"linux": [
|
||||
"deb",
|
||||
"rpm"
|
||||
]
|
||||
},
|
||||
"electronPackagerConfig": {
|
||||
"packageManager": "yarn"
|
||||
},
|
||||
"electronWinstallerConfig": {
|
||||
"name": "electron_percy_wasm"
|
||||
},
|
||||
"electronInstallerDebian": {},
|
||||
"electronInstallerRedhat": {},
|
||||
"github_repository": {
|
||||
"owner": "",
|
||||
"name": ""
|
||||
},
|
||||
"windowsStoreConfig": {
|
||||
"packageName": "",
|
||||
"name": "electron_percy_wasm"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-compile": "^6.4.3",
|
||||
"webpack": "^4.17.1",
|
||||
"webpack-cli": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-plugin-transform-async-to-generator": "^6.24.1",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"electron-forge": "^5.2.2",
|
||||
"electron-prebuilt-compile": "2.0.7",
|
||||
"eslint": "^3",
|
||||
"eslint-config-airbnb": "^15",
|
||||
"eslint-plugin-import": "^2",
|
||||
"eslint-plugin-jsx-a11y": "^5",
|
||||
"eslint-plugin-react": "^7"
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#[macro_use]
|
||||
extern crate virtual_dom_rs;
|
||||
|
||||
extern crate percy_webapis;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use percy_webapis::log;
|
||||
use percy_webapis::Element;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn main() -> Element {
|
||||
log("Entered Rust code");
|
||||
|
||||
let elem = html! {
|
||||
<span> {"It is alive!"} </span>
|
||||
};
|
||||
|
||||
elem.create_element()
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
const app = import("./percy")
|
||||
app.then(module => {
|
||||
console.log("Finished resolving application bundle")
|
||||
let rootNode = document.getElementById('root')
|
||||
rootNode.parentElement.replaceChild(module.main(), rootNode)
|
||||
rootNode = document.getElementById('root')
|
||||
}, (e) => {
|
||||
console.log("Unable to resolve application bundle: ")
|
||||
console.log(e)
|
||||
})
|
@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root">Loading...</div>
|
||||
</body>
|
||||
<script src="./bundle.js"/>
|
||||
</html>
|
@ -1,52 +0,0 @@
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow;
|
||||
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
});
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||
|
||||
// Open the DevTools.
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', () => {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
};
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', createWindow);
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', () => {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (mainWindow === null) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and import them here.
|
7736
percy/yarn.lock
7736
percy/yarn.lock
File diff suppressed because it is too large
Load Diff
@ -1,42 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"development": {
|
||||
"application/javascript": {
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"electron": 2
|
||||
}
|
||||
}
|
||||
],
|
||||
"react"
|
||||
],
|
||||
"plugins": [
|
||||
"transform-async-to-generator"
|
||||
],
|
||||
"sourceMaps": "inline"
|
||||
}
|
||||
},
|
||||
"production": {
|
||||
"application/javascript": {
|
||||
"presets": [
|
||||
[
|
||||
"env",
|
||||
{
|
||||
"targets": {
|
||||
"electron": 2
|
||||
}
|
||||
}
|
||||
],
|
||||
"react"
|
||||
],
|
||||
"plugins": [
|
||||
"transform-async-to-generator"
|
||||
],
|
||||
"sourceMaps": "none"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "eslint-config-airbnb",
|
||||
"rules": {
|
||||
"import/extensions": 0,
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"import/no-unresolved": [2, { "ignore": ["electron"] }],
|
||||
"linebreak-style": 0
|
||||
}
|
||||
}
|
4
percy_patched_webpack/.gitignore
vendored
4
percy_patched_webpack/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
node_modules/
|
||||
Cargo.lock
|
||||
target/
|
||||
dist/
|
@ -1,12 +0,0 @@
|
||||
[package]
|
||||
name = "percy"
|
||||
version = "0.1.0"
|
||||
authors = ["Bradlee Speice <bradlee@speice.io>"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
percy-webapis = "0.0.1"
|
||||
virtual-dom-rs = "0.1"
|
||||
wasm-bindgen = "0.2"
|
@ -1,372 +0,0 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
"use strict";
|
||||
|
||||
const Template = require("../Template");
|
||||
const WebAssemblyUtils = require("./WebAssemblyUtils");
|
||||
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("../MainTemplate")} MainTemplate */
|
||||
|
||||
// Get all wasm modules
|
||||
const getAllWasmModules = chunk => {
|
||||
const wasmModules = chunk.getAllAsyncChunks();
|
||||
const array = [];
|
||||
for (const chunk of wasmModules) {
|
||||
for (const m of chunk.modulesIterable) {
|
||||
if (m.type.startsWith("webassembly")) {
|
||||
array.push(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
};
|
||||
|
||||
/**
|
||||
* generates the import object function for a module
|
||||
* @param {Module} module the module
|
||||
* @param {boolean} mangle mangle imports
|
||||
* @returns {string} source code
|
||||
*/
|
||||
const generateImportObject = (module, mangle) => {
|
||||
const waitForInstances = new Map();
|
||||
const properties = [];
|
||||
const usedWasmDependencies = WebAssemblyUtils.getUsedDependencies(
|
||||
module,
|
||||
mangle
|
||||
);
|
||||
for (const usedDep of usedWasmDependencies) {
|
||||
const dep = usedDep.dependency;
|
||||
const importedModule = dep.module;
|
||||
const exportName = dep.name;
|
||||
const usedName = importedModule && importedModule.isUsed(exportName);
|
||||
const description = dep.description;
|
||||
const direct = dep.onlyDirectImport;
|
||||
|
||||
const module = usedDep.module;
|
||||
const name = usedDep.name;
|
||||
|
||||
if (direct) {
|
||||
const instanceVar = `m${waitForInstances.size}`;
|
||||
waitForInstances.set(instanceVar, importedModule.id);
|
||||
properties.push({
|
||||
module,
|
||||
name,
|
||||
value: `${instanceVar}[${JSON.stringify(usedName)}]`
|
||||
});
|
||||
} else {
|
||||
const params = description.signature.params.map(
|
||||
(param, k) => "p" + k + param.valtype
|
||||
);
|
||||
|
||||
const mod = `installedModules[${JSON.stringify(importedModule.id)}]`;
|
||||
const func = `${mod}.exports[${JSON.stringify(usedName)}]`;
|
||||
|
||||
properties.push({
|
||||
module,
|
||||
name,
|
||||
value: Template.asString([
|
||||
(importedModule.type.startsWith("webassembly")
|
||||
? `${mod} ? ${func} : `
|
||||
: "") + `function(${params}) {`,
|
||||
Template.indent([`return ${func}(${params});`]),
|
||||
"}"
|
||||
])
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let importObject;
|
||||
if (mangle) {
|
||||
importObject = [
|
||||
"return {",
|
||||
Template.indent([
|
||||
properties.map(p => `${JSON.stringify(p.name)}: ${p.value}`).join(",\n")
|
||||
]),
|
||||
"};"
|
||||
];
|
||||
} else {
|
||||
const propertiesByModule = new Map();
|
||||
for (const p of properties) {
|
||||
let list = propertiesByModule.get(p.module);
|
||||
if (list === undefined) {
|
||||
propertiesByModule.set(p.module, (list = []));
|
||||
}
|
||||
list.push(p);
|
||||
}
|
||||
importObject = [
|
||||
"return {",
|
||||
Template.indent([
|
||||
Array.from(propertiesByModule, ([module, list]) => {
|
||||
return Template.asString([
|
||||
`${JSON.stringify(module)}: {`,
|
||||
Template.indent([
|
||||
list.map(p => `${JSON.stringify(p.name)}: ${p.value}`).join(",\n")
|
||||
]),
|
||||
"}"
|
||||
]);
|
||||
}).join(",\n")
|
||||
]),
|
||||
"};"
|
||||
];
|
||||
}
|
||||
|
||||
if (waitForInstances.size === 1) {
|
||||
const moduleId = Array.from(waitForInstances.values())[0];
|
||||
const promise = `installedWasmModules[${JSON.stringify(moduleId)}]`;
|
||||
const variable = Array.from(waitForInstances.keys())[0];
|
||||
return Template.asString([
|
||||
`${JSON.stringify(module.id)}: function() {`,
|
||||
Template.indent([
|
||||
`return promiseResolve().then(function() { return ${promise}; }).then(function(${variable}) {`,
|
||||
Template.indent(importObject),
|
||||
"});"
|
||||
]),
|
||||
"},"
|
||||
]);
|
||||
} else if (waitForInstances.size > 0) {
|
||||
const promises = Array.from(
|
||||
waitForInstances.values(),
|
||||
id => `installedWasmModules[${JSON.stringify(id)}]`
|
||||
).join(", ");
|
||||
const variables = Array.from(
|
||||
waitForInstances.keys(),
|
||||
(name, i) => `${name} = array[${i}]`
|
||||
).join(", ");
|
||||
return Template.asString([
|
||||
`${JSON.stringify(module.id)}: function() {`,
|
||||
Template.indent([
|
||||
`return promiseResolve().then(function() { return Promise.all([${promises}]); }).then(function(array) {`,
|
||||
Template.indent([`var ${variables};`, ...importObject]),
|
||||
"});"
|
||||
]),
|
||||
"},"
|
||||
]);
|
||||
} else {
|
||||
return Template.asString([
|
||||
`${JSON.stringify(module.id)}: function() {`,
|
||||
Template.indent(importObject),
|
||||
"},"
|
||||
]);
|
||||
}
|
||||
};
|
||||
|
||||
class WasmMainTemplatePlugin {
|
||||
constructor({ generateLoadBinaryCode, supportsStreaming, mangleImports }) {
|
||||
this.generateLoadBinaryCode = generateLoadBinaryCode;
|
||||
this.supportsStreaming = supportsStreaming;
|
||||
this.mangleImports = mangleImports;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MainTemplate} mainTemplate main template
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(mainTemplate) {
|
||||
mainTemplate.hooks.localVars.tap(
|
||||
"WasmMainTemplatePlugin",
|
||||
(source, chunk) => {
|
||||
const wasmModules = getAllWasmModules(chunk);
|
||||
if (wasmModules.length === 0) return source;
|
||||
const importObjects = wasmModules.map(module => {
|
||||
return generateImportObject(module, this.mangleImports);
|
||||
});
|
||||
return Template.asString([
|
||||
source,
|
||||
"",
|
||||
"// object to store loaded and loading wasm modules",
|
||||
"var installedWasmModules = {};",
|
||||
"",
|
||||
// This function is used to delay reading the installed wasm module promises
|
||||
// by a microtask. Sorting them doesn't help because there are egdecases where
|
||||
// sorting is not possible (modules splitted into different chunks).
|
||||
// So we not even trying and solve this by a microtask delay.
|
||||
"function promiseResolve() { return Promise.resolve(); }",
|
||||
"",
|
||||
"var wasmImportObjects = {",
|
||||
Template.indent(importObjects),
|
||||
"};"
|
||||
]);
|
||||
}
|
||||
);
|
||||
mainTemplate.hooks.requireEnsure.tap(
|
||||
"WasmMainTemplatePlugin",
|
||||
(source, chunk, hash) => {
|
||||
const webassemblyModuleFilename =
|
||||
mainTemplate.outputOptions.webassemblyModuleFilename;
|
||||
|
||||
const chunkModuleMaps = chunk.getChunkModuleMaps(m =>
|
||||
m.type.startsWith("webassembly")
|
||||
);
|
||||
if (Object.keys(chunkModuleMaps.id).length === 0) return source;
|
||||
const wasmModuleSrcPath = mainTemplate.getAssetPath(
|
||||
JSON.stringify(webassemblyModuleFilename),
|
||||
{
|
||||
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
||||
hashWithLength: length =>
|
||||
`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
||||
module: {
|
||||
id: '" + wasmModuleId + "',
|
||||
hash: `" + ${JSON.stringify(
|
||||
chunkModuleMaps.hash
|
||||
)}[wasmModuleId] + "`,
|
||||
hashWithLength(length) {
|
||||
const shortChunkHashMap = Object.create(null);
|
||||
for (const wasmModuleId of Object.keys(chunkModuleMaps.hash)) {
|
||||
if (typeof chunkModuleMaps.hash[wasmModuleId] === "string") {
|
||||
shortChunkHashMap[wasmModuleId] = chunkModuleMaps.hash[
|
||||
wasmModuleId
|
||||
].substr(0, length);
|
||||
}
|
||||
}
|
||||
return `" + ${JSON.stringify(
|
||||
shortChunkHashMap
|
||||
)}[wasmModuleId] + "`;
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
const createImportObject = content =>
|
||||
this.mangleImports
|
||||
? `{ ${JSON.stringify(
|
||||
WebAssemblyUtils.MANGLED_MODULE
|
||||
)}: ${content} }`
|
||||
: content;
|
||||
return Template.asString([
|
||||
source,
|
||||
"",
|
||||
"// Fetch + compile chunk loading for webassembly",
|
||||
"",
|
||||
`var wasmModules = ${JSON.stringify(
|
||||
chunkModuleMaps.id
|
||||
)}[chunkId] || [];`,
|
||||
"",
|
||||
"wasmModules.forEach(function(wasmModuleId) {",
|
||||
Template.indent([
|
||||
"var installedWasmModuleData = installedWasmModules[wasmModuleId];",
|
||||
"",
|
||||
'// a Promise means "currently loading" or "already loaded".',
|
||||
"if(installedWasmModuleData)",
|
||||
Template.indent(["promises.push(installedWasmModuleData);"]),
|
||||
"else {",
|
||||
Template.indent([
|
||||
`var importObject = wasmImportObjects[wasmModuleId]();`,
|
||||
`var req = ${this.generateLoadBinaryCode(wasmModuleSrcPath)};`,
|
||||
"var promise;",
|
||||
this.supportsStreaming
|
||||
? Template.asString([
|
||||
"if(importObject instanceof Promise && typeof WebAssembly.compileStreaming === 'function') {",
|
||||
Template.indent([
|
||||
"promise = Promise.all([WebAssembly.compileStreaming(req), importObject]).then(function(items) {",
|
||||
Template.indent([
|
||||
`return WebAssembly.instantiate(items[0], ${createImportObject(
|
||||
"items[1]"
|
||||
)});`
|
||||
]),
|
||||
"});"
|
||||
]),
|
||||
"} else if(typeof WebAssembly.instantiateStreaming === 'function') {",
|
||||
Template.indent([
|
||||
`promise = WebAssembly.instantiateStreaming(req, ${createImportObject(
|
||||
"importObject"
|
||||
)}).catch(function(reason) {`,
|
||||
Template.indent([
|
||||
`if (reason.name === "TypeError") {`,
|
||||
Template.indent([
|
||||
`console.log("Potential WASM MIME issue detected, falling back to arrayBuffer instantiation");`,
|
||||
"return req.then(function(x) { return x.arrayBuffer(); }).then(function(bytes) {",
|
||||
Template.indent([
|
||||
"return WebAssembly.instantiate(bytes, importObject);"
|
||||
]),
|
||||
"});"
|
||||
]),
|
||||
"}",
|
||||
"throw reason;"
|
||||
]),
|
||||
"});"
|
||||
])
|
||||
])
|
||||
: Template.asString([
|
||||
"if(importObject instanceof Promise) {",
|
||||
Template.indent([
|
||||
"var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });",
|
||||
"promise = Promise.all([",
|
||||
Template.indent([
|
||||
"bytesPromise.then(function(bytes) { return WebAssembly.compile(bytes); }),",
|
||||
"importObject"
|
||||
]),
|
||||
"]).then(function(items) {",
|
||||
Template.indent([
|
||||
`return WebAssembly.instantiate(items[0], ${createImportObject(
|
||||
"items[1]"
|
||||
)});`
|
||||
]),
|
||||
"});"
|
||||
])
|
||||
]),
|
||||
"} else {",
|
||||
Template.indent([
|
||||
"var bytesPromise = req.then(function(x) { return x.arrayBuffer(); });",
|
||||
"promise = bytesPromise.then(function(bytes) {",
|
||||
Template.indent([
|
||||
`return WebAssembly.instantiate(bytes, ${createImportObject(
|
||||
"importObject"
|
||||
)});`
|
||||
]),
|
||||
"});"
|
||||
]),
|
||||
"}",
|
||||
"promises.push(installedWasmModules[wasmModuleId] = promise.then(function(res) {",
|
||||
Template.indent([
|
||||
`return ${
|
||||
mainTemplate.requireFn
|
||||
}.w[wasmModuleId] = (res.instance || res).exports;`
|
||||
]),
|
||||
"}));"
|
||||
]),
|
||||
"}"
|
||||
]),
|
||||
"});"
|
||||
]);
|
||||
}
|
||||
);
|
||||
mainTemplate.hooks.requireExtensions.tap(
|
||||
"WasmMainTemplatePlugin",
|
||||
(source, chunk) => {
|
||||
if (!chunk.hasModuleInGraph(m => m.type.startsWith("webassembly"))) {
|
||||
return source;
|
||||
}
|
||||
return Template.asString([
|
||||
source,
|
||||
"",
|
||||
"// object with all WebAssembly.instance exports",
|
||||
`${mainTemplate.requireFn}.w = {};`
|
||||
]);
|
||||
}
|
||||
);
|
||||
mainTemplate.hooks.hash.tap("WasmMainTemplatePlugin", hash => {
|
||||
hash.update("WasmMainTemplatePlugin");
|
||||
hash.update("1");
|
||||
hash.update(`${mainTemplate.outputOptions.webassemblyModuleFilename}`);
|
||||
hash.update(`${this.mangleImports}`);
|
||||
});
|
||||
mainTemplate.hooks.hashForChunk.tap(
|
||||
"WasmMainTemplatePlugin",
|
||||
(hash, chunk) => {
|
||||
const chunkModuleMaps = chunk.getChunkModuleMaps(m =>
|
||||
m.type.startsWith("webassembly")
|
||||
);
|
||||
hash.update(JSON.stringify(chunkModuleMaps.id));
|
||||
const wasmModules = getAllWasmModules(chunk);
|
||||
for (const module of wasmModules) {
|
||||
hash.update(module.hash);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WasmMainTemplatePlugin;
|
@ -1,27 +0,0 @@
|
||||
DIR="$(dirname $0)"
|
||||
WASM_DIR="$DIR/target/wasm32-unknown-unknown"
|
||||
WASM_NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')"
|
||||
APP_DIR="$DIR/dist/"
|
||||
|
||||
if [ ! -d "$APP_DIR" ]; then
|
||||
mkdir "$APP_DIR"
|
||||
fi
|
||||
cp "$DIR/static/"* "$APP_DIR"
|
||||
|
||||
if [ -z "$(which cargo)" ]; then
|
||||
echo 'Must install `cargo` before proceeding. Please see https://rustup.rs/ for more information.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$(which wasm-bindgen)" ]; then
|
||||
echo "Installing wasm-bindgen-cli"
|
||||
cargo install wasm-bindgen-cli
|
||||
fi
|
||||
|
||||
# Patch from: https://github.com/webpack/webpack/pull/7983
|
||||
cp "$DIR/WasmMainTemplatePlugin.patched.js" "$DIR/node_modules/webpack/lib/wasm/WasmMainTemplatePlugin.js"
|
||||
|
||||
cargo +nightly build --target=wasm32-unknown-unknown && \
|
||||
wasm-bindgen "$WASM_DIR/debug/$WASM_NAME.wasm" --out-dir "$APP_DIR" --no-typescript && \
|
||||
# --mode=production requires https://github.com/webpack/webpack/pull/7732
|
||||
"$DIR/node_modules/webpack-cli/bin/cli.js" --mode=production "$APP_DIR/app_loader.js" -o "$APP_DIR/bundle.js"
|
@ -1,66 +0,0 @@
|
||||
{
|
||||
"name": "electron_percy_wasm",
|
||||
"productName": "electron_percy_wasm",
|
||||
"version": "1.0.0",
|
||||
"description": "My Electron application description",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"prestart": "./build.sh",
|
||||
"start": "electron-forge start",
|
||||
"package": "electron-forge package",
|
||||
"make": "electron-forge make",
|
||||
"lint": "eslint src"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "bspeice",
|
||||
"license": "MIT",
|
||||
"config": {
|
||||
"forge": {
|
||||
"make_targets": {
|
||||
"win32": [
|
||||
"squirrel"
|
||||
],
|
||||
"darwin": [
|
||||
"zip"
|
||||
],
|
||||
"linux": [
|
||||
"deb",
|
||||
"rpm"
|
||||
]
|
||||
},
|
||||
"electronPackagerConfig": {
|
||||
"packageManager": "yarn"
|
||||
},
|
||||
"electronWinstallerConfig": {
|
||||
"name": "electron_percy_wasm"
|
||||
},
|
||||
"electronInstallerDebian": {},
|
||||
"electronInstallerRedhat": {},
|
||||
"github_repository": {
|
||||
"owner": "",
|
||||
"name": ""
|
||||
},
|
||||
"windowsStoreConfig": {
|
||||
"packageName": "",
|
||||
"name": "electron_percy_wasm"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"electron-compile": "^6.4.3",
|
||||
"webpack": "^4.17.1",
|
||||
"webpack-cli": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-plugin-transform-async-to-generator": "^6.24.1",
|
||||
"babel-preset-env": "^1.7.0",
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"electron-forge": "^5.2.2",
|
||||
"electron-prebuilt-compile": "2.0.7",
|
||||
"eslint": "^3",
|
||||
"eslint-config-airbnb": "^15",
|
||||
"eslint-plugin-import": "^2",
|
||||
"eslint-plugin-jsx-a11y": "^5",
|
||||
"eslint-plugin-react": "^7"
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#[macro_use]
|
||||
extern crate virtual_dom_rs;
|
||||
|
||||
extern crate percy_webapis;
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use percy_webapis::log;
|
||||
use percy_webapis::Element;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn main() -> Element {
|
||||
log("Entered Rust code");
|
||||
|
||||
let elem = html! {
|
||||
<span> {"It is alive!"} </span>
|
||||
};
|
||||
|
||||
elem.create_element()
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
const app = import("./percy")
|
||||
app.then(module => {
|
||||
console.log("Finished resolving application bundle")
|
||||
let rootNode = document.getElementById('root')
|
||||
rootNode.parentElement.replaceChild(module.main(), rootNode)
|
||||
rootNode = document.getElementById('root')
|
||||
}, (e) => {
|
||||
console.log("Unable to resolve application bundle: ")
|
||||
console.log(e)
|
||||
})
|
@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root">Loading...</div>
|
||||
</body>
|
||||
<script src="./bundle.js"/>
|
||||
</html>
|
@ -1,52 +0,0 @@
|
||||
import { app, BrowserWindow } from 'electron';
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let mainWindow;
|
||||
|
||||
const createWindow = () => {
|
||||
// Create the browser window.
|
||||
mainWindow = new BrowserWindow({
|
||||
width: 800,
|
||||
height: 600,
|
||||
});
|
||||
|
||||
// and load the index.html of the app.
|
||||
mainWindow.loadURL(`file://${__dirname}/index.html`);
|
||||
|
||||
// Open the DevTools.
|
||||
mainWindow.webContents.openDevTools();
|
||||
|
||||
// Emitted when the window is closed.
|
||||
mainWindow.on('closed', () => {
|
||||
// Dereference the window object, usually you would store windows
|
||||
// in an array if your app supports multi windows, this is the time
|
||||
// when you should delete the corresponding element.
|
||||
mainWindow = null;
|
||||
});
|
||||
};
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
// initialization and is ready to create browser windows.
|
||||
// Some APIs can only be used after this event occurs.
|
||||
app.on('ready', createWindow);
|
||||
|
||||
// Quit when all windows are closed.
|
||||
app.on('window-all-closed', () => {
|
||||
// On OS X it is common for applications and their menu bar
|
||||
// to stay active until the user quits explicitly with Cmd + Q
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
app.on('activate', () => {
|
||||
// On OS X it's common to re-create a window in the app when the
|
||||
// dock icon is clicked and there are no other windows open.
|
||||
if (mainWindow === null) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
|
||||
// In this file you can include the rest of your app's specific main process
|
||||
// code. You can also put them in separate files and import them here.
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user