Skip to content

Commit

Permalink
integration-test: Remove cargo symlink workaround
Browse files Browse the repository at this point in the history
rust-lang/cargo#12369 fixed this bug and was
picked up in rust-lang/rust#114027.
  • Loading branch information
tamird committed Aug 23, 2023
1 parent 1fa1241 commit ca2e43d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
1 change: 1 addition & 0 deletions test/integration-ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ aya-bpf = { path = "../../bpf/aya-bpf" }
aya-log-ebpf = { path = "../../bpf/aya-log-ebpf" }

[build-dependencies]
which = { workspace = true }
xtask = { path = "../../xtask" }

[[bin]]
Expand Down
14 changes: 5 additions & 9 deletions test/integration-ebpf/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{env, path::PathBuf};
use std::env;

use xtask::{create_symlink_to_binary, AYA_BUILD_INTEGRATION_BPF};
use which::which;
use xtask::AYA_BUILD_INTEGRATION_BPF;

/// Building this crate has an undeclared dependency on the `bpf-linker` binary. This would be
/// better expressed by [artifact-dependencies][bindeps] but issues such as
Expand All @@ -24,12 +25,7 @@ fn main() {
.unwrap_or_default();

if build_integration_bpf {
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = PathBuf::from(out_dir);
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 bpf_linker = which("bpf-linker").unwrap();
println!("cargo:rerun-if-changed={}", bpf_linker.to_str().unwrap());
}
}
30 changes: 1 addition & 29 deletions xtask/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use anyhow::{bail, Context as _, Result};
use std::{
fs,
path::{Path, PathBuf},
process::Command,
};
use which::which;
use std::process::Command;

pub const AYA_BUILD_INTEGRATION_BPF: &str = "AYA_BUILD_INTEGRATION_BPF";
pub const LIBBPF_DIR: &str = "xtask/libbpf";
Expand All @@ -18,26 +13,3 @@ pub fn exec(cmd: &mut Command) -> Result<()> {
}
Ok(())
}

// Create a symlink in the out directory to work around the fact that cargo ignores anything
// in `$CARGO_HOME`, which is also where `cargo install` likes to place binaries. Cargo will
// stat through the symlink and discover that the binary has changed.
//
// This was introduced in https://github.com/rust-lang/cargo/commit/99f841c.
//
// TODO(https://github.com/rust-lang/cargo/pull/12369): Remove this when the fix is available.
pub fn create_symlink_to_binary(out_dir: &Path, binary_name: &str) -> Result<PathBuf> {
let binary = which(binary_name).unwrap();
let symlink = out_dir.join(binary_name);
match fs::remove_file(&symlink) {
Ok(()) => {}
Err(err) => {
if err.kind() != std::io::ErrorKind::NotFound {
return Err(err).context(format!("failed to remove symlink {}", symlink.display()));
}
}
}
std::os::unix::fs::symlink(binary, &symlink)
.with_context(|| format!("failed to create symlink {}", symlink.display()))?;
Ok(symlink)
}

0 comments on commit ca2e43d

Please sign in to comment.