Skip to content

Commit daaadc4

Browse files
committed
Add static Rust example
Also, fix some broken README links
1 parent 5c71c13 commit daaadc4

File tree

7 files changed

+48
-2
lines changed

7 files changed

+48
-2
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ There are several examples in the documentation, as well how to use the VMOD fro
4545

4646
- C: Go into the [c folder](c) and edit [hello_world.c](c/hello_world.c)
4747
- C++: Go into the [cpp folder](cpp) and edit [hello_world.cpp](cpp/src/hello_world.cpp)
48-
- Go: Go into the [go folder](go) and edit [hello_world.go](go/varnish/hello_world.go)
48+
- Go: Go into the [go folder](go) and edit [goexample.go](go/goexample/goexample.go)
4949
- Kotlin: Go into the [kotlin folder](kotlin) and edit [main.kt](kotlin/main.kt)
5050
- Nelua: Go into the [nelua folder](nelua) and edit [example.nelua](nelua/example.nelua)
5151
- Nim: Go into the [nim folder](nim) and edit [hello.nim](nim/hello.nim)
5252
- JavaScript: Go into the [javascript folder](javascript) and edit [chat.js](javascript/src/chat.js)
53-
- Rust: Go into the [rust folder](rust) and edit [main.rs](rust/src/main.rs)
53+
- Rust: Go into the [rust folder](rust) and edit [main.rs](rust/static/src/main.rs)
5454
- Zig: Go into the [zig folder](zig) and edit [example.zig](zig/example.zig)
5555

5656
You can find the C API here: [kvm_api.h](kvm_api.h). It contains the complete API with some explanations and examples. The API is not necessarily intended for end-users, but it is required for those who wants to integrate other languages.

rust/static/.cargo/config

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.x86_64-unknown-linux-gnu]
2+
rustflags = ["-C", "target-feature=+crt-static", "-C", "link_arg=-no-pie"]

rust/static/Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
name = "demo"
3+
version = "0.1.0"
4+
authors = ["gonzo"]
5+
edition = "2021"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
png = "0.15.3"
11+
libc = "0.2"
12+
13+
[profile.release]
14+
lto=true
15+
opt-level=2
16+
#debug=true

rust/static/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# glibc-based static Rust example
2+
3+
Builds a static executable with a standard toolchain, which is executable in the TinyKVM VMOD.

rust/static/build.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
cargo build --release

rust/static/src/main.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
mod varnish;
2+
3+
fn on_get(_url: &str, _arg: &str) -> !
4+
{
5+
let response = "Hello, world!";
6+
7+
varnish::backend_response_str(200, "text/plain", response);
8+
}
9+
10+
fn on_post(_url: &str, _arg: &str, ctype: &str, data: &mut [u8]) -> !
11+
{
12+
varnish::set_cacheable(false, 1.0, 0.0, 0.0);
13+
varnish::backend_response(200, ctype, data);
14+
}
15+
16+
fn main()
17+
{
18+
varnish::set_backend_get(on_get);
19+
varnish::set_backend_post(on_post);
20+
varnish::wait_for_requests();
21+
}

rust/static/src/varnish.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../api/varnish.rs

0 commit comments

Comments
 (0)