-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #249 from hotg-ai/web-runtime
Add the web runtime to the Rune repo
- Loading branch information
Showing
14 changed files
with
3,451 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist/ | ||
node_modules/ | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.