mirror of
https://github.com/speice-io/isomorphic-rust
synced 2025-08-27 17:54:53 -04:00
Synchronize, not sure how much is or isn't working
This commit is contained in:
42
electron_percy_emscripten/.compilerc
Normal file
42
electron_percy_emscripten/.compilerc
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
electron_percy_emscripten/.eslintrc
Normal file
9
electron_percy_emscripten/.eslintrc
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "eslint-config-airbnb",
|
||||
"rules": {
|
||||
"import/extensions": 0,
|
||||
"import/no-extraneous-dependencies": 0,
|
||||
"import/no-unresolved": [2, { "ignore": ["electron"] }],
|
||||
"linebreak-style": 0
|
||||
}
|
||||
}
|
4
electron_percy_emscripten/.gitignore
vendored
Normal file
4
electron_percy_emscripten/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
node_modules/
|
||||
Cargo.lock
|
||||
target/
|
||||
binaryen/
|
10
electron_percy_emscripten/Cargo.toml
Normal file
10
electron_percy_emscripten/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "electron_percy_emscripten"
|
||||
version = "0.1.0"
|
||||
authors = ["Bradlee Speice <bradlee@speice.io>"]
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
stdweb = "0.4"
|
5
electron_percy_emscripten/app/.gitignore
vendored
Normal file
5
electron_percy_emscripten/app/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
*.wasm
|
||||
*.bundle.js
|
||||
bundle.js
|
||||
electron_percy_wasm.js
|
||||
app.js
|
8
electron_percy_emscripten/app/app_loader.js
Normal file
8
electron_percy_emscripten/app/app_loader.js
Normal file
@ -0,0 +1,8 @@
|
||||
import { main } from "./app"
|
||||
|
||||
console.log(main(24))
|
||||
|
||||
console.log("app_loader entrance")
|
||||
let rootNode = document.getElementById('root')
|
||||
//rootNode.parentElement.replaceChild(main(), rootNode)
|
||||
rootNode = document.getElementById('root')
|
11
electron_percy_emscripten/app/index.html
Normal file
11
electron_percy_emscripten/app/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root">Loading...</div>
|
||||
</body>
|
||||
<script src="./app_loader.js"/>
|
||||
</html>
|
52
electron_percy_emscripten/app/index.js
Normal file
52
electron_percy_emscripten/app/index.js
Normal file
@ -0,0 +1,52 @@
|
||||
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.
|
30
electron_percy_emscripten/build_wasm.sh
Executable file
30
electron_percy_emscripten/build_wasm.sh
Executable file
@ -0,0 +1,30 @@
|
||||
#!/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/app/"
|
||||
|
||||
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
|
||||
|
||||
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 && \
|
||||
"$DIR/binaryen/bin/wasm2js" --pedantic "$WASM_DIR/debug/$WASM_NAME.wasm" -o "$WASM_DIR/debug/$WASM_NAME.js" && \
|
||||
"$DIR/node_modules/webpack-cli/bin/cli.js" "$WASM_DIR/debug/$WASM_NAME.js" -o "$APP_DIR/app.js"
|
66
electron_percy_emscripten/package.json
Normal file
66
electron_percy_emscripten/package.json
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"name": "electron_percy_wasm",
|
||||
"productName": "electron_percy_wasm",
|
||||
"version": "1.0.0",
|
||||
"description": "My Electron application description",
|
||||
"main": "app/index.js",
|
||||
"scripts": {
|
||||
"prestart": "./build_wasm.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"
|
||||
}
|
||||
}
|
11
electron_percy_emscripten/src/lib.rs
Normal file
11
electron_percy_emscripten/src/lib.rs
Normal file
@ -0,0 +1,11 @@
|
||||
#![no_std]
|
||||
|
||||
#[macro_use]
|
||||
extern crate stdweb;
|
||||
|
||||
use stdweb::web::Element;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main(x: i32) -> i32 {
|
||||
x * 2
|
||||
}
|
91
electron_percy_emscripten/test.js
Normal file
91
electron_percy_emscripten/test.js
Normal file
@ -0,0 +1,91 @@
|
||||
function asmFunc(global, env, buffer) {
|
||||
"almost asm";
|
||||
var HEAP8 = new global.Int8Array(buffer);
|
||||
var HEAP16 = new global.Int16Array(buffer);
|
||||
var HEAP32 = new global.Int32Array(buffer);
|
||||
var HEAPU8 = new global.Uint8Array(buffer);
|
||||
var HEAPU16 = new global.Uint16Array(buffer);
|
||||
var HEAPU32 = new global.Uint32Array(buffer);
|
||||
var HEAPF32 = new global.Float32Array(buffer);
|
||||
var HEAPF64 = new global.Float64Array(buffer);
|
||||
var Math_imul = global.Math.imul;
|
||||
var Math_fround = global.Math.fround;
|
||||
var Math_abs = global.Math.abs;
|
||||
var Math_clz32 = global.Math.clz32;
|
||||
var Math_min = global.Math.min;
|
||||
var Math_max = global.Math.max;
|
||||
var Math_floor = global.Math.floor;
|
||||
var Math_ceil = global.Math.ceil;
|
||||
var Math_sqrt = global.Math.sqrt;
|
||||
var abort = env.abort;
|
||||
var nan = global.NaN;
|
||||
var infinity = global.Infinity;
|
||||
var global$0 = 1048576;
|
||||
var global$1 = 1048610;
|
||||
var global$2 = 1048610;
|
||||
var global$3 = 1048576;
|
||||
var i64toi32_i32$HIGH_BITS = 0;
|
||||
function __wasm_call_ctors() {
|
||||
|
||||
}
|
||||
|
||||
function __wasm_grow_memory(pagesToAdd) {
|
||||
pagesToAdd = pagesToAdd | 0;
|
||||
var oldPages = __wasm_current_memory() | 0;
|
||||
var newPages = oldPages + pagesToAdd | 0;
|
||||
if ((oldPages < newPages) && (newPages < 65535)) {
|
||||
var newBuffer = new ArrayBuffer(Math_imul(newPages, 65536));
|
||||
var newHEAP8 = new global.Int8Array(newBuffer);
|
||||
newHEAP8.set(HEAP8);
|
||||
HEAP8 = newHEAP8;
|
||||
HEAP16 = new global.Int16Array(newBuffer);
|
||||
HEAP32 = new global.Int32Array(newBuffer);
|
||||
HEAPU8 = new global.Uint8Array(newBuffer);
|
||||
HEAPU16 = new global.Uint16Array(newBuffer);
|
||||
HEAPU32 = new global.Uint32Array(newBuffer);
|
||||
HEAPF32 = new global.Float32Array(newBuffer);
|
||||
HEAPF64 = new global.Float64Array(newBuffer);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
return oldPages;
|
||||
}
|
||||
|
||||
function __wasm_current_memory() {
|
||||
return buffer.byteLength / 65536 | 0;
|
||||
}
|
||||
|
||||
return {
|
||||
memory: Object.create(Object.prototype, {
|
||||
grow: {
|
||||
value: __wasm_grow_memory
|
||||
},
|
||||
buffer: {
|
||||
get: function () {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
const memasmFunc = new ArrayBuffer(1114112);
|
||||
const assignasmFunc = (
|
||||
function(mem) {
|
||||
const _mem = new Uint8Array(mem);
|
||||
return function(offset, s) {
|
||||
if (typeof Buffer === 'undefined') {
|
||||
const bytes = atob(s);
|
||||
for (let i = 0; i < bytes.length; i++)
|
||||
_mem[offset + i] = bytes.charCodeAt(i);
|
||||
} else {
|
||||
const bytes = Buffer.from(s, 'base64');
|
||||
for (let i = 0; i < bytes.length; i++)
|
||||
_mem[offset + i] = bytes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
)(memasmFunc);
|
||||
assignasmFunc(1048576, "AWdkYl9sb2FkX3J1c3RfcHJldHR5X3ByaW50ZXJzLnB5AA==");
|
||||
const retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc);
|
||||
export const memory = retasmFunc.memory;
|
1972593
electron_percy_emscripten/test.log
Normal file
1972593
electron_percy_emscripten/test.log
Normal file
File diff suppressed because it is too large
Load Diff
7736
electron_percy_emscripten/yarn.lock
Normal file
7736
electron_percy_emscripten/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user