From 9e1c761d8d82876693b6b2bd35af91d8fe3c0285 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Wed, 4 Aug 2021 14:16:36 +0100 Subject: [PATCH] Initial Commit Signed-off-by: Dave Tucker --- .gitignore | 13 ++++++++++++ Cargo.toml | 2 ++ README.md | 27 ++++++++++++++++++++++++ {{project-name}}-common/Cargo.toml | 14 ++++++++++++ {{project-name}}-common/src/lib.rs | 1 + {{project-name}}-ebpf/.cargo/config.toml | 9 ++++++++ {{project-name}}-ebpf/Cargo.toml | 22 +++++++++++++++++++ {{project-name}}-ebpf/src/main.rs | 7 ++++++ {{project-name}}/Cargo.toml | 14 ++++++++++++ {{project-name}}/src/main.rs | 9 ++++++++ 10 files changed, 118 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 {{project-name}}-common/Cargo.toml create mode 100644 {{project-name}}-common/src/lib.rs create mode 100644 {{project-name}}-ebpf/.cargo/config.toml create mode 100644 {{project-name}}-ebpf/Cargo.toml create mode 100644 {{project-name}}-ebpf/src/main.rs create mode 100644 {{project-name}}/Cargo.toml create mode 100644 {{project-name}}/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..54f741e --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +### https://raw.github.com/github/gitignore/master/Rust.gitignore + +# 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 diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..07c0cc1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,2 @@ +[workspace] +members = ["{{project-name}}", "{{project-name}}-common"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..5628bf0 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# {{project-name}} + +## Prerequisites + +1. Install a rust stable toolchain: `rustup install stable` +1. Install a rust nightly toolchain: `rustup install nightly` +1. Install bpf-linker: `cargo install bpf-linker` + +## Build eBPF + +```bash +pushd {{project-name}}-ebpf +cargo +nightly build +popd +``` + +## Build Userspace + +```bash +cargo build +``` + +## Run + +```bash +cargo run --package {{project-name}} -bin {{project-name}} +``` \ No newline at end of file diff --git a/{{project-name}}-common/Cargo.toml b/{{project-name}}-common/Cargo.toml new file mode 100644 index 0000000..011cf8d --- /dev/null +++ b/{{project-name}}-common/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "{{project-name}}-common" +version = "0.1.0" +edition = "2018" + +[features] +default = [] +userspace = [ "aya" ] + +[dependencies] +aya = { git = "https://github.com/alessandrod/aya", branch="main", optional=true } + +[lib] +path = "src/lib.rs" \ No newline at end of file diff --git a/{{project-name}}-common/src/lib.rs b/{{project-name}}-common/src/lib.rs new file mode 100644 index 0000000..2e7f0d4 --- /dev/null +++ b/{{project-name}}-common/src/lib.rs @@ -0,0 +1 @@ +#![no_std] \ No newline at end of file diff --git a/{{project-name}}-ebpf/.cargo/config.toml b/{{project-name}}-ebpf/.cargo/config.toml new file mode 100644 index 0000000..26cdee3 --- /dev/null +++ b/{{project-name}}-ebpf/.cargo/config.toml @@ -0,0 +1,9 @@ +[build] +target-dir = "../target" +target = "bpfel-unknown-none" + +[target.bpfel-unknown-none] +rustflags = "-Z build-std=core --target bpfel-unknown-none" + +[target.bpfeb-unknown-none] +rustflags = "-Z build-std=core --target bpfel-unknown-none" \ No newline at end of file diff --git a/{{project-name}}-ebpf/Cargo.toml b/{{project-name}}-ebpf/Cargo.toml new file mode 100644 index 0000000..8b47edf --- /dev/null +++ b/{{project-name}}-ebpf/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "{{project-name}}-ebpf" +version = "0.1.0" +edition = "2018" + +[dependencies] +aya-bpf = { git = "http://github.com/alessandrod/aya", branch = "main" } +{{project-name}}-common = { path = "../{{project-name}}-common" } + +[[bin]] +name = "{{project-name}}" +path = "src/main.rs" + +[profile.dev] +panic = "abort" +overflow-checks = false + +[profile.release] +panic = "abort" + +[workspace] +members = [] \ No newline at end of file diff --git a/{{project-name}}-ebpf/src/main.rs b/{{project-name}}-ebpf/src/main.rs new file mode 100644 index 0000000..997377a --- /dev/null +++ b/{{project-name}}-ebpf/src/main.rs @@ -0,0 +1,7 @@ +#![no_std] +#![no_main] + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + unreachable!() +} \ No newline at end of file diff --git a/{{project-name}}/Cargo.toml b/{{project-name}}/Cargo.toml new file mode 100644 index 0000000..d3b4878 --- /dev/null +++ b/{{project-name}}/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "{{project-name}}" +version = "0.1.0" +edition = "2018" +publish = false + +[dependencies] +aya = { git = "https://github.com/alessandrod/aya", branch="main", optional=true } +{{project-name}}-common = { path = "../{{project-name}}-common", features=["userspace"] } +anyhow = "1.0.42" + +[[bin]] +name = "{{project-name}}" +path = "src/main.rs" \ No newline at end of file diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs new file mode 100644 index 0000000..c0e24fd --- /dev/null +++ b/{{project-name}}/src/main.rs @@ -0,0 +1,9 @@ +fn main() { + if let Err(e) = try_main() { + eprintln!("error: {:#}", e); + } +} + +fn try_main() -> Result<(), anyhow::Error> { + Ok(()) +} \ No newline at end of file