File tree 6 files changed +33
-49
lines changed
6 files changed +33
-49
lines changed Original file line number Diff line number Diff line change 1
- use std:: fs :: create_dir_all ;
2
- use std:: path:: Path ;
1
+ use std:: env ;
2
+ use std:: path:: PathBuf ;
3
3
4
- extern crate libbpf_cargo;
5
4
use libbpf_cargo:: SkeletonBuilder ;
6
5
7
- const SRC : & str = "./ src/bpf/profile.bpf.c" ;
6
+ const SRC : & str = "src/bpf/profile.bpf.c" ;
8
7
9
8
fn main ( ) {
10
- // It's unfortunate we cannot use `OUT_DIR` to store the generated skeleton.
11
- // Reasons are because the generated skeleton contains compiler attributes
12
- // that cannot be `include!()`ed via macro. And we cannot use the `#[path = "..."]`
13
- // trick either because you cannot yet `concat!(env!("OUT_DIR"), "/skel.rs")` inside
14
- // the path attribute either (see https://github.com/rust-lang/rust/pull/83366).
15
- //
16
- // However, there is hope! When the above feature stabilizes we can clean this
17
- // all up.
18
- create_dir_all ( "./src/bpf/.output" ) . unwrap ( ) ;
19
- let skel = Path :: new ( "./src/bpf/.output/profile.skel.rs" ) ;
9
+ let mut out =
10
+ PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . expect ( "OUT_DIR must be set in build script" ) ) ;
11
+ out. push ( "profile.skel.rs" ) ;
12
+
20
13
SkeletonBuilder :: new ( )
21
14
. source ( SRC )
22
- . build_and_generate ( skel )
15
+ . build_and_generate ( out )
23
16
. expect ( "bpf compilation failed" ) ;
24
17
println ! ( "cargo:rerun-if-changed={}" , SRC ) ;
25
18
}
Original file line number Diff line number Diff line change @@ -19,8 +19,9 @@ use tracing_subscriber::fmt::format::FmtSpan;
19
19
use tracing_subscriber:: fmt:: time:: SystemTime ;
20
20
use tracing_subscriber:: FmtSubscriber ;
21
21
22
- #[ path = "bpf/.output/profile.skel.rs" ]
23
- mod profile;
22
+ mod profile {
23
+ include ! ( concat!( env!( "OUT_DIR" ) , "/profile.skel.rs" ) ) ;
24
+ }
24
25
mod syscall;
25
26
26
27
use profile:: * ;
Original file line number Diff line number Diff line change 1
- use std:: fs :: create_dir_all ;
2
- use std:: path:: Path ;
1
+ use std:: env ;
2
+ use std:: path:: PathBuf ;
3
3
4
4
use libbpf_cargo:: SkeletonBuilder ;
5
5
6
- const SRC : & str = "./ src/bpf/tracecon.bpf.c" ;
6
+ const SRC : & str = "src/bpf/tracecon.bpf.c" ;
7
7
8
8
fn main ( ) {
9
- // It's unfortunate we cannot use `OUT_DIR` to store the generated skeleton.
10
- // Reasons are because the generated skeleton contains compiler attributes
11
- // that cannot be `include!()`ed via macro. And we cannot use the `#[path = "..."]`
12
- // trick either because you cannot yet `concat!(env!("OUT_DIR"), "/skel.rs")` inside
13
- // the path attribute either (see https://github.com/rust-lang/rust/pull/83366).
14
- //
15
- // However, there is hope! When the above feature stabilizes we can clean this
16
- // all up.
17
- create_dir_all ( "./src/bpf/.output" ) . unwrap ( ) ;
18
- let skel = Path :: new ( "./src/bpf/.output/tracecon.skel.rs" ) ;
9
+ let mut out =
10
+ PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . expect ( "OUT_DIR must be set in build script" ) ) ;
11
+ out. push ( "tracecon.skel.rs" ) ;
12
+
19
13
SkeletonBuilder :: new ( )
20
14
. source ( SRC )
21
- . build_and_generate ( & skel )
15
+ . build_and_generate ( & out )
22
16
. expect ( "bpf compilation failed" ) ;
23
17
println ! ( "cargo:rerun-if-changed={}" , SRC ) ;
24
18
}
Original file line number Diff line number Diff line change @@ -11,8 +11,9 @@ use std::sync::atomic::{AtomicBool, Ordering};
11
11
use std:: sync:: Arc ;
12
12
use structopt:: StructOpt ;
13
13
14
- #[ path = "bpf/.output/tracecon.skel.rs" ]
15
- mod tracecon;
14
+ mod tracecon {
15
+ include ! ( concat!( env!( "OUT_DIR" ) , "/tracecon.skel.rs" ) ) ;
16
+ }
16
17
use tracecon:: * ;
17
18
18
19
type Event = tracecon_bss_types:: event ;
Original file line number Diff line number Diff line change 1
- use std:: fs :: create_dir_all ;
2
- use std:: path:: Path ;
1
+ use std:: env ;
2
+ use std:: path:: PathBuf ;
3
3
4
4
use libbpf_cargo:: SkeletonBuilder ;
5
5
6
- const SRC : & str = "./ src/bpf/xdppass.bpf.c" ;
6
+ const SRC : & str = "src/bpf/xdppass.bpf.c" ;
7
7
8
8
fn main ( ) {
9
- // It's unfortunate we cannot use `OUT_DIR` to store the generated skeleton.
10
- // Reasons are because the generated skeleton contains compiler attributes
11
- // that cannot be `include!()`ed via macro. And we cannot use the `#[path = "..."]`
12
- // trick either because you cannot yet `concat!(env!("OUT_DIR"), "/skel.rs")` inside
13
- // the path attribute either (see https://github.com/rust-lang/rust/pull/83366).
14
- //
15
- // However, there is hope! When the above feature stabilizes we can clean this
16
- // all up.
17
- create_dir_all ( "./src/bpf/.output" ) . unwrap ( ) ;
18
- let skel = Path :: new ( "./src/bpf/.output/xdppass.skel.rs" ) ;
9
+ let mut out =
10
+ PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . expect ( "OUT_DIR must be set in build script" ) ) ;
11
+ out. push ( "xdppass.skel.rs" ) ;
12
+
19
13
SkeletonBuilder :: new ( )
20
14
. source ( SRC )
21
- . build_and_generate ( & skel )
15
+ . build_and_generate ( out )
22
16
. unwrap ( ) ;
23
17
println ! ( "cargo:rerun-if-changed={}" , SRC ) ;
24
18
}
Original file line number Diff line number Diff line change @@ -5,8 +5,9 @@ use std::{thread, time};
5
5
use anyhow:: { bail, Result } ;
6
6
use structopt:: StructOpt ;
7
7
8
- #[ path = "bpf/.output/xdppass.skel.rs" ]
9
- mod xdppass;
8
+ mod xdppass {
9
+ include ! ( concat!( env!( "OUT_DIR" ) , "/xdppass.skel.rs" ) ) ;
10
+ }
10
11
use xdppass:: * ;
11
12
12
13
#[ derive( Debug , StructOpt ) ]
You can’t perform that action at this time.
0 commit comments