Browse Source

Attempt adding binaryen - doesn't actually run though

Bradlee Speice 10 months ago
parent
commit
d6c662ac80

+ 42
- 0
binaryen/.compilerc View File

@@ -0,0 +1,42 @@
1
+{
2
+  "env": {
3
+    "development": {
4
+      "application/javascript": {
5
+        "presets": [
6
+          [
7
+            "env",
8
+            {
9
+              "targets": {
10
+                "electron": 2
11
+              }
12
+            }
13
+          ],
14
+          "react"
15
+        ],
16
+        "plugins": [
17
+          "transform-async-to-generator"
18
+        ],
19
+        "sourceMaps": "inline"
20
+      }
21
+    },
22
+    "production": {
23
+      "application/javascript": {
24
+        "presets": [
25
+          [
26
+            "env",
27
+            {
28
+              "targets": {
29
+                "electron": 2
30
+              }
31
+            }
32
+          ],
33
+          "react"
34
+        ],
35
+        "plugins": [
36
+          "transform-async-to-generator"
37
+        ],
38
+        "sourceMaps": "none"
39
+      }
40
+    }
41
+  }
42
+}

+ 9
- 0
binaryen/.eslintrc View File

@@ -0,0 +1,9 @@
1
+{
2
+  "extends": "eslint-config-airbnb",
3
+  "rules": {
4
+    "import/extensions": 0,
5
+    "import/no-extraneous-dependencies": 0,
6
+    "import/no-unresolved": [2, { "ignore": ["electron"] }],
7
+    "linebreak-style": 0
8
+  }
9
+}

+ 5
- 0
binaryen/.gitignore View File

@@ -0,0 +1,5 @@
1
+node_modules/
2
+Cargo.lock
3
+target/
4
+dist/
5
+binaryen/

+ 15
- 0
binaryen/Cargo.toml View File

@@ -0,0 +1,15 @@
1
+[package]
2
+authors = ["Bradlee Speice"]
3
+categories = ["wasm"]
4
+description = "A no-framework WASM Electron app"
5
+license = "Apache-2.0/MIT"
6
+name = "stdweb_electron"
7
+readme = "./README.md"
8
+repository = "https://github.com/rustwasm/rust-webpack-template"
9
+version = "0.1.0"
10
+
11
+[lib]
12
+crate-type = ["cdylib"]
13
+
14
+[dependencies]
15
+stdweb = "0.4"

+ 27
- 0
binaryen/build.sh View File

@@ -0,0 +1,27 @@
1
+#!/bin/bash
2
+
3
+DIR="$(dirname $0)"
4
+WASM_DIR="$DIR/target/wasm32-unknown-unknown"
5
+WASM_NAME="$(cat "$DIR/Cargo.toml" | grep name | sed 's/name = "//' | sed 's/"//g')"
6
+APP_DIR="$DIR/dist/"
7
+
8
+if [ ! -f "$DIR/binaryen/bin/wasm2js" ]; then
9
+    git clone "https://github.com/WebAssembly/binaryen" "$DIR/binaryen"
10
+    pushd "$DIR/binaryen"
11
+    cmake . && make -j8
12
+    popd
13
+fi
14
+
15
+if [ ! -d "$APP_DIR" ]; then
16
+    mkdir "$APP_DIR"
17
+fi
18
+cp "$DIR/static/"* "$APP_DIR"
19
+
20
+if [ -z "$(which cargo)" ]; then
21
+    echo 'Must install `cargo` before proceeding. Please see https://rustup.rs/ for more information.'
22
+    exit 1
23
+fi
24
+
25
+cargo +nightly build --target=wasm32-unknown-unknown && \
26
+    "$DIR/binaryen/bin/wasm2js" --pedantic "$WASM_DIR/debug/stdweb_electron.wasm" -o "$APP_DIR/stdweb_electron.js" && \
27
+    "$DIR/node_modules/webpack-cli/bin/cli.js" --mode=development "$APP_DIR/stdweb_electron.js" -o "$APP_DIR/bundle.js"

+ 66
- 0
binaryen/package.json View File

@@ -0,0 +1,66 @@
1
+{
2
+    "name": "electron_percy_wasm",
3
+    "productName": "electron_percy_wasm",
4
+    "version": "1.0.0",
5
+    "description": "My Electron application description",
6
+    "main": "dist/index.js",
7
+    "scripts": {
8
+        "prestart": "./build.sh",
9
+        "start": "electron-forge start",
10
+        "package": "electron-forge package",
11
+        "make": "electron-forge make",
12
+        "lint": "eslint src"
13
+    },
14
+    "keywords": [],
15
+    "author": "bspeice",
16
+    "license": "MIT",
17
+    "config": {
18
+        "forge": {
19
+            "make_targets": {
20
+                "win32": [
21
+                    "squirrel"
22
+                ],
23
+                "darwin": [
24
+                    "zip"
25
+                ],
26
+                "linux": [
27
+                    "deb",
28
+                    "rpm"
29
+                ]
30
+            },
31
+            "electronPackagerConfig": {
32
+                "packageManager": "yarn"
33
+            },
34
+            "electronWinstallerConfig": {
35
+                "name": "electron_percy_wasm"
36
+            },
37
+            "electronInstallerDebian": {},
38
+            "electronInstallerRedhat": {},
39
+            "github_repository": {
40
+                "owner": "",
41
+                "name": ""
42
+            },
43
+            "windowsStoreConfig": {
44
+                "packageName": "",
45
+                "name": "electron_percy_wasm"
46
+            }
47
+        }
48
+    },
49
+    "dependencies": {
50
+        "electron-compile": "^6.4.3",
51
+        "webpack": "^4.17.1",
52
+        "webpack-cli": "^3.1.0"
53
+    },
54
+    "devDependencies": {
55
+        "babel-plugin-transform-async-to-generator": "^6.24.1",
56
+        "babel-preset-env": "^1.7.0",
57
+        "babel-preset-react": "^6.24.1",
58
+        "electron-forge": "^5.2.2",
59
+        "electron-prebuilt-compile": "2.0.7",
60
+        "eslint": "^3",
61
+        "eslint-config-airbnb": "^15",
62
+        "eslint-plugin-import": "^2",
63
+        "eslint-plugin-jsx-a11y": "^5",
64
+        "eslint-plugin-react": "^7"
65
+    }
66
+}

+ 16
- 0
binaryen/src/lib.rs View File

@@ -0,0 +1,16 @@
1
+extern crate stdweb;
2
+
3
+use stdweb::web::document;
4
+use stdweb::web::INode;
5
+use stdweb::web::IElement;
6
+
7
+pub fn run() {
8
+    stdweb::initialize();
9
+
10
+    let doc = document();
11
+    let val = doc.create_element("p").unwrap();
12
+    val.set_attribute("innerHTML", "IT IS ALIVE").unwrap();
13
+    doc.body().unwrap().append_child(&val);
14
+
15
+    stdweb::event_loop();
16
+}

+ 8
- 0
binaryen/static/app_loader.js View File

@@ -0,0 +1,8 @@
1
+const app = import("./stdweb_electron")
2
+app.then(module => {
3
+    console.log("Finished resolving application bundle")
4
+    module.run()
5
+}, (e) => {
6
+    console.log("Unable to resolve application bundle: ")
7
+    console.log(e)
8
+})

+ 11
- 0
binaryen/static/index.html View File

@@ -0,0 +1,11 @@
1
+<!DOCTYPE html>
2
+<html>
3
+  <head>
4
+    <meta charset="utf-8">
5
+    <title></title>
6
+  </head>
7
+  <body>
8
+    <p>Loading...</p>
9
+  </body>
10
+  <script src="./bundle.js"/>
11
+</html>

+ 52
- 0
binaryen/static/index.js View File

@@ -0,0 +1,52 @@
1
+import { app, BrowserWindow } from 'electron';
2
+
3
+// Keep a global reference of the window object, if you don't, the window will
4
+// be closed automatically when the JavaScript object is garbage collected.
5
+let mainWindow;
6
+
7
+const createWindow = () => {
8
+  // Create the browser window.
9
+  mainWindow = new BrowserWindow({
10
+    width: 800,
11
+    height: 600,
12
+  });
13
+
14
+  // and load the index.html of the app.
15
+  mainWindow.loadURL(`file://${__dirname}/index.html`);
16
+
17
+  // Open the DevTools.
18
+  mainWindow.webContents.openDevTools();
19
+
20
+  // Emitted when the window is closed.
21
+  mainWindow.on('closed', () => {
22
+    // Dereference the window object, usually you would store windows
23
+    // in an array if your app supports multi windows, this is the time
24
+    // when you should delete the corresponding element.
25
+    mainWindow = null;
26
+  });
27
+};
28
+
29
+// This method will be called when Electron has finished
30
+// initialization and is ready to create browser windows.
31
+// Some APIs can only be used after this event occurs.
32
+app.on('ready', createWindow);
33
+
34
+// Quit when all windows are closed.
35
+app.on('window-all-closed', () => {
36
+  // On OS X it is common for applications and their menu bar
37
+  // to stay active until the user quits explicitly with Cmd + Q
38
+  if (process.platform !== 'darwin') {
39
+    app.quit();
40
+  }
41
+});
42
+
43
+app.on('activate', () => {
44
+  // On OS X it's common to re-create a window in the app when the
45
+  // dock icon is clicked and there are no other windows open.
46
+  if (mainWindow === null) {
47
+    createWindow();
48
+  }
49
+});
50
+
51
+// In this file you can include the rest of your app's specific main process
52
+// code. You can also put them in separate files and import them here.

+ 7736
- 0
binaryen/yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save