Skip to content

Commit ca2e43d

Browse files
committed
integration-test: Remove cargo symlink workaround
rust-lang/cargo#12369 fixed this bug and was picked up in rust-lang/rust#114027.
1 parent 1fa1241 commit ca2e43d

File tree

3 files changed

+7
-38
lines changed

3 files changed

+7
-38
lines changed

test/integration-ebpf/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ aya-bpf = { path = "../../bpf/aya-bpf" }
99
aya-log-ebpf = { path = "../../bpf/aya-log-ebpf" }
1010

1111
[build-dependencies]
12+
which = { workspace = true }
1213
xtask = { path = "../../xtask" }
1314

1415
[[bin]]

test/integration-ebpf/build.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use std::{env, path::PathBuf};
1+
use std::env;
22

3-
use xtask::{create_symlink_to_binary, AYA_BUILD_INTEGRATION_BPF};
3+
use which::which;
4+
use xtask::AYA_BUILD_INTEGRATION_BPF;
45

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

2627
if build_integration_bpf {
27-
let out_dir = env::var_os("OUT_DIR").unwrap();
28-
let out_dir = PathBuf::from(out_dir);
29-
let bpf_linker_symlink = create_symlink_to_binary(&out_dir, "bpf-linker").unwrap();
30-
println!(
31-
"cargo:rerun-if-changed={}",
32-
bpf_linker_symlink.to_str().unwrap()
33-
);
28+
let bpf_linker = which("bpf-linker").unwrap();
29+
println!("cargo:rerun-if-changed={}", bpf_linker.to_str().unwrap());
3430
}
3531
}

xtask/src/lib.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
use anyhow::{bail, Context as _, Result};
2-
use std::{
3-
fs,
4-
path::{Path, PathBuf},
5-
process::Command,
6-
};
7-
use which::which;
2+
use std::process::Command;
83

94
pub const AYA_BUILD_INTEGRATION_BPF: &str = "AYA_BUILD_INTEGRATION_BPF";
105
pub const LIBBPF_DIR: &str = "xtask/libbpf";
@@ -18,26 +13,3 @@ pub fn exec(cmd: &mut Command) -> Result<()> {
1813
}
1914
Ok(())
2015
}
21-
22-
// Create a symlink in the out directory to work around the fact that cargo ignores anything
23-
// in `$CARGO_HOME`, which is also where `cargo install` likes to place binaries. Cargo will
24-
// stat through the symlink and discover that the binary has changed.
25-
//
26-
// This was introduced in https://github.com/rust-lang/cargo/commit/99f841c.
27-
//
28-
// TODO(https://github.com/rust-lang/cargo/pull/12369): Remove this when the fix is available.
29-
pub fn create_symlink_to_binary(out_dir: &Path, binary_name: &str) -> Result<PathBuf> {
30-
let binary = which(binary_name).unwrap();
31-
let symlink = out_dir.join(binary_name);
32-
match fs::remove_file(&symlink) {
33-
Ok(()) => {}
34-
Err(err) => {
35-
if err.kind() != std::io::ErrorKind::NotFound {
36-
return Err(err).context(format!("failed to remove symlink {}", symlink.display()));
37-
}
38-
}
39-
}
40-
std::os::unix::fs::symlink(binary, &symlink)
41-
.with_context(|| format!("failed to create symlink {}", symlink.display()))?;
42-
Ok(symlink)
43-
}

0 commit comments

Comments
 (0)