File tree Expand file tree Collapse file tree 6 files changed +33
-49
lines changed Expand file tree Collapse file tree 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 ;
33
4- extern crate libbpf_cargo;
54use libbpf_cargo:: SkeletonBuilder ;
65
7- const SRC : & str = "./ src/bpf/profile.bpf.c" ;
6+ const SRC : & str = "src/bpf/profile.bpf.c" ;
87
98fn 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+
2013 SkeletonBuilder :: new ( )
2114 . source ( SRC )
22- . build_and_generate ( skel )
15+ . build_and_generate ( out )
2316 . expect ( "bpf compilation failed" ) ;
2417 println ! ( "cargo:rerun-if-changed={}" , SRC ) ;
2518}
Original file line number Diff line number Diff line change @@ -19,8 +19,9 @@ use tracing_subscriber::fmt::format::FmtSpan;
1919use tracing_subscriber:: fmt:: time:: SystemTime ;
2020use tracing_subscriber:: FmtSubscriber ;
2121
22- #[ path = "bpf/.output/profile.skel.rs" ]
23- mod profile;
22+ mod profile {
23+ include ! ( concat!( env!( "OUT_DIR" ) , "/profile.skel.rs" ) ) ;
24+ }
2425mod syscall;
2526
2627use 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 ;
33
44use libbpf_cargo:: SkeletonBuilder ;
55
6- const SRC : & str = "./ src/bpf/tracecon.bpf.c" ;
6+ const SRC : & str = "src/bpf/tracecon.bpf.c" ;
77
88fn 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+
1913 SkeletonBuilder :: new ( )
2014 . source ( SRC )
21- . build_and_generate ( & skel )
15+ . build_and_generate ( & out )
2216 . expect ( "bpf compilation failed" ) ;
2317 println ! ( "cargo:rerun-if-changed={}" , SRC ) ;
2418}
Original file line number Diff line number Diff line change @@ -11,8 +11,9 @@ use std::sync::atomic::{AtomicBool, Ordering};
1111use std:: sync:: Arc ;
1212use structopt:: StructOpt ;
1313
14- #[ path = "bpf/.output/tracecon.skel.rs" ]
15- mod tracecon;
14+ mod tracecon {
15+ include ! ( concat!( env!( "OUT_DIR" ) , "/tracecon.skel.rs" ) ) ;
16+ }
1617use tracecon:: * ;
1718
1819type 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 ;
33
44use libbpf_cargo:: SkeletonBuilder ;
55
6- const SRC : & str = "./ src/bpf/xdppass.bpf.c" ;
6+ const SRC : & str = "src/bpf/xdppass.bpf.c" ;
77
88fn 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+
1913 SkeletonBuilder :: new ( )
2014 . source ( SRC )
21- . build_and_generate ( & skel )
15+ . build_and_generate ( out )
2216 . unwrap ( ) ;
2317 println ! ( "cargo:rerun-if-changed={}" , SRC ) ;
2418}
Original file line number Diff line number Diff line change @@ -5,8 +5,9 @@ use std::{thread, time};
55use anyhow:: { bail, Result } ;
66use structopt:: StructOpt ;
77
8- #[ path = "bpf/.output/xdppass.skel.rs" ]
9- mod xdppass;
8+ mod xdppass {
9+ include ! ( concat!( env!( "OUT_DIR" ) , "/xdppass.skel.rs" ) ) ;
10+ }
1011use xdppass:: * ;
1112
1213#[ derive( Debug , StructOpt ) ]
You can’t perform that action at this time.
0 commit comments