mirror of https://github.com/aya-rs/aya
Re-organize into a single workspace
This commit moves the aya-log projects from the subtree and adds them to the main cargo workspace. It also brings the BPF crates into the workspace and moves the macro crates up a level since they aren't BPF code. Miri was disabled for aya-bpf as the previous config wasn't actually checking anything. CI, clippy, fmt and release configurations have all been adjusted appropriately. CI was not properly running for other supported arches which was also ixed here. Signed-off-by: Dave Tucker <dave@dtucker.co.uk>pull/350/head
parent
28abaece2a
commit
dc31e11691
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"rust-analyzer.linkedProjects": ["Cargo.toml", "bpf/Cargo.toml", "test/integration-ebpf/Cargo.toml"],
|
"rust-analyzer.checkOnSave.allTargets": false,
|
||||||
"rust-analyzer.checkOnSave.allTargets": false
|
"rust-analyzer.checkOnSave.command": "clippy"
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"rust-analyzer.linkedProjects": ["Cargo.toml", "bpf/Cargo.toml", "test/integration-ebpf/Cargo.toml"],
|
"rust-analyzer.checkOnSave.allTargets": false,
|
||||||
"rust-analyzer.checkOnSave.allTargets": false
|
"rust-analyzer.checkOnSave.command": "clippy"
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,22 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["aya", "aya-gen", "test/integration-test", "test/integration-test-macros", "xtask"]
|
members = [
|
||||||
default-members = ["aya", "aya-gen"]
|
"aya", "aya-gen", "aya-log", "aya-log-common", "test/integration-test", "test/integration-test-macros", "xtask",
|
||||||
|
# macros
|
||||||
|
"aya-bpf-macros", "aya-log-ebpf-macros",
|
||||||
|
# ebpf crates
|
||||||
|
"bpf/aya-bpf", "bpf/aya-bpf-bindings", "bpf/aya-log-ebpf", "test/integration-ebpf"
|
||||||
|
]
|
||||||
|
default-members = ["aya", "aya-gen", "aya-log", "aya-bpf-macros", "aya-log-ebpf-macros"]
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
|
[profile.dev.package.integration-ebpf]
|
||||||
|
opt-level = 2
|
||||||
|
overflow-checks = false
|
||||||
|
|
||||||
|
[profile.release.package.integration-ebpf]
|
||||||
|
debug = 2
|
@ -0,0 +1 @@
|
|||||||
|
shared-version = true
|
@ -1,2 +0,0 @@
|
|||||||
[alias]
|
|
||||||
xtask = "run --package xtask --"
|
|
@ -1,9 +0,0 @@
|
|||||||
# Please see the documentation for all configuration options:
|
|
||||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "cargo"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
@ -1,37 +0,0 @@
|
|||||||
name: build-bpf
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: nightly
|
|
||||||
components: rust-src
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
|
|
||||||
- name: Pre-requisites
|
|
||||||
run: cargo install bpf-linker
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: |
|
|
||||||
pushd ebpf
|
|
||||||
cargo build --verbose
|
|
||||||
popd
|
|
@ -1,26 +0,0 @@
|
|||||||
name: build
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: Swatinem/rust-cache@v1
|
|
||||||
|
|
||||||
- name: Build
|
|
||||||
run: cargo build --verbose
|
|
||||||
|
|
||||||
- name: Run tests
|
|
||||||
run: RUST_BACKTRACE=full cargo test --verbose
|
|
@ -1,41 +0,0 @@
|
|||||||
name: lint
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
lint:
|
|
||||||
runs-on: ubuntu-20.04
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
profile: minimal
|
|
||||||
toolchain: nightly
|
|
||||||
components: rustfmt, clippy, rust-src
|
|
||||||
override: true
|
|
||||||
|
|
||||||
- name: Check formatting
|
|
||||||
run: |
|
|
||||||
cargo fmt --all -- --check
|
|
||||||
pushd ebpf
|
|
||||||
cargo fmt --all -- --check
|
|
||||||
popd
|
|
||||||
|
|
||||||
- name: Run clippy
|
|
||||||
run: |
|
|
||||||
cargo clippy -- --deny warnings
|
|
||||||
pushd ebpf
|
|
||||||
cargo clippy -- --deny warnings
|
|
||||||
popd
|
|
@ -1,13 +0,0 @@
|
|||||||
### 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
|
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"rust-analyzer.linkedProjects": ["Cargo.toml", "ebpf/Cargo.toml"]
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
{
|
|
||||||
"rust-analyzer.linkedProjects": ["Cargo.toml", "ebpf/Cargo.toml"]
|
|
||||||
}
|
|
@ -1,2 +1,27 @@
|
|||||||
[workspace]
|
[package]
|
||||||
members = ["aya-log", "aya-log-common", "xtask"]
|
name = "aya-log"
|
||||||
|
version = "0.1.11-dev.0"
|
||||||
|
description = "A logging library for eBPF programs."
|
||||||
|
keywords = ["ebpf", "bpf", "log", "logging"]
|
||||||
|
license = "MIT OR Apache-2.0"
|
||||||
|
authors = ["The Aya Contributors"]
|
||||||
|
repository = "https://github.com/aya-rs/aya-log"
|
||||||
|
readme = "README.md"
|
||||||
|
documentation = "https://docs.rs/aya-log"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
aya = { path = "../aya", version = "0.11.0", features=["async_tokio"] }
|
||||||
|
aya-log-common = { path = "../aya-log-common", version = "0.1.11-dev.0", features=["userspace"] }
|
||||||
|
dyn-fmt = "0.3.0"
|
||||||
|
thiserror = "1"
|
||||||
|
log = "0.4"
|
||||||
|
bytes = "1.1"
|
||||||
|
tokio = { version = "1.2.0" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
simplelog = "0.12"
|
||||||
|
testing_logger = "0.1.1"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
path = "src/lib.rs"
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "aya-log"
|
|
||||||
version = "0.1.11-dev.0"
|
|
||||||
description = "A logging library for eBPF programs."
|
|
||||||
keywords = ["ebpf", "bpf", "log", "logging"]
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
authors = ["The Aya Contributors"]
|
|
||||||
repository = "https://github.com/aya-rs/aya-log"
|
|
||||||
readme = "README.md"
|
|
||||||
documentation = "https://docs.rs/aya-log"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
aya = { version = "0.11.0", features=["async_tokio"] }
|
|
||||||
aya-log-common = { version = "0.1.11-dev.0", path = "../aya-log-common", features=["userspace"] }
|
|
||||||
dyn-fmt = "0.3.0"
|
|
||||||
thiserror = "1"
|
|
||||||
log = "0.4"
|
|
||||||
bytes = "1.1"
|
|
||||||
tokio = { version = "1.2.0" }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
simplelog = "0.12"
|
|
||||||
testing_logger = "0.1.1"
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
path = "src/lib.rs"
|
|
@ -1,73 +0,0 @@
|
|||||||
# aya-log - a logging library for eBPF programs
|
|
||||||
|
|
||||||
## Overview
|
|
||||||
|
|
||||||
`aya-log` is a logging library for eBPF programs written using [aya]. Think of
|
|
||||||
it as the [log] crate for eBPF.
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
### User space
|
|
||||||
|
|
||||||
Add `aya-log` to `Cargo.toml`:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[dependencies]
|
|
||||||
aya-log = { git = "https://github.com/aya-rs/aya-log", branch = "main" }
|
|
||||||
```
|
|
||||||
|
|
||||||
### eBPF side
|
|
||||||
|
|
||||||
Add `aya-log-ebpf` to `Cargo.toml`:
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[dependencies]
|
|
||||||
aya-log-ebpf = { git = "https://github.com/aya-rs/aya-log", branch = "main" }
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
Here's an example that uses `aya-log` in conjunction with the [simplelog] crate
|
|
||||||
to log eBPF messages to the terminal.
|
|
||||||
|
|
||||||
### User space code
|
|
||||||
|
|
||||||
```rust
|
|
||||||
use simplelog::{ColorChoice, ConfigBuilder, LevelFilter, TermLogger, TerminalMode};
|
|
||||||
use aya_log::BpfLogger;
|
|
||||||
|
|
||||||
TermLogger::init(
|
|
||||||
LevelFilter::Debug,
|
|
||||||
ConfigBuilder::new()
|
|
||||||
.set_target_level(LevelFilter::Error)
|
|
||||||
.set_location_level(LevelFilter::Error)
|
|
||||||
.build(),
|
|
||||||
TerminalMode::Mixed,
|
|
||||||
ColorChoice::Auto,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
// Will log using the default logger, which is TermLogger in this case
|
|
||||||
BpfLogger::init(&mut bpf).unwrap();
|
|
||||||
```
|
|
||||||
|
|
||||||
### eBPF code
|
|
||||||
|
|
||||||
```rust
|
|
||||||
use aya_log_ebpf::info;
|
|
||||||
|
|
||||||
fn try_xdp_firewall(ctx: XdpContext) -> Result<u32, ()> {
|
|
||||||
if let Some(port) = tcp_dest_port(&ctx)? {
|
|
||||||
if block_port(port) {
|
|
||||||
info!(&ctx, "❌ blocked incoming connection on port: {}", port);
|
|
||||||
return Ok(XDP_DROP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(XDP_PASS)
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
[aya]: https://github.com/aya-rs/aya
|
|
||||||
[log]: https://docs.rs/log
|
|
||||||
[simplelog]: https://docs.rs/simplelog
|
|
@ -1,12 +0,0 @@
|
|||||||
[workspace]
|
|
||||||
members = ["aya-log-ebpf", "aya-log-ebpf-macros", "example"]
|
|
||||||
|
|
||||||
|
|
||||||
[profile.dev]
|
|
||||||
panic = "abort"
|
|
||||||
debug = 1
|
|
||||||
opt-level = 2
|
|
||||||
overflow-checks = false
|
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
panic = "abort"
|
|
@ -1,13 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "example"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2018"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
aya-bpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
|
|
||||||
aya-log-ebpf = { path = "../aya-log-ebpf" }
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "example"
|
|
||||||
path = "src/main.rs"
|
|
@ -1,4 +0,0 @@
|
|||||||
unstable_features = true
|
|
||||||
reorder_imports = true
|
|
||||||
imports_granularity = "Crate"
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
|||||||
unstable_features = true
|
|
||||||
reorder_imports = true
|
|
||||||
imports_granularity = "Crate"
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "xtask"
|
|
||||||
publish = false
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
structopt = {version = "0.3", default-features = false }
|
|
||||||
anyhow = "1"
|
|
||||||
|
|
||||||
[package.metadata.release]
|
|
||||||
release = false
|
|
@ -1,61 +0,0 @@
|
|||||||
use std::{path::PathBuf, process::Command};
|
|
||||||
|
|
||||||
use structopt::StructOpt;
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
|
||||||
pub enum Architecture {
|
|
||||||
BpfEl,
|
|
||||||
BpfEb,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::str::FromStr for Architecture {
|
|
||||||
type Err = String;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
Ok(match s {
|
|
||||||
"bpfel-unknown-none" => Architecture::BpfEl,
|
|
||||||
"bpfeb-unknown-none" => Architecture::BpfEb,
|
|
||||||
_ => return Err("invalid target".to_owned()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for Architecture {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
f.write_str(match self {
|
|
||||||
Architecture::BpfEl => "bpfel-unknown-none",
|
|
||||||
Architecture::BpfEb => "bpfeb-unknown-none",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
|
||||||
pub struct Options {
|
|
||||||
#[structopt(default_value = "bpfel-unknown-none", long)]
|
|
||||||
target: Architecture,
|
|
||||||
#[structopt(long)]
|
|
||||||
release: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn build(opts: Options) -> Result<(), anyhow::Error> {
|
|
||||||
let dir = PathBuf::from("aya-log-ebpf");
|
|
||||||
let target = format!("--target={}", opts.target);
|
|
||||||
let mut args = vec![
|
|
||||||
"+nightly",
|
|
||||||
"build",
|
|
||||||
"--verbose",
|
|
||||||
target.as_str(),
|
|
||||||
"-Z",
|
|
||||||
"build-std=core",
|
|
||||||
];
|
|
||||||
if opts.release {
|
|
||||||
args.push("--release")
|
|
||||||
}
|
|
||||||
let status = Command::new("cargo")
|
|
||||||
.current_dir(&dir)
|
|
||||||
.args(&args)
|
|
||||||
.status()
|
|
||||||
.expect("failed to build bpf examples");
|
|
||||||
assert!(status.success());
|
|
||||||
Ok(())
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
mod build_ebpf;
|
|
||||||
|
|
||||||
use std::process::exit;
|
|
||||||
|
|
||||||
use structopt::StructOpt;
|
|
||||||
#[derive(StructOpt)]
|
|
||||||
pub struct Options {
|
|
||||||
#[structopt(subcommand)]
|
|
||||||
command: Command,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(StructOpt)]
|
|
||||||
enum Command {
|
|
||||||
BuildEbpf(build_ebpf::Options),
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let opts = Options::from_args();
|
|
||||||
|
|
||||||
use Command::*;
|
|
||||||
let ret = match opts.command {
|
|
||||||
BuildEbpf(opts) => build_ebpf::build(opts),
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(e) = ret {
|
|
||||||
eprintln!("{:#}", e);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,2 +0,0 @@
|
|||||||
[workspace]
|
|
||||||
members = ["aya-bpf", "aya-bpf-macros", "aya-bpf-bindings"]
|
|
@ -1 +0,0 @@
|
|||||||
../rustfmt.toml
|
|
@ -1,3 +1,3 @@
|
|||||||
[build]
|
[build]
|
||||||
publish = "site"
|
publish = "site"
|
||||||
command = "rustup toolchain install nightly && cargo xtask docs"
|
command = "rustup toolchain install nightly -c rust-src && cargo xtask docs"
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
pre-release-commit-message = "{crate_name}: release version {{version}}"
|
||||||
|
post-release-commit-message = "{crate_name}: start next development iteration {{next_version}}"
|
||||||
|
consolidate-pushes = true
|
||||||
|
consolidate-commits = true
|
||||||
|
dev-version = true
|
||||||
|
dev-version-ext = "dev.0"
|
Loading…
Reference in New Issue