Skip to content

Commit

Permalink
ebpf: Always use release profile
Browse files Browse the repository at this point in the history
Using `dev` profile, even after tuning flags (to make it identical
with `release`) still causes problems and is confusing for people.

And even when we have BTF support in future, it'd be better and
less confusing to set `debug=2` in `release` profile (because we
would want debug info, but still keep the same opt-level and other
options).
  • Loading branch information
vadorovsky committed Jul 20, 2023
1 parent afdb453 commit 3449c6d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 23 deletions.
7 changes: 1 addition & 6 deletions xtask/src/build_ebpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,19 @@ pub struct Options {
/// Set the endianness of the BPF target
#[clap(default_value = "bpfel-unknown-none", long)]
pub target: Architecture,
/// Build the release target
#[clap(long)]
pub release: bool,
}

pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> {
let dir = PathBuf::from("{{project-name}}-ebpf");
let target = format!("--target={}", opts.target);
let mut args = vec![
"build",
"--release",
"--verbose",
target.as_str(),
"-Z",
"build-std=core",
];
if opts.release {
args.push("--release")
}

// Command::new creates a child process which inherits all env variables. This means env
// vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed
Expand Down
1 change: 0 additions & 1 deletion xtask/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub fn run(opts: Options) -> Result<(), anyhow::Error> {
// build our ebpf program followed by our application
build_ebpf(BuildOptions {
target: opts.bpf_target,
release: opts.release,
})
.context("Error while building eBPF program")?;
build(&opts).context("Error while building userspace application")?;
Expand Down
11 changes: 0 additions & 11 deletions {{project-name}}-ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ aya-log-ebpf = { git = "https://github.com/aya-rs/aya" }
name = "{{ project-name }}"
path = "src/main.rs"

[profile.dev]
opt-level = 3
debug = false
debug-assertions = false
overflow-checks = false
lto = true
panic = "abort"
incremental = false
codegen-units = 1
rpath = false

[profile.release]
lto = true
panic = "abort"
Expand Down
5 changes: 0 additions & 5 deletions {{project-name}}/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ async fn main() -> Result<(), anyhow::Error> {
// runtime. This approach is recommended for most real-world use cases. If you would
// like to specify the eBPF program at runtime rather than at compile-time, you can
// reach for `Bpf::load_file` instead.
#[cfg(debug_assertions)]
let mut bpf = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/debug/{{project-name}}"
))?;
#[cfg(not(debug_assertions))]
let mut bpf = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/{{project-name}}"
))?;
Expand Down

0 comments on commit 3449c6d

Please sign in to comment.