Skip to content

Commit

Permalink
Merge pull request #249 from hotg-ai/web-runtime
Browse files Browse the repository at this point in the history
Add the web runtime to the Rune repo
  • Loading branch information
Michael Bryan authored Aug 13, 2021
2 parents 2f74904 + 9c9a621 commit 2e1b2ab
Show file tree
Hide file tree
Showing 14 changed files with 3,451 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,23 @@ jobs:
with:
branch: gh-pages
folder: target/doc

web-bindings:
name: Test Web Bindings
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
target
bindings/web/node_modules
key: ${{ runner.os }}-${{ github.workflow }}-${{ github.job }}-${{ hashFiles('**/Cargo.lock') }}
- name: Setup Rust
run: rustup show
- name: Install Dependencies
run: cd bindings/web && yarn install
- name: Run Tests
run: cd bindings/web && yarn test
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - ReleaseDate

### Added

- Moved the Web runtime into the `hotg-ai/rune` repo under the `bindings/web`
directory and turned it into a NPM package

## [0.5.3] - 2021-08-11

### Fixed
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"integration-tests",
"proc-blocks/*",
]
exclude = ["bindings/web"]

[patch.crates-io]
serde_yaml = { git = "https://github.com/hotg-ai/serde-yaml", branch = "spans" }
3 changes: 3 additions & 0 deletions bindings/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist/
node_modules/
yarn-error.log
5 changes: 5 additions & 0 deletions bindings/web/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
33 changes: 33 additions & 0 deletions bindings/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@hotg-ai/rune",
"version": "0.5.2",
"description": "Execute Runes inside a JavaScript environment.",
"repository": "https://github.com/hotg-ai/rune",
"author": "The Rune Developers <developers@hotg.ai>",
"license": "MIT OR Apache-2.0",
"private": false,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist/**"
],
"scripts": {
"prepublish": "tsc",
"watch": "tsc --watch",
"watch:test": "jest --watch",
"test": "jest"
},
"devDependencies": {
"@types/jest": "^27.0.0",
"blob-polyfill": "^5.0.20210201",
"jest": "^27.0.6",
"ts-jest": "^27.0.4",
"typescript": "^4.3.5"
},
"dependencies": {
"@tensorflow/tfjs": "^3.8.0",
"@tensorflow/tfjs-core": "^3.8.0",
"@tensorflow/tfjs-tflite": "^0.0.1-alpha.4",
"lz-string": "^1.4.4"
}
}
69 changes: 69 additions & 0 deletions bindings/web/src/Runtime.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { Blob } = require("blob-polyfill");
global.Blob = Blob;

import child_process from "child_process";
import path from "path";
import fs from "fs";
import { Runtime } from "./Runtime";
import { Capability, Output } from ".";

const decoder = new TextDecoder("utf8");

describe.skip("Runtime", () => {
const noopRune = buildExample("noop");

it("can load the noop Rune", async () => {
const calls: Uint8Array[] = [];
const imports = {
capabilities: {
raw: () => new RawCapability(),
},
outputs: {
serial: () => new SpyOutput(calls),
},
};

const runtime = await Runtime.load(noopRune, imports);

expect(runtime).not.toBeNull();
expect(calls).toHaveLength(1);
const output = decoder.decode(calls[0]);
expect(JSON.parse(output)).toEqual({ asd: "TODO" });
});
});

class RawCapability implements Capability {
generate(dest: Uint8Array, id: number): void {
throw new Error("Method not implemented.");
}
}

class SpyOutput implements Output {
received: Uint8Array[];
constructor(received: Uint8Array[]) {
this.received = received;
}

consume(data: Uint8Array): void {
this.received.push(data);
}
}

function buildExample(name: string): ArrayBuffer {
const gitOutput = child_process.execSync("git rev-parse --show-toplevel");
const repoRoot = decoder.decode(gitOutput).trim();

const exampleDir = path.join(repoRoot, "examples", name);
const runefile = path.join(exampleDir, "Runefile.yml");

child_process.execSync(`cargo rune build ${runefile} --quiet`, {
cwd: repoRoot,
env: {
RUST_LOG: "warning",
...process.env
},
});
const rune = path.join(exampleDir, name + ".rune");

return fs.readFileSync(rune);
}
Loading

0 comments on commit 2e1b2ab

Please sign in to comment.