openmina / mina-network-debugger

4 stars 2 forks source link

Issue building with feature kern #45

Closed 0xMimir closed 8 months ago

0xMimir commented 8 months ago

When trying to building bpf-recorder-kern, kern feature must be enabled.

Steps to reproduce:

git clone git@github.com:openmina/mina-network-debugger.git network-debugger
CARGO_TARGET_DIR=target/bpf cargo +nightly-2022-10-10 rustc --package=bpf-recorder --bin=bpf-recorder-kern --features=kern --no-default-features --target=bpfel-unknown-none -Z build-std=core --release -- -Cdebuginfo=2 -Clink-arg=--disable-memory-builtins -Clink-arg=--keep-btf
cargo run --bin bpf-recorder-kern --features="kern"

This gives following error:

   Compiling bpf-recorder v0.1.0 (/home/mimir/0xMimir/work/network-debugger/bpf-recorder)
error[E0433]: failed to resolve: use of undeclared crate or module `std`
 --> bpf-recorder/src/proc.rs:2:5
  |
2 | use std::{
  |     ^^^ use of undeclared crate or module `std`

error[E0433]: failed to resolve: use of undeclared crate or module `std`
  --> bpf-recorder/src/lib.rs:95:9
   |
95 |     use std::net::{IpAddr, SocketAddr};
   |         ^^^ use of undeclared crate or module `std`

error[E0432]: unresolved import `std`
 --> bpf-recorder/src/proc.rs:2:5
  |
2 | use std::{
  |     ^^^ use of undeclared crate or module `std`

error: cannot find macro `format` in this scope
  --> bpf-recorder/src/proc.rs:14:32
   |
14 |         let mut f = File::open(format!("/proc/{pid}/cmdline"))?;
   |                                ^^^^^^

error[E0433]: failed to resolve: use of undeclared crate or module `std`
   --> bpf-recorder/src/lib.rs:172:17
    |
172 |                 std::process::exit(1);
    |                 ^^^ use of undeclared crate or module `std`

error[E0412]: cannot find type `String` in this scope
   --> bpf-recorder/src/lib.rs:113:16
    |
113 |         NewApp(String),
    |                ^^^^^^ not found in this scope
    |
help: there is an enum variant `serde::__private::de::Content::String` and 1 other; try using the variant's enum
    |
113 |         NewApp(serde::__private::de::Content),
    |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
113 |         NewApp(serde_json::Value),
    |                ~~~~~~~~~~~~~~~~~

error[E0412]: cannot find type `Vec` in this scope
   --> bpf-recorder/src/lib.rs:119:22
    |
119 |         IncomingData(Vec<u8>),
    |                      ^^^ not found in this scope
    |
help: consider importing this struct
    |
95  +     use serde::__private::Vec;
    |

error[E0412]: cannot find type `Vec` in this scope
   --> bpf-recorder/src/lib.rs:120:22
    |
120 |         OutgoingData(Vec<u8>),
    |                      ^^^ not found in this scope
    |
help: consider importing this struct
    |
95  +     use serde::__private::Vec;
    |

error[E0412]: cannot find type `Vec` in this scope
   --> bpf-recorder/src/lib.rs:121:16
    |
121 |         Random(Vec<u8>),
    |                ^^^ not found in this scope
    |
help: consider importing this struct
    |
95  +     use serde::__private::Vec;
    |

error[E0412]: cannot find type `Vec` in this scope
   --> bpf-recorder/src/lib.rs:122:20
    |
122 |         GetSockOpt(Vec<u8>),
    |                    ^^^ not found in this scope
    |
help: consider importing this struct
    |
95  +     use serde::__private::Vec;
    |

error[E0433]: failed to resolve: use of undeclared type `String`
  --> bpf-recorder/src/proc.rs:15:21
   |
15 |         let mut s = String::new();
   |                     ^^^^^^ use of undeclared type `String`
   |
help: there is an enum variant `serde::__private::de::Content::String` and 1 other; try using the variant's enum
   |
15 |         let mut s = serde::__private::de::Content();
   |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 |         let mut s = serde_json::Value();
   |                     ~~~~~~~~~~~~~~~~~

error[E0433]: failed to resolve: use of undeclared type `String`
   --> bpf-recorder/src/lib.rs:203:21
    |
203 |                     String::from_utf8(data[..(data.len() - 1)].to_vec())
    |                     ^^^^^^ use of undeclared type `String`
    |
help: there is an enum variant `serde::__private::de::Content::String` and 1 other; try using the variant's enum
    |
203 |                     serde::__private::de::Content(data[..(data.len() - 1)].to_vec())
    |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
203 |                     serde_json::Value(data[..(data.len() - 1)].to_vec())
    |                     ~~~~~~~~~~~~~~~~~

error[E0599]: no method named `to_string` found for reference `&'static str` in the current scope
   --> bpf-recorder/src/lib.rs:204:57
    |
204 |                         .unwrap_or("invalid_uft8_alias".to_string()),
    |                                                         ^^^^^^^^^ method not found in `&str`
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
95  +     use tinyvec::alloc::string::ToString;
    |

Some errors have detailed explanations: E0412, E0432, E0433, E0599.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `bpf-recorder` (lib) due to 13 previous errors
vlad9486 commented 8 months ago

The kern build is not intended to run in userspace. It produces BPF code which is linked to the user binary. And then the user binary can load the BPF code (kern binary) into the kernel.