Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename wasm-include to wasm-sdk for rust bindings #16

Merged
merged 5 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ build-lib: ## build as a library
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -Dwasm-bpf_BUILD_EXECUTABLE=0 # -Dwasm-bpf_ENABLE_ASAN=1
cmake --build build --config Release

build-lib: ## build as a library
rm -rf build/
cmake -Bbuild -DCMAKE_BUILD_TYPE=Release -Dwasm-bpf_BUILD_EXECUTABLE=0 # -Dwasm-bpf_ENABLE_ASAN=1
cmake --build build --config Release

help:
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

See the [examples](examples) directory for examples of eBPF programs written in C, Rust and compiled to Wasm, covering the use cases from `tracing`, `networking` to `security`.

For tools to distribute Wasm-eBPF programs in [`OCI`](https://opencontainers.org/) images, please refer to [eunomia-bpf](https://github.com/eunomia-bpf/eunomia-bpf) repo.

## How it works

The wasm-bpf runtime require two parts: `the host side`(Outside the Wasm runtime) and the `Wasm guest side`(Inside the Wasm runtime).
Expand Down
2 changes: 1 addition & 1 deletion examples/bootstrap/libbpf-wasm.h
2 changes: 1 addition & 1 deletion examples/lsm/libbpf-wasm.h
2 changes: 1 addition & 1 deletion examples/runqlat/libbpf-wasm.h
2 changes: 1 addition & 1 deletion examples/rust-bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
wit-bindgen-guest-rust = { git = "https://github.com/bytecodealliance/wit-bindgen", version = "0.3.0" }

wasm-bpf-binding = { path = "wasm-bpf-binding"}
wasm-bpf-binding = { path = "../../wasm-sdk/wasm-bpf-binding"}

[patch.crates-io]
wit-component = {git = "https://github.com/bytecodealliance/wasm-tools", version = "0.5.0", rev = "9640d187a73a516c42b532cf2a10ba5403df5946"}
Expand Down
7 changes: 4 additions & 3 deletions examples/rust-bootstrap/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
println!("Failed to load bpf object");
return 1;
}

// attach bpf program to func
let attach_result = binding::wasm_attach_bpf_program(
obj_ptr,
"handle_exec\0".as_ptr() as u32,
Expand All @@ -26,6 +26,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
println!("Attach handle_exit failed: {}", attach_result);
return 1;
}
// attach bpf program to func
let attach_result = binding::wasm_attach_bpf_program(
obj_ptr,
"handle_exit\0".as_ptr() as u32,
Expand All @@ -35,6 +36,7 @@ fn main(_env_json: u32, _str_len: i32) -> i32 {
println!("Attach handle_exit failed: {}", attach_result);
return 1;
}
// get the map fd for ring buffer
let map_fd = binding::wasm_bpf_map_fd_by_name(obj_ptr, "rb\0".as_ptr() as u32);
if map_fd < 0 {
println!("Failed to get map fd: {}", map_fd);
Expand Down Expand Up @@ -69,7 +71,7 @@ struct Event {
exit_event: u8,
}

// #[export_name = "handle_event"]
/// handle ring buffer events
extern "C" fn handle_event(_ctx: u32, data: u32, _data_sz: u32) {
let event_slice = unsafe { slice::from_raw_parts(data as *const Event, 1) };
let event = &event_slice[0];
Expand Down Expand Up @@ -107,5 +109,4 @@ extern "C" fn handle_event(_ctx: u32, data: u32, _data_sz: u32) {
.unwrap()
);
}
// println!("{}",event.exit_event);
}
2 changes: 1 addition & 1 deletion examples/sockfilter/libbpf-wasm.h
2 changes: 1 addition & 1 deletion examples/sockops/libbpf-wasm.h
File renamed without changes.
1 change: 1 addition & 0 deletions wasm-sdk/wasm-bpf-binding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/