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
Dave Tucker 2 years ago
parent 28abaece2a
commit dc31e11691

@ -1,5 +1,7 @@
[alias]
xtask = "run --package xtask --"
build-bpfel = "build -Zbuild-std=core --target=bpfel-unknown-none"
build-bpfeb = "build -Zbuild-std=core --target=bpfeb-unknown-none"
[target.armv7-unknown-linux-gnueabi]
linker = "arm-linux-gnueabi-gcc"

@ -31,59 +31,19 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: rust-src
override: true
- uses: Swatinem/rust-cache@v1
- name: Prereqs
run: cargo install cross --git https://github.com/cross-rs/cross
run: cargo install bpf-linker
- name: Build
env:
CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }}
run: |
pushd bpf
cargo build --workspace --exclude aya-bpf-macros --verbose
popd
- name: Run tests
env:
CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }}
run: |
pushd bpf
cargo test --workspace --exclude aya-bpf-macros --verbose
popd
build-macros:
strategy:
matrix:
arch:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabi
- riscv64gc-unknown-none-elf
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
- uses: Swatinem/rust-cache@v1
- name: Prereqs
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build bpf macros
run: |
pushd bpf
cross build -p aya-bpf-macros --verbose
popd
- name: Test bpf macros
run: |
pushd bpf
RUST_BACKTRACE=full cross test -p aya-bpf-macros --verbose
popd
cargo build-bpfel -p aya-bpf --verbose
cargo build-bpfeb -p aya-bpf --verbose
cargo build-bpfel -p aya-log-ebpf --verbose
cargo build-bpfeb -p aya-log-ebpf --verbose

@ -21,19 +21,38 @@ jobs:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabi
- riscv64gc-unknown-none-elf
- riscv64gc-unknown-linux-gnu
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: false
- uses: Swatinem/rust-cache@v1
- name: Prereqs
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Build
run: cross build --verbose
run: cross build --verbose --target ${{matrix.arch}}
- name: Run test
run: RUST_BACKTRACE=full cross test --verbose
env:
RUST_BACKTRACE: full
run: |
cross test --verbose -p aya --target ${{matrix.arch}}
cross test --verbose -p aya-gen --target ${{matrix.arch}}
cross test --verbose -p aya-log --target ${{matrix.arch}}
cross test --verbose -p aya-log-ebpf-macros --target ${{matrix.arch}}
# aya-bpf-macros can only be tested on nightly since its tests depend on aya-bpf, which requires the never type
cross +nightly test --verbose -p aya-bpf-macros --target ${{matrix.arch}}
test:
runs-on: ubuntu-20.04
@ -60,12 +79,10 @@ jobs:
sudo apt-get -qy install linux-tools-common qemu-system-x86 cloud-image-utils openssh-client libelf-dev gcc-multilib
cargo install bpf-linker
- name: Lint integration tests
run: |
cargo xtask build-integration-test-ebpf --libbpf-dir ./libbpf
cargo clippy -p integration-test -- --deny warnings
cargo clippy -p integration-test-macros -- --deny warnings
- name: Run integration tests
run: |

@ -30,22 +30,11 @@ jobs:
- name: Check formatting
run: |
cargo fmt --all -- --check
(cd bpf && cargo fmt --all -- --check)
(cd test/integration-ebpf && cargo fmt --all -- --check)
- name: Run clippy
run: |
cargo clippy -p aya -- --deny warnings
cargo clippy -p aya-gen -- --deny warnings
cargo clippy -p xtask -- --deny warnings
(cd bpf && cargo clippy -p aya-bpf -- --deny warnings)
(cd test/integration-ebpf && cargo clippy -- --deny warnings)
cargo clippy --workspace --exclude integration-test -- --deny warnings
- name: Run miri
env:
MIRIFLAGS: -Zmiri-disable-stacked-borrows
run: |
cargo miri test --all-targets
pushd bpf
cargo miri test
popd

@ -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]
members = ["aya", "aya-gen", "test/integration-test", "test/integration-test-macros", "xtask"]
default-members = ["aya", "aya-gen"]
members = [
"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

@ -13,4 +13,4 @@ quote = "1.0"
syn = {version = "1.0", features = ["full"]}
[dev-dependencies]
aya-bpf = { path = "../aya-bpf" }
aya-bpf = { path = "../bpf/aya-bpf" }

@ -14,7 +14,7 @@ default = []
userspace = [ "aya" ]
[dependencies]
aya = { version = "0.11.0", optional=true }
aya = { path = "../aya", version = "0.11.0", optional=true }
[lib]
path = "src/lib.rs"

@ -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

13
aya-log/.gitignore vendored

@ -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]
members = ["aya-log", "aya-log-common", "xtask"]
[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 = { 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,22 +0,0 @@
#![no_std]
#![no_main]
use aya_bpf::{macros::tracepoint, programs::TracePointContext, BpfContext};
use aya_log_ebpf::{debug, error, info, trace, warn};
#[tracepoint]
pub fn example(ctx: TracePointContext) -> u32 {
error!(&ctx, "this is an error message 🚨");
warn!(&ctx, "this is a warning message ⚠️");
info!(&ctx, "this is an info message ");
debug!(&ctx, "this is a debug message ️🐝");
trace!(&ctx, "this is a trace message 🔍");
let pid = ctx.pid();
info!(&ctx, "a message with args PID: {}", pid);
0
}
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
unsafe { core::hint::unreachable_unchecked() }
}

@ -1,4 +0,0 @@
unstable_features = true
reorder_imports = true
imports_granularity = "Crate"

@ -1,7 +1 @@
pre-release-commit-message = "aya-log, aya-log-common: release version {{version}}"
post-release-commit-message = "aya-log, aya-log-common: start next development iteration {{next_version}}"
consolidate-pushes = true
consolidate-commits = true
shared-version = true
dev-version = true
dev-version-ext = "dev.0"

@ -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"]

@ -6,5 +6,5 @@ edition = "2018"
[dependencies]
aya-bpf-cty = { path = "../aya-bpf-cty" }
aya-bpf-macros = { path = "../aya-bpf-macros" }
aya-bpf-macros = { path = "../../aya-bpf-macros" }
aya-bpf-bindings = { path = "../aya-bpf-bindings" }

@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2018"
[dependencies]
aya-bpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
aya-bpf = { path = "../aya-bpf" }
aya-log-common = { path = "../../aya-log-common" }
aya-log-ebpf-macros = { path = "../aya-log-ebpf-macros" }
aya-log-ebpf-macros = { path = "../../aya-log-ebpf-macros" }
[lib]
path = "src/lib.rs"

@ -1 +0,0 @@
../rustfmt.toml

@ -1,3 +1,3 @@
[build]
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"

@ -22,15 +22,3 @@ path = "src/pass.rs"
[[bin]]
name = "test"
path = "src/test.rs"
[profile.dev]
panic = "abort"
opt-level = 2
overflow-checks = false
[profile.release]
panic = "abort"
debug = 2
[workspace]
members = []

@ -8,67 +8,19 @@ use std::{fs, io, io::Write};
use indoc::indoc;
pub fn docs() -> Result<(), anyhow::Error> {
let mut working_dir = PathBuf::from(".");
let replace = Command::new("sed")
.current_dir(&working_dir)
.args(vec![
"-i.bak",
"s/crabby.svg/crabby_dev.svg/",
"aya/src/lib.rs",
])
.status()
.expect("failed to replace logo");
assert!(replace.success());
let mut header_path = PathBuf::from(".");
header_path.push("header.html");
let current_dir = PathBuf::from(".");
let header_path = current_dir.join("header.html");
let mut header = fs::File::create(&header_path).expect("can't create header.html");
header
.write_all(r#"<meta name="robots" content="noindex">"#.as_bytes())
.expect("can't write header.html contents");
header.flush().expect("couldn't flush contents");
let abs_header_path = fs::canonicalize(&header_path).unwrap();
let args = vec!["+nightly", "doc", "--no-deps", "--all-features"];
let status = Command::new("cargo")
.current_dir(&working_dir)
.env(
"RUSTDOCFLAGS",
format!("--html-in-header {}", abs_header_path.to_str().unwrap()),
)
.args(&args)
.status()
.expect("failed to build aya docs");
assert!(status.success());
working_dir.push("bpf");
let replace = Command::new("sed")
.current_dir(&working_dir)
.args(vec![
"-i.bak",
"s/crabby.svg/crabby_dev.svg/",
"aya-bpf/src/lib.rs",
])
.status()
.expect("failed to replace logo");
assert!(replace.success());
let status = Command::new("cargo")
.current_dir(&working_dir)
.env(
"RUSTDOCFLAGS",
format!("--html-in-header {}", abs_header_path.to_str().unwrap()),
)
.args(&args)
.status()
.expect("failed to build aya-bpf docs");
assert!(status.success());
copy_dir_all("./target/doc", "site/user")?;
copy_dir_all("./bpf/target/doc", "site/bpf")?;
build_docs(&current_dir.join("aya"), &abs_header_path)?;
build_docs(&current_dir.join("bpf/aya-bpf"), &abs_header_path)?;
copy_dir_all("./target/doc", "./site/user")?;
copy_dir_all("./target/bpfel-unknown-none/doc", "./site/bpf")?;
let mut robots = fs::File::create("site/robots.txt").expect("can't create robots.txt");
robots
@ -98,14 +50,38 @@ pub fn docs() -> Result<(), anyhow::Error> {
.as_bytes(),
)
.expect("can't write index.html");
Ok(())
}
fn build_docs(working_dir: &PathBuf, abs_header_path: &Path) -> Result<(), anyhow::Error> {
let replace = Command::new("sed")
.current_dir(&working_dir)
.args(vec!["-i.bak", "s/crabby.svg/crabby_dev.svg/", "src/lib.rs"])
.status()
.expect("failed to replace logo");
assert!(replace.success());
fs::rename("aya/src/lib.rs.bak", "aya/src/lib.rs").unwrap();
fs::rename("bpf/aya-bpf/src/lib.rs.bak", "bpf/aya-bpf/src/lib.rs").unwrap();
let args = vec!["+nightly", "doc", "--no-deps", "--all-features"];
let status = Command::new("cargo")
.current_dir(&working_dir)
.env(
"RUSTDOCFLAGS",
format!("--html-in-header {}", abs_header_path.to_str().unwrap()),
)
.args(&args)
.status()
.expect("failed to build aya docs");
assert!(status.success());
fs::rename(
working_dir.join("src/lib.rs.bak"),
working_dir.join("src/lib.rs"),
)
.unwrap();
Ok(())
}
fn copy_dir_all<P: AsRef<Path>>(src: P, dst: P) -> io::Result<()> {
fn copy_dir_all<P1: AsRef<Path>, P2: AsRef<Path>>(src: P1, dst: P2) -> io::Result<()> {
fs::create_dir_all(&dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;

Loading…
Cancel
Save