Skip to content

Commit

Permalink
integration-ebpf: artifact dependency bpf-linker
Browse files Browse the repository at this point in the history
- integration-ebpf: add artifact dependency on bpf-linker.
- integration-ebpf: remove manual rerun-if-changed=bpf-linker.
- integration-ebpf: make bpf-linker availble to rustc in build.rs.
- xtask: filter for test binaries now that the build also produces the
  bpf-linker binary.
- github: remove `cargo install bpf-linker`.
- integration-test: remove bpf-linker installation instructions.

Blockers:
- rust-lang/cargo#12385 (artifact = "bin"
  makes entire workspace nightly-only).
  • Loading branch information
tamird committed Nov 7, 2023
1 parent e68fa14 commit d261880
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 23 deletions.
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ linker = "arm-linux-gnueabihf-gcc"

[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"

# See https://github.com/rust-lang/rust-analyzer/issues/14510.
#
# Turns out this affects all cargo invocations in the project, not just rust-analyzer.
[unstable]
bindeps = true
12 changes: 0 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,6 @@ jobs:

- uses: Swatinem/rust-cache@v2

- name: bpf-linker
run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git

- uses: taiki-e/install-action@cargo-hack
- name: Build
env:
Expand Down Expand Up @@ -185,10 +182,6 @@ jobs:
sudo apt update
sudo apt -y install clang gcc-multilib llvm locate qemu-system-{arm,x86}
- name: bpf-linker
if: runner.os == 'Linux'
run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git

- name: Install prerequisites
if: runner.os == 'macOS'
# The xargs shipped on macOS always exits 0 with -P0, so we need GNU findutils.
Expand All @@ -211,11 +204,6 @@ jobs:
# https://github.com/Homebrew/homebrew-core/issues/140244
codesign --verify $(which qemu-system-x86_64) || brew reinstall qemu --build-from-source
- name: bpf-linker
if: runner.os == 'macOS'
# NB: rustc doesn't ship libLLVM.so on macOS, so disable proxying (default feature).
run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git --no-default-features

- name: Download debian kernels
if: runner.arch == 'ARM64'
run: |
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ aya-obj = { path = "aya-obj", version = "0.1.0", default-features = false }
aya-tool = { path = "aya-tool", default-features = false }
bindgen = { version = "0.69", default-features = false }
bitflags = { version = "2.2.1", default-features = false }
bpf-linker = { version = "0.9.10", artifact = "bin" }
bytes = { version = "1", default-features = false }
cargo_metadata = { version = "0.18.0", default-features = false }
clap = { version = "4", default-features = false }
Expand Down Expand Up @@ -95,7 +96,6 @@ test-log = { version = "0.2.13", default-features = false }
testing_logger = { version = "0.1.1", default-features = false }
thiserror = { version = "1", default-features = false }
tokio = { version = "1.24.0", default-features = false }
which = { version = "5.0.0", default-features = false }
xtask = { path = "xtask", default-features = false }

[profile.dev]
Expand All @@ -107,3 +107,6 @@ panic = "abort"
[profile.release.package.integration-ebpf]
debug = 2
codegen-units = 1

[patch.crates-io]
bpf-linker = { git = "https://github.com/aya-rs/bpf-linker.git", artifact = "bin" }
1 change: 0 additions & 1 deletion test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ You'll need:

1. `rustup toolchain install nightly`
1. `rustup target add {aarch64,x86_64}-unknown-linux-musl`
1. `cargo install bpf-linker`
1. (virtualized only) `qemu`

## Usage
Expand Down
2 changes: 1 addition & 1 deletion test/integration-ebpf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ aya-bpf = { path = "../../bpf/aya-bpf" }
aya-log-ebpf = { path = "../../bpf/aya-log-ebpf" }

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

[[bin]]
name = "log"
Expand Down
30 changes: 26 additions & 4 deletions test/integration-ebpf/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::env;

use which::which;
use xtask::AYA_BUILD_INTEGRATION_BPF;

/// Building this crate has an undeclared dependency on the `bpf-linker` binary. This would be
Expand All @@ -25,7 +23,31 @@ fn main() {
.unwrap_or_default();

if build_integration_bpf {
let bpf_linker = which("bpf-linker").unwrap();
println!("cargo:rerun-if-changed={}", bpf_linker.to_str().unwrap());
let out_dir = env::var_os("OUT_DIR").unwrap();
let out_dir = std::path::PathBuf::from(out_dir);

let bpf_linker = env::var("CARGO_BIN_FILE_BPF_LINKER").unwrap();

// There seems to be no way to pass `-Clinker={}` to rustc from here.
//
// We assume rustc is going to look for `bpf-linker` on the PATH, so we can create a symlink
// and put it on the PATH.
let bin_dir = out_dir.join("bin");
std::fs::create_dir_all(&bin_dir).unwrap();
let bpf_linker_symlink = bin_dir.join("bpf-linker");
match std::fs::remove_file(&bpf_linker_symlink) {
Ok(()) => {}
Err(err) => {
if err.kind() != std::io::ErrorKind::NotFound {
panic!("failed to remove symlink: {err}")
}
}
}
std::os::unix::fs::symlink(bpf_linker, bpf_linker_symlink).unwrap();
let path = env::var_os("PATH");
let path = path.as_ref();
let paths = std::iter::once(bin_dir).chain(path.into_iter().flat_map(env::split_paths));
let path = env::join_paths(paths).unwrap();
println!("cargo:rustc-env=PATH={}", path.to_str().unwrap());
}
}
1 change: 0 additions & 1 deletion xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ rustdoc-json = { workspace = true }
rustup-toolchain = { workspace = true }
syn = { workspace = true }
tempfile = { workspace = true }
which = { workspace = true }
9 changes: 6 additions & 3 deletions xtask/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
};

use anyhow::{anyhow, bail, Context as _, Result};
use cargo_metadata::{Artifact, CompilerMessage, Message, Target};
use cargo_metadata::{Artifact, ArtifactProfile, CompilerMessage, Message, Target};
use clap::Parser;
use xtask::{exec, Errors, AYA_BUILD_INTEGRATION_BPF};

Expand Down Expand Up @@ -79,10 +79,13 @@ where
Message::CompilerArtifact(Artifact {
executable,
target: Target { name, .. },
profile: ArtifactProfile { test, .. },
..
}) => {
if let Some(executable) = executable {
executables.push((name, executable.into()));
if test {
if let Some(executable) = executable {
executables.push((name, executable.into()));
}
}
}
Message::CompilerMessage(CompilerMessage { message, .. }) => {
Expand Down

0 comments on commit d261880

Please sign in to comment.