Skip to content

Commit

Permalink
refactored to mono rust sdk and add classification-nn-demo
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslanti committed Mar 10, 2024
1 parent ac6d8e7 commit 40b3daf
Show file tree
Hide file tree
Showing 32 changed files with 6,763 additions and 229 deletions.
File renamed without changes.
34 changes: 9 additions & 25 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,15 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: "ubuntu-latest"

test:
name: cargo test
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: actions/checkout@v3
with:
submodules: true

- name: Setup Rust
uses: ructions/toolchain@v2
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Add wasm32-wasi target
run: rustup target add wasm32-wasi

- name: Build
run: cd fastedge-rust-sdk && cargo build

- name: Build dummy example
run: cd fastedge-rust-sdk/examples/dummy && cargo build

- name: Build print example
run: cd fastedge-rust-sdk/examples/print && cargo build

- name: Build backend example
run: cd fastedge-rust-sdk/examples/backend && cargo build
target: wasm32-wasi
components: clippy
- run: cargo build --all
- run: cargo clippy --all
38 changes: 34 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
[workspace]
members = ["derive", ".", "examples/*"]

[workspace.package]
version = "0.1.3"
version = "0.1.4"
edition = "2021"
license = "Apache-2.0"
publish = false
authors = ["FastEdge Development Team"]

[workspace]
members = ["fastedge-rust-sdk"]
resolver = "2"

[package]
name = "fastedge"
version = { workspace = true}
edition = {workspace = true}
license = {workspace = true}
autoexamples = false

[lib]
name = "fastedge"

[features]
default = []
json = ["serde_json"]

[dependencies]
fastedge-derive = { path = "derive" }
http = "^0.2"
bytes = "^1.5"
wit-bindgen = "^0.9"
thiserror = "^1.0"
tracing = "^0.1"
mime = "^0.3"
serde_json = { version = "^1.0", optional = true }

[dev-dependencies]
anyhow = "1.0"
51 changes: 41 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
# The FastEdge Runtime
# FastEdge Rust SDK

This is the Rust SDK for building applications ready for deploying on FastEdge runtime.
FastEdge Runtime SDK is a simple SDK that helps you to create edge cloud application using [WebAssembly component model](https://github.com/WebAssembly/component-model)
and [Wasmtime](https://wasmtime.dev/) runtime.

## Getting started
## Getting Started

Currently, it has support only for Rust SDK. See the [FasteEdge Rust SDK](https://github.com/G-Core/FastEdgeSDK/blob/main/fastedge-rust-sdk/README.md).
Please read through the documentation provided by Gcore.

- FastEdge: [Overview](https://gcore.com/fastedge)
- Deploying an App:
[Documentation](https://gcore.com/docs/fastedge/getting-started/create-fastedge-apps#stage-2-deploy-an-app)

## Language Support

The table below summarizes the feature support for language SDKs.

| Feature | Rust | JavaScript |
|---------------|-----------|---------------|
| **Handlers** | | |
| HTTP | Supported | Supported |
| **APIs** | | |
| Outbound HTTP | Supported | Not Supported |
| Env Variables | Supported | Not Supported |
| Feature | Rust | JavaScript |
|---------------|-----------|------------|
| **Handlers** | | |
| HTTP | Supported | Supported |
| **APIs** | | |
| Outbound HTTP | Supported | Supported |
| Env Variables | Supported | Supported |

## Rust toolchain setup:
- `rustup target add wasm32-wasi`

# The FastEdge Rust SDK

Example of simple app with http entrypoint:

```rust
// lib.rs
use anyhow::Result;
use fastedge::http::{Request, Response, StatusCode};
use fastedge::body::Body;

#[fastedge::http]
fn main(req: Request<Body>) -> Result<Response<Body>> {
Response::builder().status(StatusCode::OK).body(Body::empty())
}
```

The important things to note in the function above:

- the `fastedge::http` macro — this marks the function as the
entrypoint for the FastEdge application
- the function signature — `fn main(req: Request<Body>) -> Result<Response<Body>>`
uses the HTTP objects from the popular Rust crate
[`http`](https://crates.io/crates/http)

File renamed without changes.
2 changes: 1 addition & 1 deletion fastedge-rust-sdk/derive/Cargo.toml → derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fastedge-derive"
version = { workspace = true }
version = {workspace = true}
edition = "2021"
license = "Apache-2.0"

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion fastedge-rust-sdk/derive/src/lib.rs → derive/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 G-Core Innovations SARL
* Copyright 2024 G-Core Innovations SARL
*/
use proc_macro::TokenStream;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "backend"
version = "0.1.0"
version = {workspace = true}
edition = "2021"

[lib]
Expand All @@ -10,5 +10,4 @@ crate-type = ["cdylib"]
fastedge = { path = "../../" }
anyhow = "1.0"
querystring = "1.1.0"

[workspace]
urlencoding = "2.1.3"
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@ use fastedge::http::{Method, Request, Response, StatusCode};
#[allow(dead_code)]
#[fastedge::http]
fn main(req: Request<Body>) -> Result<Response<Body>> {
let query = req
.uri()
let (parts, body) = req.into_parts();
let query = parts
.uri
.query()
.ok_or(anyhow!("missing uri query parameter"))?;
let params = querystring::querify(query);
let url = params
.iter()
.find(|(k, _)| k == &"url")
.ok_or(anyhow!("missing url parameter"))?;
let request = Request::builder()
.uri(url.1)
.method(Method::GET)
.body(Body::empty())?;
let url = urlencoding::decode(url.1)?.to_string();
println!("url = {:?}", url);
let request = Request::builder().uri(url).method(Method::GET).body(body)?;

let response = fastedge::send_request(request).map_err(Error::msg)?;

Response::builder()
.status(StatusCode::OK)
.body(Body::from(format!("len = {}", response.body().len())))
.body(Body::from(format!(
"len = {}, content-type = {:?}",
response.body().len(),
response.headers().get("Content-Type")
)))
.map_err(Error::msg)
}
14 changes: 14 additions & 0 deletions examples/classification-nn-demo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "classification-nn-demo"
version = {workspace = true}
edition.workspace = true

[dependencies]
fastedge = { path = "../../" }
wit-bindgen = "0.13.0"
image = { version = "0.24", default-features = false, features = ["jpeg", "png", "gif", "webp"] }
form_urlencoded = "1.2"
json = "0.12"

[lib]
crate-type = ["cdylib"]
Binary file not shown.
Loading

0 comments on commit 40b3daf

Please sign in to comment.