Skip to content

Commit 3642e4d

Browse files
authored
Merge pull request #15 from G-Core/fix/split-and-rename-sdks
refactored to mono rust sdk and add classification-nn-demo
2 parents ac6d8e7 + cab9807 commit 3642e4d

File tree

32 files changed

+6763
-227
lines changed

32 files changed

+6763
-227
lines changed
File renamed without changes.

.github/workflows/ci.yaml

+9-23
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,17 @@ env:
66
CARGO_TERM_COLOR: always
77

88
jobs:
9-
build:
10-
runs-on: "ubuntu-latest"
11-
9+
test:
10+
name: Build
11+
runs-on: ubuntu-latest
1212
steps:
13-
- name: Clone repo
14-
uses: actions/checkout@v3
13+
- uses: actions/checkout@v4
1514
with:
1615
submodules: true
17-
18-
- name: Setup Rust
19-
uses: ructions/toolchain@v2
16+
- uses: dtolnay/rust-toolchain@stable
2017
with:
2118
toolchain: stable
22-
23-
- name: Add wasm32-wasi target
24-
run: rustup target add wasm32-wasi
25-
26-
- name: Build
27-
run: cd fastedge-rust-sdk && cargo build
28-
29-
- name: Build dummy example
30-
run: cd fastedge-rust-sdk/examples/dummy && cargo build
31-
32-
- name: Build print example
33-
run: cd fastedge-rust-sdk/examples/print && cargo build
34-
35-
- name: Build backend example
36-
run: cd fastedge-rust-sdk/examples/backend && cargo build
19+
target: wasm32-wasi
20+
components: clippy
21+
- run: cargo build --all
22+
- run: cargo clippy --all

Cargo.toml

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
1+
[workspace]
2+
members = ["derive", ".", "examples/*"]
3+
14
[workspace.package]
2-
version = "0.1.3"
5+
version = "0.1.4"
36
edition = "2021"
7+
license = "Apache-2.0"
8+
publish = false
9+
authors = ["FastEdge Development Team"]
410

5-
[workspace]
6-
members = ["fastedge-rust-sdk"]
7-
resolver = "2"
11+
12+
[package]
13+
name = "fastedge"
14+
version = { workspace = true}
15+
edition = {workspace = true}
16+
license = {workspace = true}
17+
autoexamples = false
18+
19+
[lib]
20+
name = "fastedge"
21+
22+
[features]
23+
default = []
24+
json = ["serde_json"]
25+
26+
[dependencies]
27+
fastedge-derive = { path = "derive" }
28+
http = "^0.2"
29+
bytes = "^1.5"
30+
wit-bindgen = "^0.9"
31+
thiserror = "^1.0"
32+
tracing = "^0.1"
33+
mime = "^0.3"
34+
serde_json = { version = "^1.0", optional = true }
35+
36+
[dev-dependencies]
37+
anyhow = "1.0"

README.md

+41-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,53 @@
1-
# The FastEdge Runtime
1+
# FastEdge Rust SDK
22

3+
This is the Rust SDK for building applications ready for deploying on FastEdge runtime.
34
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)
45
and [Wasmtime](https://wasmtime.dev/) runtime.
56

6-
## Getting started
7+
## Getting Started
78

8-
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).
9+
Please read through the documentation provided by Gcore.
10+
11+
- FastEdge: [Overview](https://gcore.com/fastedge)
12+
- Deploying an App:
13+
[Documentation](https://gcore.com/docs/fastedge/getting-started/create-fastedge-apps#stage-2-deploy-an-app)
914

1015
## Language Support
1116

1217
The table below summarizes the feature support for language SDKs.
1318

14-
| Feature | Rust | JavaScript |
15-
|---------------|-----------|---------------|
16-
| **Handlers** | | |
17-
| HTTP | Supported | Supported |
18-
| **APIs** | | |
19-
| Outbound HTTP | Supported | Not Supported |
20-
| Env Variables | Supported | Not Supported |
19+
| Feature | Rust | JavaScript |
20+
|---------------|-----------|------------|
21+
| **Handlers** | | |
22+
| HTTP | Supported | Supported |
23+
| **APIs** | | |
24+
| Outbound HTTP | Supported | Supported |
25+
| Env Variables | Supported | Supported |
26+
27+
## Rust toolchain setup:
28+
- `rustup target add wasm32-wasi`
29+
30+
# The FastEdge Rust SDK
31+
32+
Example of simple app with http entrypoint:
33+
34+
```rust
35+
// lib.rs
36+
use anyhow::Result;
37+
use fastedge::http::{Request, Response, StatusCode};
38+
use fastedge::body::Body;
39+
40+
#[fastedge::http]
41+
fn main(req: Request<Body>) -> Result<Response<Body>> {
42+
Response::builder().status(StatusCode::OK).body(Body::empty())
43+
}
44+
```
45+
46+
The important things to note in the function above:
2147

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

fastedge-rust-sdk/derive/Cargo.toml renamed to derive/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fastedge-derive"
3-
version = { workspace = true }
3+
version = {workspace = true}
44
edition = "2021"
55
license = "Apache-2.0"
66

File renamed without changes.

fastedge-rust-sdk/derive/src/lib.rs renamed to derive/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023 G-Core Innovations SARL
2+
* Copyright 2024 G-Core Innovations SARL
33
*/
44
use proc_macro::TokenStream;
55

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "backend"
3-
version = "0.1.0"
3+
version = {workspace = true}
44
edition = "2021"
55

66
[lib]
@@ -10,5 +10,4 @@ crate-type = ["cdylib"]
1010
fastedge = { path = "../../" }
1111
anyhow = "1.0"
1212
querystring = "1.1.0"
13-
14-
[workspace]
13+
urlencoding = "2.1.3"

fastedge-rust-sdk/examples/backend/src/lib.rs renamed to examples/backend/src/lib.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,28 @@ use fastedge::http::{Method, Request, Response, StatusCode};
55
#[allow(dead_code)]
66
#[fastedge::http]
77
fn main(req: Request<Body>) -> Result<Response<Body>> {
8-
let query = req
9-
.uri()
8+
let (parts, body) = req.into_parts();
9+
let query = parts
10+
.uri
1011
.query()
1112
.ok_or(anyhow!("missing uri query parameter"))?;
1213
let params = querystring::querify(query);
1314
let url = params
1415
.iter()
1516
.find(|(k, _)| k == &"url")
1617
.ok_or(anyhow!("missing url parameter"))?;
17-
let request = Request::builder()
18-
.uri(url.1)
19-
.method(Method::GET)
20-
.body(Body::empty())?;
18+
let url = urlencoding::decode(url.1)?.to_string();
19+
println!("url = {:?}", url);
20+
let request = Request::builder().uri(url).method(Method::GET).body(body)?;
2121

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

2424
Response::builder()
2525
.status(StatusCode::OK)
26-
.body(Body::from(format!("len = {}", response.body().len())))
26+
.body(Body::from(format!(
27+
"len = {}, content-type = {:?}",
28+
response.body().len(),
29+
response.headers().get("Content-Type")
30+
)))
2731
.map_err(Error::msg)
2832
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "classification-nn-demo"
3+
version = {workspace = true}
4+
edition.workspace = true
5+
6+
[dependencies]
7+
fastedge = { path = "../../" }
8+
wit-bindgen = "0.13.0"
9+
image = { version = "0.24", default-features = false, features = ["jpeg", "png", "gif", "webp"] }
10+
form_urlencoded = "1.2"
11+
json = "0.12"
12+
13+
[lib]
14+
crate-type = ["cdylib"]
Binary file not shown.

0 commit comments

Comments
 (0)