integration-test: build-dep on integration-ebpf

Remove the manual dependency tracking machinery in
integration-test/build.rs in favor of a build-dependency on
integration-ebpf. This required adding an empty lib.rs to create the
library target.

This allows integration-test/build.rs to be ignorant of bpf-linker.
Remove that in favor of the logic now in integration-ebpf.
reviewable/pr677/r10
Tamir Duberstein 1 year ago
parent e276c07f73
commit 6fc09ca07a
No known key found for this signature in database

@ -0,0 +1,3 @@
#![no_std]
// This file exists to enable the library target.

@ -25,4 +25,17 @@ tokio = { version = "1.24", default-features = false, features = [
[build-dependencies]
cargo_metadata = { version = "0.15.4", default-features = false }
# TODO(https://github.com/rust-lang/cargo/issues/12375): this should be an artifact dependency, but
# it's not possible to tell cargo to use `-Z build-std` to build it. We cargo-in-cargo in the build
# script to build this, but we want to teach cargo about the dependecy so that cache invalidation
# works properly.
#
# Note also that https://github.com/rust-lang/cargo/issues/10593 occurs when `target = ...` is added
# to an artifact dependency; it seems possible to work around that by setting `resolver = "1"` in
# Cargo.toml in the workspace root.
#
# Finally note that *any* usage of `artifact = ...` in *any* Cargo.toml in the workspace breaks
# workflows with stable cargo; stable cargo outright refuses to load manifests that use unstable
# features.
integration-ebpf = { path = "../integration-ebpf" }
xtask = { path = "../../xtask" }

@ -1,5 +1,4 @@
use std::{
collections::{HashMap, HashSet},
env,
ffi::OsString,
fmt::Write as _,
@ -10,9 +9,9 @@ use std::{
};
use cargo_metadata::{
Artifact, CompilerMessage, Dependency, Message, Metadata, MetadataCommand, Package, Target,
Artifact, CompilerMessage, Message, Metadata, MetadataCommand, Package, Target,
};
use xtask::{create_symlink_to_binary, exec, AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR};
use xtask::{exec, AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR};
fn main() {
println!("cargo:rerun-if-env-changed={}", AYA_BUILD_INTEGRATION_BPF);
@ -23,16 +22,11 @@ fn main() {
.map(Result::unwrap)
.unwrap_or_default();
const INTEGRATION_EBPF_PACKAGE: &str = "integration-ebpf";
let Metadata { packages, .. } = MetadataCommand::new().no_deps().exec().unwrap();
let packages: HashMap<String, _> = packages
let integration_ebpf_package = packages
.into_iter()
.map(|package| {
let Package { name, .. } = &package;
(name.clone(), package)
})
.collect();
.find(|Package { name, .. }| name == "integration-ebpf")
.unwrap();
let manifest_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
let manifest_dir = PathBuf::from(manifest_dir);
@ -116,27 +110,8 @@ fn main() {
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 bpf_linker_symlink = create_symlink_to_binary(&out_dir, "bpf-linker").unwrap();
println!(
"cargo:rerun-if-changed={}",
bpf_linker_symlink.to_str().unwrap()
);
let Package { manifest_path, .. } = integration_ebpf_package;
let integration_ebpf_dir = manifest_path.parent().unwrap();
let mut cmd = Command::new("cargo");
cmd.args([
@ -150,8 +125,6 @@ fn main() {
]);
// Workaround to make sure that the rust-toolchain.toml is respected.
let Package { manifest_path, .. } = packages.get(INTEGRATION_EBPF_PACKAGE).unwrap();
let integration_ebpf_dir = manifest_path.parent().unwrap();
cmd.env_remove("RUSTUP_TOOLCHAIN")
.current_dir(integration_ebpf_dir);
@ -209,7 +182,7 @@ fn main() {
fs::write(&dst, []).unwrap_or_else(|err| panic!("failed to create {dst:?}: {err}"));
}
let Package { targets, .. } = packages.get(INTEGRATION_EBPF_PACKAGE).unwrap();
let Package { targets, .. } = integration_ebpf_package;
for Target { name, kind, .. } in targets {
if *kind != ["bin"] {
continue;

Loading…
Cancel
Save