Skip to content

Commit 8dd4e4a

Browse files
authored
Fix hardcode paths (#46)
1 parent db22351 commit 8dd4e4a

File tree

5 files changed

+46
-16
lines changed

5 files changed

+46
-16
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ jobs:
2121
run: cargo xtask build-ebpf
2222

2323
- name: Build oryx-tui
24-
run: cargo build
24+
run: cargo xtask build
2525

2626
- name: Linting
2727
run: |
28-
cargo clippy --workspace --all-features -- -D warnings
28+
cargo xtask lint
2929
cargo fmt --all -- --check
3030
cd oryx-ebpf
3131
cargo clippy --workspace --all-features -- -D warnings

oryx-tui/src/ebpf/egress.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ pub fn load_egress(
5454
#[cfg(debug_assertions)]
5555
let mut bpf = match EbpfLoader::new()
5656
.set_global("TRAFFIC_DIRECTION", &traffic_direction, true)
57-
.load(include_bytes_aligned!(
58-
"../../../target/bpfel-unknown-none/debug/oryx"
59-
)) {
57+
.load(include_bytes_aligned!(env!("ORYX_BIN_PATH")))
58+
{
6059
Ok(v) => v,
6160
Err(e) => {
6261
error!("Fail to load the egress eBPF bytecode. {}", e);
@@ -73,9 +72,8 @@ pub fn load_egress(
7372
#[cfg(not(debug_assertions))]
7473
let mut bpf = match EbpfLoader::new()
7574
.set_global("TRAFFIC_DIRECTION", &traffic_direction, true)
76-
.load(include_bytes_aligned!(
77-
"../../../target/bpfel-unknown-none/debug/oryx"
78-
)) {
75+
.load(include_bytes_aligned!(env!("ORYX_BIN_PATH")))
76+
{
7977
Ok(v) => v,
8078
Err(e) => {
8179
error!("Fail to load the egress eBPF bytecode. {}", e);

oryx-tui/src/ebpf/ingress.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ pub fn load_ingress(
5454
#[cfg(debug_assertions)]
5555
let mut bpf = match EbpfLoader::new()
5656
.set_global("TRAFFIC_DIRECTION", &traffic_direction, true)
57-
.load(include_bytes_aligned!(
58-
"../../../target/bpfel-unknown-none/debug/oryx"
59-
)) {
57+
.load(include_bytes_aligned!(env!("ORYX_BIN_PATH")))
58+
{
6059
Ok(v) => v,
6160
Err(e) => {
6261
error!("Failed to load the ingress eBPF bytecode. {}", e);
@@ -73,9 +72,8 @@ pub fn load_ingress(
7372
#[cfg(not(debug_assertions))]
7473
let mut bpf = match EbpfLoader::new()
7574
.set_global("TRAFFIC_DIRECTION", &traffic_direction, true)
76-
.load(include_bytes_aligned!(
77-
"../../../target/bpfel-unknown-none/debug/oryx"
78-
)) {
75+
.load(include_bytes_aligned!(env!("ORYX_BIN_PATH")))
76+
{
7977
Ok(v) => v,
8078
Err(e) => {
8179
error!("Failed to load the ingress eBPF bytecode. {}", e);

xtask/src/build.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::process::Command;
1+
use std::{path::Path, process::Command};
22

33
use anyhow::Context as _;
44
use clap::Parser;
@@ -15,12 +15,24 @@ pub struct Options {
1515
pub release: bool,
1616
}
1717

18+
/// Set the ORYX_BIN_PATH env var based on build option
19+
fn set_ebpf_build_base_dir(build_type: &str) {
20+
let path = Path::new(env!("CARGO_MANIFEST_DIR"))
21+
.join(format!("../target/bpfel-unknown-none/{build_type}/oryx"))
22+
.to_path_buf();
23+
std::env::set_var("ORYX_BIN_PATH", &path);
24+
}
25+
1826
/// Build the project
1927
fn build_project(opts: &Options) -> Result<(), anyhow::Error> {
2028
let mut args = vec!["build"];
2129
if opts.release {
22-
args.push("--release")
30+
args.push("--release");
31+
set_ebpf_build_base_dir("release");
32+
} else {
33+
set_ebpf_build_base_dir("debug");
2334
}
35+
2436
let status = Command::new("cargo")
2537
.args(&args)
2638
.status()
@@ -40,3 +52,23 @@ pub fn build(opts: Options) -> Result<(), anyhow::Error> {
4052
build_project(&opts).context("Error while building userspace application")?;
4153
Ok(())
4254
}
55+
56+
57+
/// Run linter on the project with ORYX_BIN_DIR env var set
58+
pub fn lint() -> Result<(), anyhow::Error> {
59+
set_ebpf_build_base_dir("debug");
60+
let status = Command::new("cargo")
61+
.args([
62+
"clippy",
63+
"--workspace",
64+
"--all-features",
65+
"--",
66+
"-D",
67+
"warnings",
68+
])
69+
.status()
70+
.expect("failed to build userspace");
71+
72+
assert!(status.success());
73+
Ok(())
74+
}

xtask/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum Command {
1717
BuildEbpf(build_ebpf::Options),
1818
Run(run::Options),
1919
Build(build::Options),
20+
Lint,
2021
}
2122

2223
fn main() {
@@ -27,6 +28,7 @@ fn main() {
2728
BuildEbpf(opts) => build_ebpf::build_ebpf(opts),
2829
Run(opts) => run::run(opts),
2930
Build(opts) => build::build(opts),
31+
Lint => build::lint(),
3032
};
3133

3234
if let Err(e) = ret {

0 commit comments

Comments
 (0)