Merge pull request #40 from vadorovsky/profile-dev

ebpf: Make the dev target identical to release
pull/42/head
Alessandro Decina 2 years ago committed by GitHub
commit eda904b187
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -35,24 +35,25 @@ pub struct Options {
/// Set the endianness of the BPF target /// Set the endianness of the BPF target
#[structopt(default_value = "bpfel-unknown-none", long)] #[structopt(default_value = "bpfel-unknown-none", long)]
pub target: Architecture, pub target: Architecture,
/// Build profile for eBPF programs /// Build the release target
#[structopt(default_value = "release", long)] #[structopt(long)]
pub profile: String, pub release: bool,
} }
pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> {
let dir = PathBuf::from("{{project-name}}-ebpf"); let dir = PathBuf::from("{{project-name}}-ebpf");
let target = format!("--target={}", opts.target); let target = format!("--target={}", opts.target);
let args = vec![ let mut args = vec![
"+nightly", "+nightly",
"build", "build",
"--verbose", "--verbose",
target.as_str(), target.as_str(),
"-Z", "-Z",
"build-std=core", "build-std=core",
"--profile",
opts.profile.as_str(),
]; ];
if opts.release {
args.push("--release")
}
let status = Command::new("cargo") let status = Command::new("cargo")
.current_dir(&dir) .current_dir(&dir)
.args(&args) .args(&args)

@ -10,9 +10,9 @@ pub struct Options {
/// Set the endianness of the BPF target /// Set the endianness of the BPF target
#[structopt(default_value = "bpfel-unknown-none", long)] #[structopt(default_value = "bpfel-unknown-none", long)]
pub bpf_target: Architecture, pub bpf_target: Architecture,
/// Build profile for userspace program /// Build and run the release target
#[structopt(default_value = "dev", long)] #[structopt(long)]
pub profile: String, pub release: bool,
/// The command used to wrap your application /// The command used to wrap your application
#[structopt(short, long, default_value = "sudo -E")] #[structopt(short, long, default_value = "sudo -E")]
pub runner: String, pub runner: String,
@ -23,7 +23,10 @@ pub struct Options {
/// Build the project /// Build the project
fn build(opts: &Options) -> Result<(), anyhow::Error> { fn build(opts: &Options) -> Result<(), anyhow::Error> {
let args = vec!["build", "--profile", opts.profile.as_str()]; let mut args = vec!["build"];
if opts.release {
args.push("--release")
}
let status = Command::new("cargo") let status = Command::new("cargo")
.args(&args) .args(&args)
.status() .status()
@ -37,17 +40,14 @@ pub fn run(opts: Options) -> Result<(), anyhow::Error> {
// build our ebpf program followed by our application // build our ebpf program followed by our application
build_ebpf(BuildOptions { build_ebpf(BuildOptions {
target: opts.bpf_target, target: opts.bpf_target,
profile: opts.profile.clone(), release: opts.release,
}) })
.context("Error while building eBPF program")?; .context("Error while building eBPF program")?;
build(&opts).context("Error while building userspace application")?; build(&opts).context("Error while building userspace application")?;
let target_dir = match opts.profile.as_str() { // profile we are building (release or debug)
"dev" | "test" => "debug", let profile = if opts.release { "release" } else { "debug" };
"bench" | "release" => "release", let bin_path = format!("target/{}/{{project-name}}", profile);
_ => opts.profile.as_str(),
};
let bin_path = format!("target/{}/{{project-name}}", target_dir);
// arguments to pass to the application // arguments to pass to the application
let mut run_args: Vec<_> = opts.run_args.iter().map(String::as_str).collect(); let mut run_args: Vec<_> = opts.run_args.iter().map(String::as_str).collect();

@ -11,8 +11,21 @@ aya-bpf = { git = "https://github.com/aya-rs/aya", branch = "main" }
name = "{{ project-name }}" name = "{{ project-name }}"
path = "src/main.rs" 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] [profile.release]
lto = true
panic = "abort" panic = "abort"
codegen-units = 1
[workspace] [workspace]
members = [] members = []

@ -65,6 +65,11 @@ async fn main() -> Result<(), anyhow::Error> {
// runtime. This approach is recommended for most real-world use cases. If you would // 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 // like to specify the eBPF program at runtime rather than at compile-time, you can
// reach for `Bpf::load_file` instead. // 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!( let mut bpf = Bpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/{{project-name}}" "../../target/bpfel-unknown-none/release/{{project-name}}"
))?; ))?;

Loading…
Cancel
Save