Projects STRLCPY ebpfguard Commits 33fa0ce4
🤬
  • eBPF: add compiled release mode build

    - autocopy object files on `xtask build-ebpf` run
    - change development.md to make eBPF compilation step conditional
  • Loading...
  • Tomasz Jonak committed 12 months ago
    33fa0ce4
    1 parent a1e61003
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    docs/gh/development.md
    skipped 5 lines
    6 6   
    7 7  ## Compilation
    8 8   
    9  -First compile ebpf bytecode with the following command. It will be embedded
    10  -in userspace binary using aya.
     9 +Just utilize cargo infrastructure.
    11 10   
    12 11  ```
    13  -$ cargo xtask build-ebpf
     12 +$ cargo build
    14 13  ```
    15 14   
    16  -Then userspace code.
     15 +If you make changes to any code under `ebpfguard-ebpf` and/or `ebpfguard-common` make sure to rebuild eBPF objects.
    17 16   
    18 17  ```
    19  -$ cargo build
     18 +$ cargo xtask build-ebpf
    20 19  ```
    21 20   
    22 21  ## Tests
    skipped 18 lines
    41 40  $ cargo clippy --workspace -- --deny warnings
    42 41  ```
    43 42   
    44  -Miri verification. Requires optional dependencies from [miri section](prerequisites.md#miri)
     43 +Miri verification.
    45 44   
    46 45  ```
    47 46  $ cargo +nightly miri test --all-targets
    48 47  ```
    49 48   
     49 +## Contributing
     50 + 
     51 +Before setting up a PR make sure to run
     52 + 
     53 +```
     54 +cargo clippy --fix && cargo fmt
     55 +```
     56 + 
     57 +And verify/commit any resulting changes.
     58 + 
  • ebpfguard-ebpf/ebpfguard.debug.obj
    Binary file.
  • ebpfguard-ebpf/ebpfguard.release.obj
    Binary file.
  • ■ ■ ■ ■ ■ ■
    xtask/src/build_ebpf.rs
    skipped 28 lines
    29 29   }
    30 30  }
    31 31   
     32 +#[derive(Debug, Copy, Clone)]
     33 +pub enum BuildType {
     34 + Debug,
     35 + Release,
     36 +}
     37 + 
     38 +impl From<bool> for BuildType {
     39 + fn from(value: bool) -> Self {
     40 + match value {
     41 + true => Self::Release,
     42 + false => Self::Debug,
     43 + }
     44 + }
     45 +}
     46 + 
     47 +impl std::fmt::Display for BuildType {
     48 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
     49 + f.write_str(match self {
     50 + Self::Release => "release",
     51 + Self::Debug => "debug",
     52 + })
     53 + }
     54 +}
     55 + 
    32 56  #[derive(Debug, Parser)]
    33 57  pub struct Options {
    34 58   /// Set the endianness of the BPF target
    skipped 14 lines
    49 73   "-Z",
    50 74   "build-std=core",
    51 75   ];
    52  - if opts.release {
     76 + let build_type = BuildType::from(opts.release);
     77 + 
     78 + if matches!(build_type, BuildType::Release) {
    53 79   args.push("--release")
    54 80   }
    55 81   
    skipped 8 lines
    64 90   .status()
    65 91   .expect("failed to build bpf program");
    66 92   assert!(status.success());
     93 + 
     94 + let source = format!("target/{}/{}/ebpfguard", opts.target, build_type);
     95 + let destination = format!("ebpfguard-ebpf/ebpfguard.{}.obj", build_type);
     96 + 
     97 + std::fs::copy(source, destination)
     98 + .expect("Couldn't copy compiled eBPFObject to destination path");
     99 + 
    67 100   Ok(())
    68 101  }
    69 102   
Please wait...
Page is in error, reload to recover