Skip to content

Commit 73dcab7

Browse files
authored
feat(windows): build windows compressed file (#1860)
1 parent 61ea71b commit 73dcab7

File tree

3 files changed

+82
-12
lines changed

3 files changed

+82
-12
lines changed

.github/workflows/component_packages.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ jobs:
4747
toolchain: ${{ env.RUST_VERSION }}
4848
targets: >-
4949
aarch64-unknown-linux-musl,
50-
x86_64-unknown-linux-musl
50+
x86_64-unknown-linux-musl,
51+
x86_64-pc-windows-msvc
5152
5253
- name: cargo generate-lockfile
5354
if: hashFiles('Cargo.lock') == ''
@@ -70,6 +71,14 @@ jobs:
7071
run: |
7172
cargo install --locked cargo-zigbuild --force
7273
74+
- name: Install Windows cross-compilation dependencies
75+
run: |
76+
sudo apt-get install -y llvm
77+
78+
- name: Install cargo-xwin
79+
run: |
80+
cargo install --locked cargo-xwin --force
81+
7382
- name: Set tag and skip_upload=false for pre-release
7483
if: ${{ inputs.pre-release}}
7584
run: |
@@ -83,12 +92,12 @@ jobs:
8392
if: ${{ ! inputs.pre-release }}
8493
run: |
8594
git tag ${{ inputs.tag_name }}
86-
echo SKIP_UPLOAD=--skip=publish >> $GITHUB_ENV
87-
95+
echo SKIP_UPLOAD="--skip=publish" >> $GITHUB_ENV
96+
8897
- name: Skip packages sign
8998
if: ${{ inputs.skip_sign }}
9099
run: |
91-
echo SKIP_SIGN=--skip=sign >> $GITHUB_ENV
100+
echo SKIP_SIGN="--skip=sign" >> $GITHUB_ENV
92101
93102
- name: Release packages with GoReleaser
94103
uses: goreleaser/goreleaser-action@v6

.goreleaser.yml

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ env:
66
- NEWRELIC_INFRA_AGENT_VERSION=1.71.1
77
- NR_OTEL_COLLECTOR_VERSION=1.5.0
88
builds:
9-
- id: newrelic-agent-control
9+
# Linux builds using cargo zigbuild
10+
- id: newrelic-agent-control-linux
1011
builder: rust
12+
command: zigbuild
1113
binary: newrelic-agent-control
1214
targets:
1315
- x86_64-unknown-linux-musl
@@ -29,8 +31,28 @@ builds:
2931
- cmd: ./build/scripts/download_collector_config.sh
3032
env:
3133
- NR_OTEL_COLLECTOR_VERSION={{ .Env.NR_OTEL_COLLECTOR_VERSION }}
32-
- id: newrelic-agent-control-cli
34+
35+
# Windows builds using cargo xwin
36+
- id: newrelic-agent-control-windows
37+
builder: rust
38+
binary: newrelic-agent-control
39+
tool: cargo-xwin
40+
command: build
41+
targets:
42+
- x86_64-pc-windows-msvc
43+
flags:
44+
- --release
45+
- --package=newrelic_agent_control
46+
- --bin=newrelic-agent-control
47+
env:
48+
- AGENT_CONTROL_VERSION={{ .Version }}
49+
- NEWRELIC_INFRA_AGENT_VERSION={{ .Env.NEWRELIC_INFRA_AGENT_VERSION }}
50+
- NR_OTEL_COLLECTOR_VERSION={{ .Env.NR_OTEL_COLLECTOR_VERSION }}
51+
52+
# Linux builds for CLI
53+
- id: newrelic-agent-control-cli-linux
3354
builder: rust
55+
command: zigbuild
3456
binary: newrelic-agent-control-cli
3557
targets:
3658
- x86_64-unknown-linux-musl
@@ -42,14 +64,31 @@ builds:
4264
env:
4365
- AGENT_CONTROL_VERSION={{ .Version }}
4466

67+
# Windows builds for CLI using cargo xwin
68+
- id: newrelic-agent-control-cli-windows
69+
builder: rust
70+
binary: newrelic-agent-control-cli
71+
tool: cargo-xwin
72+
command: build
73+
targets:
74+
- x86_64-pc-windows-msvc
75+
flags:
76+
- --release
77+
- --package=newrelic_agent_control
78+
- --bin=newrelic-agent-control-cli
79+
env:
80+
- AGENT_CONTROL_VERSION={{ .Version }}
81+
hooks:
82+
pre:
83+
# Wait for newrelic-agent-control to be ready (parallel executions of cargo-xwin can be problematic)
84+
- 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'
85+
output: true
86+
4587
archives:
4688
- formats: tar.gz
4789
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
48-
ids:
49-
- newrelic-agent-control
50-
- newrelic-agent-control-cli
5190

52-
nfpms:
91+
nfpms: # deb and rpm are only built for linux targets
5392
- package_name: newrelic-agent-control
5493

5594
# Replace arch for rpm from amd64 to x86_64 to be consistent with our rpm repo.
@@ -165,8 +204,8 @@ nfpms:
165204

166205
id: newrelic-agent-control
167206
ids:
168-
- newrelic-agent-control
169-
- newrelic-agent-control-cli
207+
- newrelic-agent-control-linux
208+
- newrelic-agent-control-cli-linux
170209
formats:
171210
- deb
172211
- rpm

docs/DEVELOPMENT.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ To compile and run locally:
5353

5454
8. Execute the binary with the config file with `sudo ./target/debug/newrelic-agent-control`
5555

56+
#### Cross-compilation for Windows
57+
58+
The steps below work for the `x86_64-pc-windows-msvc` target only. It is also possible to compile the project for the `x86_64-pc-windows-gnu` target using `cargo-zigbuild`.
59+
60+
1. Install the [Rust toolchain](https://www.rust-lang.org/tools/install): `rustup target add x86_64-pc-windows-msvc`
61+
2. Install [cargo-xwin](https://github.com/rust-cross/cargo-xwin) and dependencies.
62+
Example for macOs:
63+
64+
```bash
65+
❯ brew install cmake ninja llvm
66+
❯ cargo install --locked cargo-xwin
67+
```
68+
69+
3. Compile agent-control:
70+
71+
```bash
72+
❯ cargo xwin build --bin newrelic-agent-control --target x86_64-pc-windows-msvc --release
73+
```
74+
75+
⚠️ This method doesn't work for building debug binaries (`--release` is required). As `cargo-xwin` doesn't provide `msvcrtd.lib` (the debug version of the C runtime library).
76+
77+
5678
#### Filesystem layout and persistence
5779

5880
The following shows the directory structure used by Agent Control, assuming an existing sub-agent with the ID `newrelic-infra`:

0 commit comments

Comments
 (0)