Skip to content

Commit

Permalink
feat(rust): download ebpf binary from artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjoDeundiak committed Sep 20, 2024
1 parent baca565 commit 40b7873
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file removed implementations/rust/ockam/ockam_ebpf/ockam_ebpf
Binary file not shown.
2 changes: 2 additions & 0 deletions implementations/rust/ockam/ockam_transport_tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ ebpf = ["pnet", "aya", "aya-log", "env_logger", "libc", "nix"]

[build-dependencies]
cfg_aliases = "0.2.1"
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls-native-roots"] }
url = "2.5.2"

[dependencies]
cfg-if = "1.0.0"
Expand Down
46 changes: 46 additions & 0 deletions implementations/rust/ockam/ockam_transport_tcp/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,50 @@ fn main() {
cfg_aliases! {
ebpf_alias: { all(target_os = "linux", feature = "ebpf") }
}

#[cfg(all(target_os = "linux", feature = "ebpf"))]
{
use std::env;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Duration;
use url::Url;

let out_dir = env::var("OUT_DIR").unwrap();

let output_file = PathBuf::from_str(&out_dir).unwrap().join("ockam_ebpf");

// TODO: Handle updates
if output_file.exists() {
return;
}

let url = "https://github.com/SanjoDeundiak/ebpf-test/releases/download/0.1.0/ockam_ebpf";

let url = Url::parse(url).unwrap().join("ockam_ebpf").unwrap();

let client_builder = reqwest::blocking::Client::builder();

// TODO: Also respect other variables, like CARGO_HTTP_PROXY
let client_builder = if let Ok(http_timeout) = env::var("CARGO_HTTP_TIMEOUT") {
if let Ok(http_timeout) = u64::from_str(&http_timeout) {
client_builder.timeout(Some(Duration::from_secs(http_timeout)))
} else {
client_builder
}
} else {
client_builder
};

let client = client_builder.build().unwrap();

let ebpf = client
.get(url)
.send()
.expect("Error downloading eBPF")
.bytes()
.expect("Error downloading eBPF");

std::fs::write(&output_file, ebpf).unwrap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ impl TcpTransportEbpfSupport {
// runtime. This approach is recommended for most real-world use cases. If you would
// like to specify the eBPF program at runtime rather than at compile-time, you can
// reach for `Bpf::load_file` instead.
let ebpf_binary = aya::include_bytes_aligned!(concat!(std::env!("OUT_DIR"), "/ockam_ebpf"));

let ebpf_binary = aya::include_bytes_aligned!("../../../ockam_ebpf/ockam_ebpf");
let mut bpf = Bpf::load(ebpf_binary).map_err(map_bpf_error)?;
// eBPF can be read from the filesystem in the runtime for development purposes
// let ebpf_binary = std::fs::read(PATH).unwrap();
Expand Down

0 comments on commit 40b7873

Please sign in to comment.