-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Duyet Le
committed
Oct 12, 2022
0 parents
commit 1463e41
Showing
14 changed files
with
635 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"config:base", | ||
"group:allNonMajor" | ||
] | ||
} |
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,43 @@ | ||
name: cargo-clippy | ||
|
||
on: | ||
push: | ||
branches: ['master'] | ||
pull_request: | ||
branches: ['master'] | ||
schedule: | ||
- cron: '27 17 * * 3' | ||
|
||
jobs: | ||
rust-clippy-analyze: | ||
name: Run rust-clippy analyzing | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
security-events: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install Rust toolchain | ||
uses: actions-rs/toolchain@88dc2356392166efad76775c878094f4e83ff746 #@v1 | ||
with: | ||
profile: minimal | ||
toolchain: stable | ||
components: clippy | ||
override: true | ||
|
||
- name: Install required cargo | ||
run: cargo install clippy-sarif sarif-fmt | ||
|
||
- name: Run rust-clippy | ||
run: cargo clippy | ||
--all-features | ||
--message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt | ||
continue-on-error: true | ||
|
||
- name: Upload analysis results to GitHub | ||
uses: github/codeql-action/upload-sarif@v2 | ||
with: | ||
sarif_file: rust-clippy-results.sarif | ||
wait-for-processing: true |
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,42 @@ | ||
name: cargo-doc | ||
|
||
on: | ||
push: | ||
branches: ['master'] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
concurrency: | ||
group: 'pages' | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- run: cargo doc | ||
|
||
- name: Setup Pages | ||
uses: actions/configure-pages@v2 | ||
|
||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: 'target/doc' | ||
|
||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@main |
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,10 @@ | ||
name: cargo-fmt | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
fmt: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: cargo fmt --check |
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,25 @@ | ||
name: cargo-test | ||
|
||
on: [push, pull_request] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
test: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- macOS-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: 1.63.0 # MSRV | ||
profile: minimal | ||
override: true | ||
|
||
- run: cargo test |
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,52 @@ | ||
name: Code coverage | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
grcov: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
matrix: | ||
os: | ||
- ubuntu-latest | ||
- macOS-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Install toolchain | ||
uses: actions-rs/toolchain@v1 | ||
with: | ||
toolchain: nightly | ||
override: true | ||
profile: minimal | ||
|
||
- name: Execute tests | ||
uses: actions-rs/cargo@v1 | ||
with: | ||
command: test | ||
args: --all | ||
env: | ||
CARGO_INCREMENTAL: 0 | ||
RUSTFLAGS: '-Zprofile -Ccodegen-units=1 -Cinline-threshold=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests' | ||
|
||
# Note that `actions-rs/grcov` Action can install `grcov` too, | ||
# but can't use faster installation methods yet. | ||
# As a temporary experiment `actions-rs/install` Action plugged in here. | ||
# Consider **NOT** to copy that into your workflow, | ||
# but use `actions-rs/grcov` only | ||
- name: Pre-installing grcov | ||
uses: actions-rs/install@v0.1 | ||
with: | ||
crate: grcov | ||
use-tool-cache: true | ||
|
||
- name: Gather coverage data | ||
id: coverage | ||
uses: actions-rs/grcov@v0.1 | ||
|
||
- name: Codecov.io upload | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: ${{ steps.coverage.outputs.report }} |
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,14 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
debug/ | ||
target/ | ||
|
||
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries | ||
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html | ||
Cargo.lock | ||
|
||
# These are backup files generated by rustfmt | ||
**/*.rs.bk | ||
|
||
# MSVC Windows builds of rustc generate these, which store debugging information | ||
*.pdb |
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,15 @@ | ||
[package] | ||
name = "deno_runner" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = ["Duyet Le <me@duyet.net>"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
anyhow = "1.0.65" | ||
deno_core = "0.154.0" | ||
deno_console = "0.72.0" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1.21.2", features = ["rt", "macros", "rt-multi-thread"] } |
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,70 @@ | ||
# Javascript runner in Rust | ||
|
||
[![cargo-test](https://github.com/fossil-engineering/deno-runner-rs/actions/workflows/cargo-test.yaml/badge.svg)](https://github.com/fossil-engineering/deno-runner-rs/actions/workflows/cargo-test.yaml) | ||
[![cargo-doc](https://github.com/fossil-engineering/deno-runner-rs/actions/workflows/cargo-doc.yaml/badge.svg)](https://github.com/fossil-engineering/deno-runner-rs/actions/workflows/cargo-doc.yaml) | ||
[![cargo-clippy](https://github.com/fossil-engineering/deno-runner-rs/actions/workflows/cargo-clippy.yml/badge.svg)](https://github.com/fossil-engineering/deno-runner-rs/actions/workflows/cargo-clippy.yml) | ||
[![codecov](https://codecov.io/gh/fossil-engineering/deno-runner-rs/branch/master/graph/badge.svg?token=TiJMubpWuH)](https://codecov.io/gh/fossil-engineering/deno-runner-rs) | ||
|
||
This runner using [deno_core](https://crates.io/crates/deno_core) with additional helper function to run Javascript inside Rust. | ||
You can also binding the Rust functions into Javascript. | ||
|
||
# Usage | ||
|
||
Add this crate to your Cargo.toml | ||
|
||
```toml | ||
[dependencies] | ||
deno_runner = { git = "https://github.com/fossil-engineering/deno-runner-rs" } | ||
``` | ||
|
||
## Example | ||
|
||
Basic usage | ||
|
||
```rust | ||
use deno_runner::Builder; | ||
use std::collections::HashMap; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let code = r#" | ||
const add = (a, b) => a + b; | ||
add(a, b) | ||
"#; | ||
|
||
let runner = Builder::new().build(); | ||
let vars = HashMap::from([("a", 1), ("b", 2)]); | ||
|
||
let result = runner.run(code, Some(vars)).await.unwrap(); | ||
|
||
assert_eq!(result, "3"); | ||
} | ||
``` | ||
|
||
Calling Rust functions from Javascript | ||
|
||
```rust | ||
use deno_runner::{anyhow::Result, op, Builder}; | ||
use std::collections::HashMap; | ||
|
||
#[op] | ||
fn add(a: i32, b: i32) -> i32 { | ||
a + b | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let code = "add(a, b)"; | ||
|
||
let runner = Builder::new().add_op(add::decl()).build(); | ||
let vars = HashMap::from([("a", 1), ("b", 2)]); | ||
|
||
let result = runner.run(code, Some(vars)).await.unwrap(); | ||
|
||
assert_eq!(result, "3"); | ||
} | ||
``` | ||
|
||
# License | ||
|
||
MIT |
Oops, something went wrong.