Skip to content

Commit d5f8534

Browse files
feat: build windows executable
1 parent 16515a8 commit d5f8534

File tree

8 files changed

+291
-0
lines changed

8 files changed

+291
-0
lines changed

.github/workflows/release.yml

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
# Copyright 2022-2023, axodotdev
2+
# SPDX-License-Identifier: MIT or Apache-2.0
3+
#
4+
# CI that:
5+
#
6+
# * checks for a Git Tag that looks like a release
7+
# * builds artifacts with cargo-dist (archives, installers, hashes)
8+
# * uploads those artifacts to temporary workflow zip
9+
# * on success, uploads the artifacts to a Github Release
10+
#
11+
# Note that the Github Release will be created with a generated
12+
# title/body based on your changelogs.
13+
14+
name: Release
15+
16+
permissions:
17+
contents: write
18+
19+
# This task will run whenever you push a git tag that looks like a version
20+
# like "1.0.0", "v0.1.0-prerelease.1", "my-app/0.1.0", "releases/v1.0.0", etc.
21+
# Various formats will be parsed into a VERSION and an optional PACKAGE_NAME, where
22+
# PACKAGE_NAME must be the name of a Cargo package in your workspace, and VERSION
23+
# must be a Cargo-style SemVer Version (must have at least major.minor.patch).
24+
#
25+
# If PACKAGE_NAME is specified, then the announcement will be for that
26+
# package (erroring out if it doesn't have the given version or isn't cargo-dist-able).
27+
#
28+
# If PACKAGE_NAME isn't specified, then the announcement will be for all
29+
# (cargo-dist-able) packages in the workspace with that version (this mode is
30+
# intended for workspaces with only one dist-able package, or with all dist-able
31+
# packages versioned/released in lockstep).
32+
#
33+
# If you push multiple tags at once, separate instances of this workflow will
34+
# spin up, creating an independent announcement for each one. However Github
35+
# will hard limit this to 3 tags per commit, as it will assume more tags is a
36+
# mistake.
37+
#
38+
# If there's a prerelease-style suffix to the version, then the release(s)
39+
# will be marked as a prerelease.
40+
on:
41+
push:
42+
tags:
43+
- '**[0-9]+.[0-9]+.[0-9]+*'
44+
pull_request:
45+
46+
jobs:
47+
# Run 'cargo dist plan' (or host) to determine what tasks we need to do
48+
plan:
49+
runs-on: ubuntu-latest
50+
outputs:
51+
val: ${{ steps.plan.outputs.manifest }}
52+
tag: ${{ !github.event.pull_request && github.ref_name || '' }}
53+
tag-flag: ${{ !github.event.pull_request && format('--tag={0}', github.ref_name) || '' }}
54+
publishing: ${{ !github.event.pull_request }}
55+
env:
56+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
steps:
58+
- uses: actions/checkout@v4
59+
with:
60+
submodules: recursive
61+
- name: Install cargo-dist
62+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.5.0/cargo-dist-installer.sh | sh"
63+
# sure would be cool if github gave us proper conditionals...
64+
# so here's a doubly-nested ternary-via-truthiness to try to provide the best possible
65+
# functionality based on whether this is a pull_request, and whether it's from a fork.
66+
# (PRs run on the *source* but secrets are usually on the *target* -- that's *good*
67+
# but also really annoying to build CI around when it needs secrets to work right.)
68+
- id: plan
69+
run: |
70+
cargo dist ${{ !github.event.pull_request && format('host --steps=create --tag={0}', github.ref_name) || (github.event.pull_request.head.repo.fork && 'plan' || 'host --steps=check') }} --output-format=json > dist-manifest.json
71+
echo "cargo dist ran successfully"
72+
cat dist-manifest.json
73+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
74+
- name: "Upload dist-manifest.json"
75+
uses: actions/upload-artifact@v3
76+
with:
77+
name: artifacts
78+
path: dist-manifest.json
79+
80+
# Build and packages all the platform-specific things
81+
build-local-artifacts:
82+
name: build-local-artifacts (${{ join(matrix.targets, ', ') }})
83+
# Let the initial task tell us to not run (currently very blunt)
84+
needs: plan
85+
if: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix.include != null && (needs.plan.outputs.publishing == 'true' || fromJson(needs.plan.outputs.val).ci.github.pr_run_mode == 'upload') }}
86+
strategy:
87+
fail-fast: false
88+
# Target platforms/runners are computed by cargo-dist in create-release.
89+
# Each member of the matrix has the following arguments:
90+
#
91+
# - runner: the github runner
92+
# - dist-args: cli flags to pass to cargo dist
93+
# - install-dist: expression to run to install cargo-dist on the runner
94+
#
95+
# Typically there will be:
96+
# - 1 "global" task that builds universal installers
97+
# - N "local" tasks that build each platform's binaries and platform-specific installers
98+
matrix: ${{ fromJson(needs.plan.outputs.val).ci.github.artifacts_matrix }}
99+
runs-on: ${{ matrix.runner }}
100+
env:
101+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
BUILD_MANIFEST_NAME: target/distrib/${{ join(matrix.targets, '-') }}-dist-manifest.json
103+
steps:
104+
- uses: actions/checkout@v4
105+
with:
106+
submodules: recursive
107+
- uses: swatinem/rust-cache@v2
108+
- name: Install cargo-dist
109+
run: ${{ matrix.install_dist }}
110+
# Get the dist-manifest
111+
- name: Fetch local artifacts
112+
uses: actions/download-artifact@v3
113+
with:
114+
name: artifacts
115+
path: target/distrib/
116+
- name: Install dependencies
117+
run: |
118+
${{ matrix.packages_install }}
119+
- name: Build artifacts
120+
run: |
121+
# Actually do builds and make zips and whatnot
122+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --print=linkage --output-format=json ${{ matrix.dist_args }} > dist-manifest.json
123+
echo "cargo dist ran successfully"
124+
- id: cargo-dist
125+
name: Post-build
126+
# We force bash here just because github makes it really hard to get values up
127+
# to "real" actions without writing to env-vars, and writing to env-vars has
128+
# inconsistent syntax between shell and powershell.
129+
shell: bash
130+
run: |
131+
# Parse out what we just built and upload it to scratch storage
132+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
133+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
134+
echo "EOF" >> "$GITHUB_OUTPUT"
135+
136+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
137+
- name: "Upload artifacts"
138+
uses: actions/upload-artifact@v3
139+
with:
140+
name: artifacts
141+
path: |
142+
${{ steps.cargo-dist.outputs.paths }}
143+
${{ env.BUILD_MANIFEST_NAME }}
144+
145+
# Build and package all the platform-agnostic(ish) things
146+
build-global-artifacts:
147+
needs:
148+
- plan
149+
- build-local-artifacts
150+
runs-on: "ubuntu-20.04"
151+
env:
152+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
153+
BUILD_MANIFEST_NAME: target/distrib/dist-manifest.json
154+
steps:
155+
- uses: actions/checkout@v4
156+
with:
157+
submodules: recursive
158+
- name: Install cargo-dist
159+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.5.0/cargo-dist-installer.sh | sh"
160+
# Get all the local artifacts for the global tasks to use (for e.g. checksums)
161+
- name: Fetch local artifacts
162+
uses: actions/download-artifact@v3
163+
with:
164+
name: artifacts
165+
path: target/distrib/
166+
- id: cargo-dist
167+
shell: bash
168+
run: |
169+
cargo dist build ${{ needs.plan.outputs.tag-flag }} --output-format=json "--artifacts=global" > dist-manifest.json
170+
echo "cargo dist ran successfully"
171+
172+
# Parse out what we just built and upload it to scratch storage
173+
echo "paths<<EOF" >> "$GITHUB_OUTPUT"
174+
jq --raw-output ".artifacts[]?.path | select( . != null )" dist-manifest.json >> "$GITHUB_OUTPUT"
175+
echo "EOF" >> "$GITHUB_OUTPUT"
176+
177+
cp dist-manifest.json "$BUILD_MANIFEST_NAME"
178+
- name: "Upload artifacts"
179+
uses: actions/upload-artifact@v3
180+
with:
181+
name: artifacts
182+
path: |
183+
${{ steps.cargo-dist.outputs.paths }}
184+
${{ env.BUILD_MANIFEST_NAME }}
185+
# Determines if we should publish/announce
186+
host:
187+
needs:
188+
- plan
189+
- build-local-artifacts
190+
- build-global-artifacts
191+
# Only run if we're "publishing", and only if local and global didn't fail (skipped is fine)
192+
if: ${{ always() && needs.plan.outputs.publishing == 'true' && (needs.build-global-artifacts.result == 'skipped' || needs.build-global-artifacts.result == 'success') && (needs.build-local-artifacts.result == 'skipped' || needs.build-local-artifacts.result == 'success') }}
193+
env:
194+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
195+
runs-on: "ubuntu-20.04"
196+
outputs:
197+
val: ${{ steps.host.outputs.manifest }}
198+
steps:
199+
- uses: actions/checkout@v4
200+
with:
201+
submodules: recursive
202+
- name: Install cargo-dist
203+
run: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/axodotdev/cargo-dist/releases/download/v0.5.0/cargo-dist-installer.sh | sh"
204+
# Fetch artifacts from scratch-storage
205+
- name: Fetch artifacts
206+
uses: actions/download-artifact@v3
207+
with:
208+
name: artifacts
209+
path: target/distrib/
210+
# This is a harmless no-op for Github Releases, hosting for that happens in "announce"
211+
- id: host
212+
shell: bash
213+
run: |
214+
cargo dist host ${{ needs.plan.outputs.tag-flag }} --steps=upload --steps=release --output-format=json > dist-manifest.json
215+
echo "artifacts uploaded and released successfully"
216+
cat dist-manifest.json
217+
echo "manifest=$(jq -c "." dist-manifest.json)" >> "$GITHUB_OUTPUT"
218+
- name: "Upload dist-manifest.json"
219+
uses: actions/upload-artifact@v3
220+
with:
221+
name: artifacts
222+
path: dist-manifest.json
223+
224+
# Create a Github Release while uploading all files to it
225+
announce:
226+
needs:
227+
- plan
228+
- host
229+
# use "always() && ..." to allow us to wait for all publish jobs while
230+
# still allowing individual publish jobs to skip themselves (for prereleases).
231+
# "host" however must run to completion, no skipping allowed!
232+
if: ${{ always() && needs.host.result == 'success' }}
233+
runs-on: "ubuntu-20.04"
234+
env:
235+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
236+
steps:
237+
- uses: actions/checkout@v4
238+
with:
239+
submodules: recursive
240+
- name: "Download Github Artifacts"
241+
uses: actions/download-artifact@v3
242+
with:
243+
name: artifacts
244+
path: artifacts
245+
- name: Cleanup
246+
run: |
247+
# Remove the granular manifests
248+
rm -f artifacts/*-dist-manifest.json
249+
- name: Create Github Release
250+
uses: ncipollo/release-action@v1
251+
with:
252+
tag: ${{ needs.plan.outputs.tag }}
253+
name: ${{ fromJson(needs.host.outputs.val).announcement_title }}
254+
body: ${{ fromJson(needs.host.outputs.val).announcement_github_body }}
255+
prerelease: ${{ fromJson(needs.host.outputs.val).announcement_is_prerelease }}
256+
artifacts: "artifacts/*"

Cargo.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ edition = "2021"
1717
repository = "https://github.com/dfinity/sdk"
1818
rust-version = "1.75.0"
1919
license = "Apache-2.0"
20+
publish = false
2021

2122
[workspace.dependencies]
2223
candid = "0.10.3"
@@ -71,12 +72,32 @@ tokio = "1.35"
7172
url = "2.1.0"
7273
walkdir = "2.3.2"
7374

75+
# Config for 'cargo dist'
76+
[workspace.metadata.dist]
77+
# The preferred cargo-dist version to use in CI (Cargo.toml SemVer syntax)
78+
cargo-dist-version = "0.5.0"
79+
# CI backends to support
80+
ci = ["github"]
81+
# The installers to generate for each app
82+
installers = []
83+
# Target platforms to build apps for (Rust target-triple syntax)
84+
targets = ["x86_64-pc-windows-msvc"]
85+
# Publish jobs to run in CI
86+
pr-run-mode = "upload"
87+
# don't build ic-frontend-canister or others
88+
precise-builds = true
89+
7490
[profile.release]
7591
panic = 'abort'
7692
lto = true
7793

7894
[profile.dev.package.argon2]
7995
opt-level = 3
8096

97+
# The profile that 'cargo dist' will build with
98+
[profile.dist]
99+
inherits = "release"
100+
lto = "thin"
101+
81102
[profile.release.package.ic-frontend-canister]
82103
opt-level = 'z'

src/canisters/frontend/ic-asset/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "Library for storing files in an asset canister."
1010
documentation = "https://docs.rs/ic-asset"
1111
categories = ["api-bindings", "data-structures"]
1212
keywords = ["internet-computer", "assets", "icp", "dfinity"]
13+
publish = false
1314

1415
[dependencies]
1516
backoff.workspace = true

src/canisters/frontend/ic-certified-assets/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "Rust support for asset certification."
1010
documentation = "https://docs.rs/ic-certified-assets"
1111
categories = ["wasm", "filesystem", "data-structures"]
1212
keywords = ["internet-computer", "dfinity"]
13+
publish = false
1314

1415
[dependencies]
1516
base64.workspace = true

src/canisters/frontend/ic-frontend-canister/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repository = "https://github.com/dfinity/sdk"
88
license = "Apache-2.0"
99
categories = ["wasm"]
1010
keywords = ["internet-computer", "dfinity"]
11+
publish = false
1112

1213
[lib]
1314
path = "src/lib.rs"
@@ -17,3 +18,7 @@ crate-type = ["cdylib"]
1718
ic-certified-assets = { path = "../ic-certified-assets" }
1819
ic-cdk.workspace = true
1920
candid.workspace = true
21+
22+
# Config for 'cargo dist'
23+
[package.metadata.dist]
24+
dist = false

src/canisters/frontend/icx-asset/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ description = "CLI tool to manage assets on an asset canister on the Internet Co
1010
documentation = "https://docs.rs/icx-asset"
1111
categories = ["command-line-interface"]
1212
keywords = ["internet-computer", "agent", "icp", "dfinity", "asset"]
13+
publish = false
1314

1415
[dependencies]
1516
anstyle.workspace = true

src/dfx-core/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition.workspace = true
66
repository.workspace = true
77
license.workspace = true
88
rust-version.workspace = true
9+
publish = false
910

1011
[dependencies]
1112
aes-gcm.workspace = true

src/dfx/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ repository.workspace = true
77
license.workspace = true
88
rust-version.workspace = true
99
build = "assets/build.rs"
10+
publish = false
1011

1112
[[bin]]
1213
name = "dfx"
@@ -125,3 +126,7 @@ env_logger = "0.10"
125126
proptest = "1.0"
126127
mockito = "0.31.0"
127128
tempfile = "3.1.0"
129+
130+
# Config for 'cargo dist'
131+
[package.metadata.dist]
132+
dist = true

0 commit comments

Comments
 (0)