diff options
author | Daniel Mueller <muellerd@meta.com> | 2024-02-02 06:10:48 -0800 |
---|---|---|
committer | Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> | 2024-02-02 06:10:48 -0800 |
commit | 37ee74ce1827a65b41b0f0cfeb55840e58df534d (patch) | |
tree | 2efd7e22abcc51de43901151da071b70613b7bce | |
parent | 0f677792c4da4ad4d11e0a0c5ecda7a19ad63e7a (diff) |
Use OUT_DIR in build script
Summary:
The comment inside the build script is misleading: The issue referenced
won't resolve the problem indicated. However, if we switch to using the
include! macro for sourcing the generated skeleton, we can use the
$OUT_DIR variable just fine.
Reviewed By: dtolnay
Differential Revision: D53323352
fbshipit-source-id: c83fae5f35bc01bea4dafde71128256bf1fb10cb
-rw-r--r-- | below/build.rs | 20 | ||||
-rw-r--r-- | below/src/open_source/mod.rs | 5 |
2 files changed, 10 insertions, 15 deletions
diff --git a/below/build.rs b/below/build.rs index dcbb29fc..9f6723e0 100644 --- a/below/build.rs +++ b/below/build.rs @@ -12,29 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -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/exitstat.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/exitstat.skel.rs"); + let mut out = + PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR must be set in build script")); + out.push("exitstat.skel.rs"); + let mut builder = SkeletonBuilder::new(); builder.source(SRC); if let Some(clang) = option_env!("CLANG") { builder.clang(clang); } - builder.build_and_generate(&skel).unwrap(); + builder.build_and_generate(out).unwrap(); println!("cargo:rerun-if-changed={}", SRC); } diff --git a/below/src/open_source/mod.rs b/below/src/open_source/mod.rs index f3e4cc1a..485b322f 100644 --- a/below/src/open_source/mod.rs +++ b/below/src/open_source/mod.rs @@ -12,8 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -#[path = "../bpf/.output/exitstat.skel.rs"] -mod bpf; +mod bpf { + include!(concat!(env!("OUT_DIR"), "/exitstat.skel.rs")); +} pub mod commands; pub mod gpu_stats; pub mod init; |