forked from libbpf/libbpf-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples/rust: Store skeletons in $OUT_DIR
Store skeletons in $OUT_DIR as opposed to .output, which is kind of the proper thing to do (though it certainly doesn't help discoverability...) and it is more in line with how examples in libbpf-rs work. Also remove the "there is hope!" comments, because even with rust-lang/rust#83366 resolved we still cannot use the concat! macro in #[path = ...] attributes. All hope is lost. Signed-off-by: Daniel Müller <deso@posteo.net>
- Loading branch information
Showing
6 changed files
with
33 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
use std::fs::create_dir_all; | ||
use std::path::Path; | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
extern crate libbpf_cargo; | ||
use libbpf_cargo::SkeletonBuilder; | ||
|
||
const SRC: &str = "./src/bpf/profile.bpf.c"; | ||
const SRC: &str = "src/bpf/profile.bpf.c"; | ||
|
||
fn main() { | ||
// It's unfortunate we cannot use `OUT_DIR` to store the generated skeleton. | ||
// Reasons are because the generated skeleton contains compiler attributes | ||
// that cannot be `include!()`ed via macro. And we cannot use the `#[path = "..."]` | ||
// trick either because you cannot yet `concat!(env!("OUT_DIR"), "/skel.rs")` inside | ||
// the path attribute either (see https://github.com/rust-lang/rust/pull/83366). | ||
// | ||
// However, there is hope! When the above feature stabilizes we can clean this | ||
// all up. | ||
create_dir_all("./src/bpf/.output").unwrap(); | ||
let skel = Path::new("./src/bpf/.output/profile.skel.rs"); | ||
let mut out = | ||
PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script")); | ||
out.push("profile.skel.rs"); | ||
|
||
SkeletonBuilder::new() | ||
.source(SRC) | ||
.build_and_generate(skel) | ||
.build_and_generate(out) | ||
.expect("bpf compilation failed"); | ||
println!("cargo:rerun-if-changed={}", SRC); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
use std::fs::create_dir_all; | ||
use std::path::Path; | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
use libbpf_cargo::SkeletonBuilder; | ||
|
||
const SRC: &str = "./src/bpf/tracecon.bpf.c"; | ||
const SRC: &str = "src/bpf/tracecon.bpf.c"; | ||
|
||
fn main() { | ||
// It's unfortunate we cannot use `OUT_DIR` to store the generated skeleton. | ||
// Reasons are because the generated skeleton contains compiler attributes | ||
// that cannot be `include!()`ed via macro. And we cannot use the `#[path = "..."]` | ||
// trick either because you cannot yet `concat!(env!("OUT_DIR"), "/skel.rs")` inside | ||
// the path attribute either (see https://github.com/rust-lang/rust/pull/83366). | ||
// | ||
// However, there is hope! When the above feature stabilizes we can clean this | ||
// all up. | ||
create_dir_all("./src/bpf/.output").unwrap(); | ||
let skel = Path::new("./src/bpf/.output/tracecon.skel.rs"); | ||
let mut out = | ||
PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script")); | ||
out.push("tracecon.skel.rs"); | ||
|
||
SkeletonBuilder::new() | ||
.source(SRC) | ||
.build_and_generate(&skel) | ||
.build_and_generate(&out) | ||
.expect("bpf compilation failed"); | ||
println!("cargo:rerun-if-changed={}", SRC); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,18 @@ | ||
use std::fs::create_dir_all; | ||
use std::path::Path; | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
use libbpf_cargo::SkeletonBuilder; | ||
|
||
const SRC: &str = "./src/bpf/xdppass.bpf.c"; | ||
const SRC: &str = "src/bpf/xdppass.bpf.c"; | ||
|
||
fn main() { | ||
// It's unfortunate we cannot use `OUT_DIR` to store the generated skeleton. | ||
// Reasons are because the generated skeleton contains compiler attributes | ||
// that cannot be `include!()`ed via macro. And we cannot use the `#[path = "..."]` | ||
// trick either because you cannot yet `concat!(env!("OUT_DIR"), "/skel.rs")` inside | ||
// the path attribute either (see https://github.com/rust-lang/rust/pull/83366). | ||
// | ||
// However, there is hope! When the above feature stabilizes we can clean this | ||
// all up. | ||
create_dir_all("./src/bpf/.output").unwrap(); | ||
let skel = Path::new("./src/bpf/.output/xdppass.skel.rs"); | ||
let mut out = | ||
PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script")); | ||
out.push("xdppass.skel.rs"); | ||
|
||
SkeletonBuilder::new() | ||
.source(SRC) | ||
.build_and_generate(&skel) | ||
.build_and_generate(out) | ||
.unwrap(); | ||
println!("cargo:rerun-if-changed={}", SRC); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters