|
|
@ -8,7 +8,6 @@ use std::{
|
|
|
|
use cargo_metadata::{
|
|
|
|
use cargo_metadata::{
|
|
|
|
Artifact, CompilerMessage, Message, Metadata, MetadataCommand, Package, Target,
|
|
|
|
Artifact, CompilerMessage, Message, Metadata, MetadataCommand, Package, Target,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use xtask::AYA_BUILD_EBPF;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// This crate has a runtime dependency on artifacts produced by the `{{project-name}}-ebpf` crate.
|
|
|
|
/// This crate has a runtime dependency on artifacts produced by the `{{project-name}}-ebpf` crate.
|
|
|
|
/// This would be better expressed as one or more [artifact-dependencies][bindeps] but issues such
|
|
|
|
/// This would be better expressed as one or more [artifact-dependencies][bindeps] but issues such
|
|
|
@ -20,32 +19,8 @@ use xtask::AYA_BUILD_EBPF;
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// prevent their use for the time being.
|
|
|
|
/// prevent their use for the time being.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// This file, along with the xtask crate, allows analysis tools such as `cargo check`, `cargo
|
|
|
|
|
|
|
|
/// clippy`, and even `cargo build` to work as users expect. Prior to this file's existence, this
|
|
|
|
|
|
|
|
/// crate's undeclared dependency on artifacts from `{{project-name}}-ebpf` would cause build (and
|
|
|
|
|
|
|
|
/// `cargo check`, and `cargo clippy`) failures until the user ran certain other commands in the
|
|
|
|
|
|
|
|
/// workspace. Conversely, those same tools (e.g. cargo test --no-run) would produce stale results
|
|
|
|
|
|
|
|
/// if run naively because they'd make use of artifacts from a previous build of
|
|
|
|
|
|
|
|
/// `{{project-name}}-ebpf`.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Note that this solution is imperfect: in particular it has to balance correctness with
|
|
|
|
|
|
|
|
/// performance; an environment variable is used to replace true builds of `{{project-name}}-ebpf`
|
|
|
|
|
|
|
|
/// with stubs to preserve the property that code generation and linking (in
|
|
|
|
|
|
|
|
/// `{{project-name}}-ebpf`) do not occur on metadata-only actions such as `cargo check` or `cargo
|
|
|
|
|
|
|
|
/// clippy` of this crate. This means that naively attempting to `cargo test --no-run` this crate
|
|
|
|
|
|
|
|
/// will produce binaries that fail at runtime because the stubs are inadequate for actually running
|
|
|
|
|
|
|
|
/// the tests.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// [bindeps]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies
|
|
|
|
/// [bindeps]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies
|
|
|
|
fn main() {
|
|
|
|
fn main() {
|
|
|
|
println!("cargo:rerun-if-env-changed={}", AYA_BUILD_EBPF);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let build_ebpf = env::var(AYA_BUILD_EBPF)
|
|
|
|
|
|
|
|
.as_deref()
|
|
|
|
|
|
|
|
.map(str::parse)
|
|
|
|
|
|
|
|
.map(Result::unwrap)
|
|
|
|
|
|
|
|
.unwrap_or_default();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let Metadata { packages, .. } = MetadataCommand::new().no_deps().exec().unwrap();
|
|
|
|
let Metadata { packages, .. } = MetadataCommand::new().no_deps().exec().unwrap();
|
|
|
|
let ebpf_package = packages
|
|
|
|
let ebpf_package = packages
|
|
|
|
.into_iter()
|
|
|
|
.into_iter()
|
|
|
@ -64,6 +39,9 @@ fn main() {
|
|
|
|
panic!("unsupported endian={:?}", endian)
|
|
|
|
panic!("unsupported endian={:?}", endian)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(https://github.com/rust-lang/cargo/issues/4001): Make this `false` if we can determine
|
|
|
|
|
|
|
|
// we're in a check build.
|
|
|
|
|
|
|
|
let build_ebpf = true;
|
|
|
|
if build_ebpf {
|
|
|
|
if build_ebpf {
|
|
|
|
let arch = env::var_os("CARGO_CFG_TARGET_ARCH").unwrap();
|
|
|
|
let arch = env::var_os("CARGO_CFG_TARGET_ARCH").unwrap();
|
|
|
|
|
|
|
|
|
|
|
@ -94,7 +72,7 @@ fn main() {
|
|
|
|
cmd.env("CARGO_CFG_BPF_TARGET_ARCH", arch);
|
|
|
|
cmd.env("CARGO_CFG_BPF_TARGET_ARCH", arch);
|
|
|
|
|
|
|
|
|
|
|
|
// Workaround to make sure that the rust-toolchain.toml is respected.
|
|
|
|
// Workaround to make sure that the rust-toolchain.toml is respected.
|
|
|
|
for key in ["RUSTUP_TOOLCHAIN", "RUSTC"] {
|
|
|
|
for key in ["RUSTUP_TOOLCHAIN", "RUSTC", "RUSTC_WORKSPACE_WRAPPER"] {
|
|
|
|
cmd.env_remove(key);
|
|
|
|
cmd.env_remove(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cmd.current_dir(ebpf_dir);
|
|
|
|
cmd.current_dir(ebpf_dir);
|
|
|
|