Skip to content

Commit 96f8e05

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

File tree

6 files changed

+142
-22
lines changed

6 files changed

+142
-22
lines changed

.github/workflows/component_packages.yml

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ jobs:
3838
runs-on: ubuntu-latest
3939
name: Build and upload
4040
steps:
41-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
41+
- uses: actions/checkout@v4
4242
with:
4343
fetch-depth: 0
4444

45-
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6
45+
- uses: actions/setup-go@v5
4646
with:
4747
go-version-file: 'build/embedded/go.mod'
4848
check-latest: true
@@ -65,19 +65,30 @@ jobs:
6565
save-cache: false
6666

6767
- name: Install Zig
68-
uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2
68+
uses: mlugg/setup-zig@v2
6969

70-
- uses: taiki-e/install-action@288875dd3d64326724fa6d9593062d9f8ba0b131 # v2.67.30
70+
- uses: taiki-e/install-action@v2
7171
with:
7272
tool: cargo-zigbuild@0.20.1
7373

7474
- name: Install Windows cross-compilation dependencies
7575
run: |
76-
sudo apt-get install -y llvm
76+
sudo apt-get update && sudo apt-get install -y llvm mingw-w64 nasm
77+
sudo ln -sf /usr/bin/llvm-ar /usr/bin/llvm-lib
7778
78-
- name: Install cargo-xwin
79+
- name: Install and Pre-cache cargo-xwin
7980
run: |
80-
cargo install --locked cargo-xwin --force
81+
cargo install --locked cargo-xwin
82+
83+
rm -rf /home/runner/.cache/cargo-xwin
84+
85+
cd /tmp
86+
cargo new pre_cache_dummy
87+
cd pre_cache_dummy
88+
89+
cargo xwin build --target x86_64-pc-windows-msvc
90+
91+
cd $GITHUB_WORKSPACE
8192
8293
- name: If pre-release, set tag and verify it matches Cargo.toml version
8394
if: ${{ inputs.pre-release}}
@@ -101,22 +112,22 @@ jobs:
101112
echo SKIP_WINDOWS_SIGN="true" >> $GITHUB_ENV
102113
103114
- name: Release packages with GoReleaser
104-
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
115+
uses: goreleaser/goreleaser-action@v6
105116
with:
106117
args: release ${{ env.SKIP_UPLOAD_RELEASE }} ${{ env.SKIP_SIGN }} --clean --verbose --timeout 2h
107118
env:
108119
GITHUB_TOKEN: ${{ secrets.gh_token }}
109-
GPG_PRIVATE_KEY_BASE64: ${{ secrets.gpg_private_key_base64 }} # base64 encoded
120+
GPG_PRIVATE_KEY_BASE64: ${{ secrets.gpg_private_key_base64 }}
110121
GPG_PASSPHRASE: ${{ secrets.gpg_passphrase }}
111-
PFX_CERTIFICATE_BASE64: ${{ secrets.pfx_certificate_base64 }} # base64 encoded
122+
PFX_CERTIFICATE_BASE64: ${{ secrets.pfx_certificate_base64 }}
112123
PFX_PASSPHRASE: ${{ secrets.pfx_passphrase }}
113124
GPG_MAIL: 'infrastructure-eng@newrelic.com'
114125
NR_RELEASE_TAG: ${{ inputs.tag_name }}
115126
GORELEASER_CURRENT_TAG: ${{ inputs.tag_name }}
116127
SKIP_WINDOWS_SIGN: ${{ env.SKIP_WINDOWS_SIGN }}
117128

118129
- name: Upload assets to pipeline
119-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
130+
uses: actions/upload-artifact@v4
120131
with:
121132
retention-days: 1
122133
name: built-binaries-${{ inputs.tag_name }}
@@ -130,10 +141,10 @@ jobs:
130141
needs: build
131142
if: ${{ ! inputs.skip_sign }}
132143
steps:
133-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
144+
- uses: actions/checkout@v4
134145

135146
- name: Download built binaries
136-
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
147+
uses: actions/download-artifact@v4
137148
with:
138149
name: built-binaries-${{ inputs.tag_name }}
139150
path: ./artifacts
@@ -144,4 +155,4 @@ jobs:
144155
./build/scripts/windows-exec-sign/verify-signature.ps1 -Executables @(
145156
"./artifacts/dist/newrelic-agent-control-windows_x86_64-pc-windows-msvc/newrelic-agent-control.exe",
146157
"./artifacts/dist/newrelic-agent-control-cli-windows_x86_64-pc-windows-msvc/newrelic-agent-control-cli.exe"
147-
)
158+
)

.goreleaser.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ builds:
8686
env:
8787
- AGENT_CONTROL_VERSION={{ .Version }}
8888
hooks:
89-
pre:
90-
# Wait for newrelic-agent-control to be ready (parallel executions of cargo-xwin can be problematic)
91-
- cmd: sh -c 'while [ ! -f target/x86_64-pc-windows-msvc/release/newrelic-agent-control.exe ]; do echo "Waiting for newrelic-agent-control-windows build to complete..."; sleep 5; done'
92-
output: true
89+
# pre:
90+
# # Wait for newrelic-agent-control to be ready (parallel executions of cargo-xwin can be problematic)
91+
# - cmd: sh -c 'while [ ! -f target/x86_64-pc-windows-msvc/release/newrelic-agent-control.exe ]; do echo "Waiting for newrelic-agent-control-windows build to complete..."; sleep 5; done'
92+
# output: true
9393
post:
9494
# This step cannot be done inside the 'signs' section because that happens after packaging.
9595
- cmd: ./build/scripts/windows-exec-sign/sign.sh

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: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,24 @@ const GENERATED_REGISTRY_FILE: &str = "generated_agent_type_registry.rs";
1212

1313
fn main() {
1414
generate_agent_type_registry();
15-
// setup the env variable for the generated registry path
15+
1616
println!("cargo:rustc-env=GENERATED_REGISTRY_FILE={GENERATED_REGISTRY_FILE}");
17-
// re-run only if the registry has changed
18-
println!("cargo:rerun-if-changed={REGISTRY_PATH}")
17+
println!("cargo:rerun-if-changed={REGISTRY_PATH}");
18+
19+
let target = env::var("TARGET").unwrap_or_default();
20+
let host = env::var("HOST").unwrap_or_default();
21+
22+
println!("cargo:warning=Build.rs Diagnostic: Host is {}", host);
23+
println!("cargo:warning=Build.rs Diagnostic: Target is {}", target);
24+
25+
println!("cargo:rerun-if-env-changed=AGENT_CONTROL_VERSION");
26+
27+
if target.contains("windows") {
28+
println!("cargo:warning=Build.rs: Target is Windows, applying resources...");
29+
set_windows_resources();
30+
} else {
31+
println!("cargo:warning=Build.rs: Target is NOT Windows. Skipping resources.");
32+
}
1933
}
2034

2135
fn generate_agent_type_registry() {
@@ -42,3 +56,72 @@ fn generate_agent_type_registry() {
4256
let dest_path = Path::new(&out_dir).join(GENERATED_REGISTRY_FILE);
4357
fs::write(dest_path, contents).expect("Could not write the filesystem registry file");
4458
}
59+
60+
fn set_windows_resources() {
61+
let original_target = std::env::var("TARGET").unwrap_or_default();
62+
let host = std::env::var("HOST").unwrap_or_default();
63+
64+
let is_msvc_cross = host.contains("linux") && original_target.contains("msvc");
65+
if is_msvc_cross {
66+
println!("cargo:warning=Aplicando hack de winres: Cambiando TARGET a gnu temporalmente");
67+
unsafe {
68+
env::set_var("TARGET", "x86_64-pc-windows-gnu");
69+
}
70+
}
71+
72+
let mut res = winres::WindowsResource::new();
73+
74+
if is_msvc_cross {
75+
res.set_windres_path("x86_64-w64-mingw32-windres");
76+
}
77+
78+
res.set("FileDescription", "New Relic Agent Control");
79+
res.set("ProductName", "New Relic Agent Control");
80+
res.set("CompanyName", "New Relic, Inc.");
81+
res.set(
82+
"LegalCopyright",
83+
"© 2026 New Relic, Inc. All rights reserved.",
84+
);
85+
res.set("OriginalFilename", "newrelic-agent-control.exe");
86+
87+
if let Ok(version) = env::var("AGENT_CONTROL_VERSION") {
88+
let clean_version = version.trim_start_matches('v');
89+
let version_semver = format!("{}.0", clean_version);
90+
91+
if let Ok(u64_version) = parse_version_u64(&version_semver) {
92+
res.set_version_info(winres::VersionInfo::PRODUCTVERSION, u64_version);
93+
res.set_version_info(winres::VersionInfo::FILEVERSION, u64_version);
94+
}
95+
96+
res.set("ProductVersion", &version);
97+
res.set("FileVersion", &version);
98+
}
99+
100+
res.compile()
101+
.expect("Failed to compile Windows resources. Is 'mingw-w64' installed?");
102+
103+
if is_msvc_cross {
104+
unsafe {
105+
env::set_var("TARGET", &original_target);
106+
}
107+
}
108+
}
109+
110+
// Helper to convert string "1.9.1" to u64 (Windows binary format X.X.X.X)
111+
fn parse_version_u64(v: &str) -> Result<u64, std::num::ParseIntError> {
112+
let parts: Result<Vec<u16>, _> = v.split('.').map(|s| s.parse()).collect();
113+
114+
let parts = parts?;
115+
116+
// We expect for example "1.9.1".
117+
// .first() -> 1 (Major)
118+
// .get(1) -> 9 (Minor)
119+
// .get(2) -> 1 (Patch)
120+
// .get(3) -> None -> defaults to 0 (Build)
121+
let major = *parts.first().unwrap_or(&0) as u64;
122+
let minor = *parts.get(1).unwrap_or(&0) as u64;
123+
let patch = *parts.get(2).unwrap_or(&0) as u64;
124+
let build = *parts.get(3).unwrap_or(&0) as u64;
125+
126+
Ok((major << 48) | (minor << 32) | (patch << 16) | build)
127+
}

0 commit comments

Comments
 (0)