Skip to content

Commit e208c78

Browse files
committed
fix: add exe metadata
1 parent a25d69c commit e208c78

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

Cargo.lock

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

THIRD_PARTY_NOTICES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,12 @@ Distributed under the following license(s):
30453045

30463046
* MIT
30473047

3048+
## winres <https://crates.io/crates/winres>
3049+
3050+
Distributed under the following license(s):
3051+
3052+
* MIT
3053+
30483054
## wit-bindgen <https://crates.io/crates/wit-bindgen>
30493055

30503056
Distributed under the following license(s):

agent-control/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ tokio-stream = { version = "0.1.18", features = ["net"] }
118118

119119
[build-dependencies]
120120
glob = "0.3.3"
121+
winres = "0.1"
121122

122123
[[bin]]
123124
name = "newrelic-agent-control-k8s"

agent-control/build.rs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ fn main() {
1515
// setup the env variable for the generated registry path
1616
println!("cargo:rustc-env=GENERATED_REGISTRY_FILE={GENERATED_REGISTRY_FILE}");
1717
// re-run only if the registry has changed
18-
println!("cargo:rerun-if-changed={REGISTRY_PATH}")
18+
println!("cargo:rerun-if-changed={REGISTRY_PATH}");
19+
20+
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
21+
if target_os == "windows" {
22+
set_windows_resources();
23+
}
1924
}
2025

2126
fn generate_agent_type_registry() {
@@ -42,3 +47,52 @@ fn generate_agent_type_registry() {
4247
let dest_path = Path::new(&out_dir).join(GENERATED_REGISTRY_FILE);
4348
fs::write(dest_path, contents).expect("Could not write the filesystem registry file");
4449
}
50+
51+
fn set_windows_resources() {
52+
let mut res = winres::WindowsResource::new();
53+
54+
res.set("FileDescription", "New Relic Agent Control");
55+
res.set("ProductName", "New Relic Agent Control");
56+
res.set("CompanyName", "New Relic, Inc.");
57+
res.set(
58+
"LegalCopyright",
59+
"© 2026 New Relic, Inc. All rights reserved.",
60+
);
61+
res.set("OriginalFilename", "newrelic-agent-control.exe");
62+
63+
if let Ok(version) = env::var("AGENT_CONTROL_VERSION") {
64+
let clean_version = version.trim_start_matches('v');
65+
66+
let version_semver = format!("{}.0", clean_version);
67+
68+
if let Ok(u64_version) = parse_version_u64(&version_semver) {
69+
res.set_version_info(winres::VersionInfo::PRODUCTVERSION, u64_version);
70+
res.set_version_info(winres::VersionInfo::FILEVERSION, u64_version);
71+
}
72+
73+
res.set("ProductVersion", &version);
74+
res.set("FileVersion", &version);
75+
}
76+
77+
res.compile()
78+
.expect("Failed to compile Windows resources. Is 'mingw-w64' installed?");
79+
}
80+
81+
// Helper to convert string "1.9.1" to u64 (Windows binary format X.X.X.X)
82+
fn parse_version_u64(v: &str) -> Result<u64, std::num::ParseIntError> {
83+
let parts: Result<Vec<u16>, _> = v.split('.').map(|s| s.parse()).collect();
84+
85+
let parts = parts?;
86+
87+
// We expect for example "1.9.1".
88+
// .first() -> 1 (Major)
89+
// .get(1) -> 9 (Minor)
90+
// .get(2) -> 1 (Patch)
91+
// .get(3) -> None -> defaults to 0 (Build)
92+
let major = *parts.first().unwrap_or(&0) as u64;
93+
let minor = *parts.get(1).unwrap_or(&0) as u64;
94+
let patch = *parts.get(2).unwrap_or(&0) as u64;
95+
let build = *parts.get(3).unwrap_or(&0) as u64;
96+
97+
Ok((major << 48) | (minor << 32) | (patch << 16) | build)
98+
}

0 commit comments

Comments
 (0)