Skip to content

Commit

Permalink
feat: add features info to cli version info
Browse files Browse the repository at this point in the history
Also make build info parseable.

Closes #25
  • Loading branch information
EHfive committed Jan 23, 2025
1 parent 613a260 commit 4062977
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Configuration file:
- Architecture: [e.g. x86-64, aarch64]
- Linux distribution and version: [e.g. Arch Linux (rolling), OpenWrt (v23.05.5)]
- Kernel version: [e.g. 5.15, 6.7.1]
- einat version: [e.g. 0.1.1]
- einat version(`einat -v`): [e.g. `version: 0.1.5 features: aya build_features: pkg-config`]

**Additional context**
Add any other context about the problem here, e.g. network interface information, firewall(iptables/nftables) configuration.
Expand Down
38 changes: 38 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,51 @@ fn libbpf_skel_build() {
.unwrap();
}

fn gen_build_info() {
macro_rules! enabled_features {
($($feat:literal),+) => {
&[ $(#[cfg(feature = $feat)] $feat),+ ]
};
}

let features: &[&str] = enabled_features!("ipv6", "aya", "libbpf", "libbpf-skel");
let build_features: &[&str] = enabled_features!("pkg-config", "bindgen", "static");
let features = features.join(",");
let build_features = build_features.join(",");

// IMPORTANT:
// use format `<key>: <value>[ <key>: <value>]+`, <key> and <value> should not contains any whitespace,
// so the printed build info text can be parsed.
let build_info = [
("version", env!("CARGO_PKG_VERSION").to_string()),
("features", features),
("build_features", build_features),
];

let build_info = build_info
.iter()
.map(|(k, v)| {
if v.is_empty() {
format!("{k}: <none>")
} else {
format!("{k}: {v}")
}
})
.collect::<Vec<_>>()
.join(" ");

println!("cargo:rustc-env=EINAT_BUILD_INFO={}", build_info);
}

fn main() {
#[cfg(any(feature = "aya", feature = "libbpf"))]
einat_obj_build();

#[cfg(feature = "libbpf-skel")]
libbpf_skel_build();

gen_build_info();

println!("cargo:rerun-if-changed={}", SRC_DIR);
println!("cargo:rerun-if-changed=build.rs");
}
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn parse_env_args() -> Result<Args> {
std::process::exit(0);
}
Short('v') | Long("version") => {
println!("v{}", env!("CARGO_PKG_VERSION"));
println!("{}", env!("EINAT_BUILD_INFO"));
std::process::exit(0);
}
Short('c') | Long("config") => {
Expand Down

0 comments on commit 4062977

Please sign in to comment.