@ -1,4 +1,5 @@
use std ::{
use std ::{
collections ::{ HashMap , HashSet } ,
env ,
env ,
ffi ::OsString ,
ffi ::OsString ,
fmt ::Write as _ ,
fmt ::Write as _ ,
@ -9,7 +10,7 @@ use std::{
} ;
} ;
use cargo_metadata ::{
use cargo_metadata ::{
Artifact , CompilerMessage , Message, Metadata , MetadataCommand , Package , Target ,
Artifact , CompilerMessage , Dependency, Message, Metadata , MetadataCommand , Package , Target ,
} ;
} ;
fn main ( ) {
fn main ( ) {
@ -25,6 +26,17 @@ fn main() {
}
}
} ;
} ;
const INTEGRATION_EBPF_PACKAGE : & str = "integration-ebpf" ;
let Metadata { packages , .. } = MetadataCommand ::new ( ) . no_deps ( ) . exec ( ) . unwrap ( ) ;
let packages : HashMap < String , _ > = packages
. into_iter ( )
. map ( | package | {
let Package { name , .. } = & package ;
( name . clone ( ) , package )
} )
. collect ( ) ;
let manifest_dir = env ::var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
let manifest_dir = env ::var_os ( "CARGO_MANIFEST_DIR" ) . unwrap ( ) ;
let manifest_dir = PathBuf ::from ( manifest_dir ) ;
let manifest_dir = PathBuf ::from ( manifest_dir ) ;
let out_dir = env ::var_os ( "OUT_DIR" ) . unwrap ( ) ;
let out_dir = env ::var_os ( "OUT_DIR" ) . unwrap ( ) ;
@ -117,14 +129,29 @@ fn main() {
}
}
}
}
let ebpf_dir = manifest_dir . parent ( ) . unwrap ( ) . join ( "integration-ebpf" ) ;
println! ( "cargo:rerun-if-changed={}" , ebpf_dir . to_str ( ) . unwrap ( ) ) ;
let target = format! ( "{target}-unknown-none" ) ;
let target = format! ( "{target}-unknown-none" ) ;
// Teach cargo about our dependencies.
let mut visited = HashSet ::new ( ) ;
let mut frontier = vec! [ INTEGRATION_EBPF_PACKAGE ] ;
while let Some ( package ) = frontier . pop ( ) {
if ! visited . insert ( package ) {
continue ;
}
let Package { dependencies , .. } = packages . get ( package ) . unwrap ( ) ;
for Dependency { name , path , .. } in dependencies {
if let Some ( path ) = path {
println! ( "cargo:rerun-if-changed={}" , path . as_str ( ) ) ;
frontier . push ( name ) ;
}
}
}
let mut cmd = Command ::new ( "cargo" ) ;
let mut cmd = Command ::new ( "cargo" ) ;
cmd . current_dir ( & ebpf_dir ) . args ( [
cmd . args( [
"build" ,
"build" ,
"-p" ,
"integration-ebpf" ,
"-Z" ,
"-Z" ,
"build-std=core" ,
"build-std=core" ,
"--release" ,
"--release" ,
@ -185,18 +212,13 @@ fn main() {
fs ::write ( & dst , [ ] ) . unwrap_or_else ( | err | panic! ( "failed to create {dst:?}: {err}" ) ) ;
fs ::write ( & dst , [ ] ) . unwrap_or_else ( | err | panic! ( "failed to create {dst:?}: {err}" ) ) ;
}
}
let Metadata { packages , .. } = MetadataCommand ::new ( ) . no_deps ( ) . exec ( ) . unwrap ( ) ;
let Package { targets , .. } = packages . get ( INTEGRATION_EBPF_PACKAGE ) . unwrap ( ) ;
for Package { name , targets , .. } in packages {
if name ! = "integration-ebpf" {
continue ;
}
for Target { name , kind , .. } in targets {
for Target { name , kind , .. } in targets {
if kind ! = [ "bin" ] {
if * kind ! = [ "bin" ] {
continue ;
continue ;
}
}
let dst = out_dir . join ( name ) ;
let dst = out_dir . join ( name ) ;
fs ::write ( & dst , [ ] ) . unwrap_or_else ( | err | panic! ( "failed to create {dst:?}: {err}" ) ) ;
fs ::write ( & dst , [ ] ) . unwrap_or_else ( | err | panic! ( "failed to create {dst:?}: {err}" ) ) ;
}
}
}
}
}
}
}