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