Skip to content

Commit 7dade21

Browse files
committed
feat: add cargo-binstall support with versioned release artifacts
1 parent 5dfa304 commit 7dade21

File tree

4 files changed

+104
-33
lines changed

4 files changed

+104
-33
lines changed

.dagger/main.go

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,21 @@ func (m *HttpNu) DarwinEnv(
3838
)
3939
}
4040

41-
func (m *HttpNu) DarwinBuild(ctx context.Context, src *dagger.Directory) *dagger.File {
42-
return m.DarwinEnv(ctx, src).
41+
func (m *HttpNu) DarwinBuild(ctx context.Context, src *dagger.Directory, version string) *dagger.File {
42+
container := m.DarwinEnv(ctx, src).
4343
WithExec([]string{"rustup", "update", "stable"}).
4444
WithExec([]string{"rustup", "default", "stable"}).
4545
WithExec([]string{"rustup", "target", "add", "aarch64-apple-darwin"}).
46-
WithExec([]string{"./scripts/cross-build-darwin.sh", "--release"}).
47-
WithExec([]string{"tar", "-czf", "/tmp/http-nu-darwin-arm64.tar.gz", "-C", "/app/target/aarch64-apple-darwin/release", "http-nu"}).
48-
File("/tmp/http-nu-darwin-arm64.tar.gz")
46+
WithExec([]string{"./scripts/cross-build-darwin.sh", "--release"})
47+
48+
container = container.WithExec([]string{"sh", "-c", `
49+
mkdir -p /tmp/http-nu-` + version + `
50+
cp /app/target/aarch64-apple-darwin/release/http-nu /tmp/http-nu-` + version + `/
51+
cd /tmp
52+
tar -czf http-nu-` + version + `-darwin-arm64.tar.gz http-nu-` + version + `
53+
`})
54+
55+
return container.File("/tmp/http-nu-" + version + "-darwin-arm64.tar.gz")
4956
}
5057

5158
func (m *HttpNu) WindowsEnv(
@@ -71,15 +78,22 @@ func (m *HttpNu) WindowsEnv(
7178
)
7279
}
7380

74-
func (m *HttpNu) WindowsBuild(ctx context.Context, src *dagger.Directory) *dagger.File {
75-
return m.WindowsEnv(ctx, src).
81+
func (m *HttpNu) WindowsBuild(ctx context.Context, src *dagger.Directory, version string) *dagger.File {
82+
container := m.WindowsEnv(ctx, src).
7683
WithExec([]string{"rustup", "update", "stable"}).
7784
WithExec([]string{"rustup", "default", "stable"}).
7885
WithExec([]string{"rustup", "target", "add", "x86_64-pc-windows-gnu"}).
7986
WithExec([]string{"cargo", "check", "--release", "--tests", "--target", "x86_64-pc-windows-gnu"}).
80-
WithExec([]string{"cargo", "build", "--release", "--target", "x86_64-pc-windows-gnu"}).
81-
WithExec([]string{"tar", "-czf", "/tmp/http-nu-windows-amd64.tar.gz", "-C", "/app/target/x86_64-pc-windows-gnu/release", "http-nu.exe"}).
82-
File("/tmp/http-nu-windows-amd64.tar.gz")
87+
WithExec([]string{"cargo", "build", "--release", "--target", "x86_64-pc-windows-gnu"})
88+
89+
container = container.WithExec([]string{"sh", "-c", `
90+
mkdir -p /tmp/http-nu-` + version + `
91+
cp /app/target/x86_64-pc-windows-gnu/release/http-nu.exe /tmp/http-nu-` + version + `/
92+
cd /tmp
93+
tar -czf http-nu-` + version + `-windows-amd64.tar.gz http-nu-` + version + `
94+
`})
95+
96+
return container.File("/tmp/http-nu-" + version + "-windows-amd64.tar.gz")
8397
}
8498

8599
func (m *HttpNu) LinuxArm64Env(
@@ -94,11 +108,18 @@ func (m *HttpNu) LinuxArm64Env(
94108
)
95109
}
96110

97-
func (m *HttpNu) LinuxArm64Build(ctx context.Context, src *dagger.Directory) *dagger.File {
98-
return m.LinuxArm64Env(ctx, src).
99-
WithExec([]string{"cargo", "build", "--release", "--target", "aarch64-unknown-linux-musl"}).
100-
WithExec([]string{"tar", "-czf", "/tmp/http-nu-linux-arm64.tar.gz", "-C", "/app/target/aarch64-unknown-linux-musl/release", "http-nu"}).
101-
File("/tmp/http-nu-linux-arm64.tar.gz")
111+
func (m *HttpNu) LinuxArm64Build(ctx context.Context, src *dagger.Directory, version string) *dagger.File {
112+
container := m.LinuxArm64Env(ctx, src).
113+
WithExec([]string{"cargo", "build", "--release", "--target", "aarch64-unknown-linux-musl"})
114+
115+
container = container.WithExec([]string{"sh", "-c", `
116+
mkdir -p /tmp/http-nu-` + version + `
117+
cp /app/target/aarch64-unknown-linux-musl/release/http-nu /tmp/http-nu-` + version + `/
118+
cd /tmp
119+
tar -czf http-nu-` + version + `-linux-arm64.tar.gz http-nu-` + version + `
120+
`})
121+
122+
return container.File("/tmp/http-nu-" + version + "-linux-arm64.tar.gz")
102123
}
103124

104125
func (m *HttpNu) LinuxAmd64Env(
@@ -113,9 +134,16 @@ func (m *HttpNu) LinuxAmd64Env(
113134
)
114135
}
115136

116-
func (m *HttpNu) LinuxAmd64Build(ctx context.Context, src *dagger.Directory) *dagger.File {
117-
return m.LinuxAmd64Env(ctx, src).
118-
WithExec([]string{"cargo", "build", "--release", "--target", "x86_64-unknown-linux-musl"}).
119-
WithExec([]string{"tar", "-czf", "/tmp/http-nu-linux-amd64.tar.gz", "-C", "/app/target/x86_64-unknown-linux-musl/release", "http-nu"}).
120-
File("/tmp/http-nu-linux-amd64.tar.gz")
137+
func (m *HttpNu) LinuxAmd64Build(ctx context.Context, src *dagger.Directory, version string) *dagger.File {
138+
container := m.LinuxAmd64Env(ctx, src).
139+
WithExec([]string{"cargo", "build", "--release", "--target", "x86_64-unknown-linux-musl"})
140+
141+
container = container.WithExec([]string{"sh", "-c", `
142+
mkdir -p /tmp/http-nu-` + version + `
143+
cp /app/target/x86_64-unknown-linux-musl/release/http-nu /tmp/http-nu-` + version + `/
144+
cd /tmp
145+
tar -czf http-nu-` + version + `-linux-amd64.tar.gz http-nu-` + version + `
146+
`})
147+
148+
return container.File("/tmp/http-nu-" + version + "-linux-amd64.tar.gz")
121149
}

.github/workflows/release-binaries.yml

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,40 @@ jobs:
2323
include:
2424
- target: darwin-arm64
2525
dagger_fn: darwin-build
26-
artifact: http-nu-darwin-arm64.tar.gz
26+
artifact_suffix: darwin-arm64.tar.gz
2727

2828
- target: windows-amd64
2929
dagger_fn: windows-build
30-
artifact: http-nu-windows-amd64.tar.gz
30+
artifact_suffix: windows-amd64.tar.gz
3131

3232
- target: linux-arm64
3333
dagger_fn: linux-arm-64-build
34-
artifact: http-nu-linux-arm64.tar.gz
34+
artifact_suffix: linux-arm64.tar.gz
3535

3636
- target: linux-amd64
3737
dagger_fn: linux-amd-64-build
38-
artifact: http-nu-linux-amd64.tar.gz
38+
artifact_suffix: linux-amd64.tar.gz
3939

4040
steps:
4141
# 1) Check out source
4242
- uses: actions/checkout@v4
4343

44-
# 2) Free up disk space (Windows cross-compile needs ~20GB)
44+
# 2) Sanitize ref name (replace / with -)
45+
- name: Set version
46+
id: version
47+
run: |
48+
VERSION="${{ github.ref_name }}"
49+
VERSION_SAFE="${VERSION//\//-}"
50+
echo "version=$VERSION_SAFE" >> "$GITHUB_OUTPUT"
51+
echo "artifact=http-nu-${VERSION_SAFE}-${{ matrix.artifact_suffix }}" >> "$GITHUB_OUTPUT"
52+
53+
# 3) Free up disk space (Windows cross-compile needs ~20GB)
4554
- name: Free disk space
4655
run: |
4756
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc /opt/hostedtoolcache/CodeQL
4857
sudo docker image prune --all --force
4958
50-
# 3) Cache Dagger BuildKit cache (restore and save)
59+
# 4) Cache Dagger BuildKit cache (restore and save)
5160
- name: Cache Dagger
5261
uses: actions/cache@v4
5362
with:
@@ -56,31 +65,31 @@ jobs:
5665
restore-keys: |
5766
dagger-${{ runner.os }}-${{ matrix.target }}-
5867
59-
# 4) Boot the Dagger engine
68+
# 5) Boot the Dagger engine
6069
- name: Setup Dagger
6170
uses: dagger/dagger-for-github@8.0.0
6271
with:
6372
version: "0.18.10"
6473
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
6574

66-
# 5) Defensive: pre-pull the engine image
75+
# 6) Defensive: pre-pull the engine image
6776
- name: Pre-pull Dagger Engine
6877
run: docker pull registry.dagger.io/engine:v0.18.10
6978

70-
# 6) Run one Dagger build function and export artifact
79+
# 7) Run one Dagger build function and export artifact
7180
- name: Build with Dagger
7281
uses: dagger/dagger-for-github@8.0.0
7382
with:
7483
version: "0.18.10"
75-
call: ${{ matrix.dagger_fn }} --src upload --src . export --path ./artifacts/${{ matrix.artifact }}
84+
call: ${{ matrix.dagger_fn }} --src upload --src . --version ${{ steps.version.outputs.version }} export --path ./artifacts/${{ steps.version.outputs.artifact }}
7685
cloud-token: ${{ secrets.DAGGER_CLOUD_TOKEN }}
7786

78-
# 7) Upload artifact for fan-in job
87+
# 8) Upload artifact for fan-in job
7988
- name: Upload artifact
8089
uses: actions/upload-artifact@v4
8190
with:
82-
name: ${{ matrix.artifact }}
83-
path: ./artifacts/${{ matrix.artifact }}
91+
name: ${{ steps.version.outputs.artifact }}
92+
path: ./artifacts/${{ steps.version.outputs.artifact }}
8493

8594
#-----------------------------------------------------------
8695
# 2. Fan-in job - gather artifacts and create prerelease

Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@ syntect = "5.3.0"
8989
lto = true
9090
codegen-units = 1
9191

92+
[package.metadata.binstall]
93+
pkg-url = "{ repo }/releases/download/v{ version }/http-nu-v{ version }-{ target-family }.tar.gz"
94+
bin-dir = "http-nu-v{ version }/{ bin }{ binary-ext }"
95+
pkg-fmt = "tgz"
96+
97+
[package.metadata.binstall.overrides.x86_64-unknown-linux-gnu]
98+
pkg-url = "{ repo }/releases/download/v{ version }/http-nu-v{ version }-linux-amd64.tar.gz"
99+
100+
[package.metadata.binstall.overrides.x86_64-unknown-linux-musl]
101+
pkg-url = "{ repo }/releases/download/v{ version }/http-nu-v{ version }-linux-amd64.tar.gz"
102+
103+
[package.metadata.binstall.overrides.aarch64-unknown-linux-gnu]
104+
pkg-url = "{ repo }/releases/download/v{ version }/http-nu-v{ version }-linux-arm64.tar.gz"
105+
106+
[package.metadata.binstall.overrides.aarch64-unknown-linux-musl]
107+
pkg-url = "{ repo }/releases/download/v{ version }/http-nu-v{ version }-linux-arm64.tar.gz"
108+
109+
[package.metadata.binstall.overrides.aarch64-apple-darwin]
110+
pkg-url = "{ repo }/releases/download/v{ version }/http-nu-v{ version }-darwin-arm64.tar.gz"
111+
112+
[package.metadata.binstall.overrides.x86_64-pc-windows-msvc]
113+
pkg-url = "{ repo }/releases/download/v{ version }/http-nu-v{ version }-windows-amd64.tar.gz"
114+
115+
[package.metadata.binstall.overrides.x86_64-pc-windows-gnu]
116+
pkg-url = "{ repo }/releases/download/v{ version }/http-nu-v{ version }-windows-amd64.tar.gz"
117+
92118
[dev-dependencies]
93119
tempfile = "3.10.1"
94120
assert_cmd = "2.0"

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ brew install cablehead/tap/http-nu
9393

9494
### cargo
9595

96+
For fast installation using pre-built binaries:
97+
98+
```bash
99+
cargo binstall http-nu
100+
```
101+
102+
Or build from source:
103+
96104
```bash
97105
cargo install http-nu --locked
98106
```

0 commit comments

Comments
 (0)