Skip to content

Commit 7edf1b8

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

File tree

6 files changed

+151
-23
lines changed

6 files changed

+151
-23
lines changed

.github/workflows/component_packages.yml

Lines changed: 29 additions & 15 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,33 @@ 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 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
92+
93+
- name: Install go-winres
94+
run: go install github.com/tc-hib/go-winres@latest
8195

8296
- name: If pre-release, set tag and verify it matches Cargo.toml version
8397
if: ${{ inputs.pre-release}}
@@ -101,22 +115,22 @@ jobs:
101115
echo SKIP_WINDOWS_SIGN="true" >> $GITHUB_ENV
102116
103117
- name: Release packages with GoReleaser
104-
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6
118+
uses: goreleaser/goreleaser-action@v6
105119
with:
106-
args: release ${{ env.SKIP_UPLOAD_RELEASE }} ${{ env.SKIP_SIGN }} --clean --verbose --timeout 2h
120+
args: release ${{ env.SKIP_UPLOAD_RELEASE }} ${{ env.SKIP_SIGN }} --clean --verbose --timeout 2h --parallelism 1
107121
env:
108122
GITHUB_TOKEN: ${{ secrets.gh_token }}
109-
GPG_PRIVATE_KEY_BASE64: ${{ secrets.gpg_private_key_base64 }} # base64 encoded
123+
GPG_PRIVATE_KEY_BASE64: ${{ secrets.gpg_private_key_base64 }}
110124
GPG_PASSPHRASE: ${{ secrets.gpg_passphrase }}
111-
PFX_CERTIFICATE_BASE64: ${{ secrets.pfx_certificate_base64 }} # base64 encoded
125+
PFX_CERTIFICATE_BASE64: ${{ secrets.pfx_certificate_base64 }}
112126
PFX_PASSPHRASE: ${{ secrets.pfx_passphrase }}
113127
GPG_MAIL: 'infrastructure-eng@newrelic.com'
114128
NR_RELEASE_TAG: ${{ inputs.tag_name }}
115129
GORELEASER_CURRENT_TAG: ${{ inputs.tag_name }}
116130
SKIP_WINDOWS_SIGN: ${{ env.SKIP_WINDOWS_SIGN }}
117131

118132
- name: Upload assets to pipeline
119-
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
133+
uses: actions/upload-artifact@v4
120134
with:
121135
retention-days: 1
122136
name: built-binaries-${{ inputs.tag_name }}
@@ -130,10 +144,10 @@ jobs:
130144
needs: build
131145
if: ${{ ! inputs.skip_sign }}
132146
steps:
133-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
147+
- uses: actions/checkout@v4
134148

135149
- name: Download built binaries
136-
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
150+
uses: actions/download-artifact@v4
137151
with:
138152
name: built-binaries-${{ inputs.tag_name }}
139153
path: ./artifacts
@@ -144,4 +158,4 @@ jobs:
144158
./build/scripts/windows-exec-sign/verify-signature.ps1 -Executables @(
145159
"./artifacts/dist/newrelic-agent-control-windows_x86_64-pc-windows-msvc/newrelic-agent-control.exe",
146160
"./artifacts/dist/newrelic-agent-control-cli-windows_x86_64-pc-windows-msvc/newrelic-agent-control-cli.exe"
147-
)
161+
)

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

0 commit comments

Comments
 (0)