Skip to content

Commit

Permalink
Always build eBPF; remove xtask
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed Oct 30, 2024
1 parent 27e7867 commit 451159a
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 224 deletions.
2 changes: 0 additions & 2 deletions .cargo/config.toml

This file was deleted.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
resolver = "2"
members = ["xtask", "{{project-name}}", "{{project-name}}-common", "{{project-name}}-ebpf"]
default-members = ["xtask", "{{project-name}}", "{{project-name}}-common"]
members = ["{{project-name}}", "{{project-name}}-common", "{{project-name}}-ebpf"]
default-members = ["{{project-name}}", "{{project-name}}-common"]

[workspace.dependencies]
aya = { version = "0.13.0", default-features = false }
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@

## Build & Run

Use `cargo build`, `cargo check`, etc. as normal. Run your program with `xtask run`.
Use `cargo build`, `cargo check`, etc. as normal. Run your program with:

```shell
cargo run --release --config 'target."cfg(all())".runner="sudo -E"'
```

Cargo build scripts are used to automatically build the eBPF correctly and include it in the
program. When not using `xtask run`, eBPF code generation is skipped for a faster developer
experience; this compromise necessitates the use of `xtask` to actually build the eBPF.
program.

## Cross-compiling on macOS

Cross compilation should work on both Intel and Apple Silicon Macs.

```shell
AYA_BUILD_EBPF=true CC=${ARCH}-linux-musl-gcc cargo build --package {{project-name}} --release \
CC=${ARCH}-linux-musl-gcc cargo build --package {{project-name}} --release \
--target=${ARCH}-unknown-linux-musl \
--config=target.${ARCH}-unknown-linux-musl.linker=\"${ARCH}-linux-musl-gcc\"
```
Expand Down
4 changes: 2 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ case $OS in
if [[ "$ARCH" == "arm64" ]]; then
ARCH="aarch64"
fi
AYA_BUILD_EBPF=true CC=${ARCH}-linux-musl-gcc cargo build --package "${CRATE_NAME}" --release \
CC=${ARCH}-linux-musl-gcc cargo build --package "${CRATE_NAME}" --release \
--target="${ARCH}"-unknown-linux-musl \
--config=target."${ARCH}"-unknown-linux-musl.linker=\""${ARCH}"-linux-musl-gcc\"
;;
Expand All @@ -85,7 +85,7 @@ case $OS in

expect <<EOF
set timeout 30 ;# Increase timeout if necessary
spawn cargo xtask run
spawn cargo run --release --config 'target."cfg(all())".runner="sudo -E"'
expect {
-re "Waiting for Ctrl-C.*" {
send -- \003 ;# Send Ctrl-C
Expand Down
8 changes: 0 additions & 8 deletions xtask/Cargo.toml

This file was deleted.

1 change: 0 additions & 1 deletion xtask/src/lib.rs

This file was deleted.

23 changes: 0 additions & 23 deletions xtask/src/main.rs

This file was deleted.

47 changes: 0 additions & 47 deletions xtask/src/run.rs

This file was deleted.

1 change: 0 additions & 1 deletion {{project-name}}-ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ aya-log-ebpf = { workspace = true }

[build-dependencies]
which = { workspace = true }
xtask = { path = "../xtask" }

[[bin]]
name = "{{ project-name }}"
Expand Down
15 changes: 2 additions & 13 deletions {{project-name}}-ebpf/build.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::env;

use which::which;
use xtask::AYA_BUILD_EBPF;

/// Building this crate has an undeclared dependency on the `bpf-linker` binary. This would be
/// better expressed by [artifact-dependencies][bindeps] but issues such as
Expand All @@ -15,16 +14,6 @@ use xtask::AYA_BUILD_EBPF;
///
/// [bindeps]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies
fn main() {
println!("cargo:rerun-if-env-changed={}", AYA_BUILD_EBPF);

let build_ebpf = env::var(AYA_BUILD_EBPF)
.as_deref()
.map(str::parse)
.map(Result::unwrap)
.unwrap_or_default();

if build_ebpf {
let bpf_linker = which("bpf-linker").unwrap();
println!("cargo:rerun-if-changed={}", bpf_linker.to_str().unwrap());
}
let bpf_linker = which("bpf-linker").unwrap();
println!("cargo:rerun-if-changed={}", bpf_linker.to_str().unwrap());
}
1 change: 0 additions & 1 deletion {{project-name}}/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ cargo_metadata = { workspace = true }
# workflows with stable cargo; stable cargo outright refuses to load manifests that use unstable
# features.
{{project-name}}-ebpf = { path = "../{{project-name}}-ebpf" }
xtask = { path = "../xtask" }

[[bin]]
name = "{{project-name}}"
Expand Down
Loading

0 comments on commit 451159a

Please sign in to comment.