Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

upload-rust-binary-action

releasegithub actions

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

NameRequiredDescriptionTypeDefault
binBinary names (non-extension portion of filename) to build and upload (whitespace or comma separated list)String
tokenGitHub token for uploading assets to GitHub Releases (see action.yml for more)String${{ github.token }}
archiveArchive name (non-extension portion of filename) to be uploadedString$bin-$target
target[1]Target triple, default is host tripleString(host triple)
featuresCargo build features to enable (space or comma separated list)String
no-default-featuresWhether to disable cargo build default featuresBooleanfalse
all-featuresWhether to build with --all-features flagBooleanfalse
packagePackage names to build (whitespace or comma separated list)String
workspaceWhether to build with --workspace flagBooleanfalse
lockedWhether to build with --locked flagBooleanfalse
tarOn which platform to distribute the .tar.gz file (all, unix, windows, or none)Stringunix
tar-xzOn which platform to distribute the .tar.xz file (all, unix, windows, or none)Stringnone
zipOn which platform to distribute the .zip file (all, unix, windows, or none)Stringwindows
checksumAlgorithms to be used for checksum (sha256, sha512, b2, sha1, or md5) (whitespace or comma separated list).
Note: b2 is not available by default on macOS, install b2sum to use it. sha1 and md5 are insecure and strongly discouraged.
String
includeAdditional files to be included to the archive (whitespace or comma separated list)String
assetAdditional files to be uploaded separately (whitespace or comma separated list)String
leading-dirWhether to create the leading directory in the archive or notBooleanfalse
bin-leading-dirCreate extra leading directory(s) for binary file(s) specified by bin optionString
build-toolTool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more)String
refFully-formed tag ref for this release (see action.yml for more)String
manifest-pathPath to Cargo.tomlStringCargo.toml
profileThe cargo profile to build. This defaults to the release profile.Stringrelease
dry-runBuild and compress binaries, but do not upload them (see action.yml for more)Booleanfalse
dry-run-intendedSuppress informational dry-run warnings, keeping the restBooleanfalse
codesignSign build products using codesign on macOSString
codesign-prefixPrefix for the codesign identifier on macOSString
codesign-optionsSpecifies a set of option flags to be embedded in the code signature on macOS. See the codesign manpage for details.String

[1] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.

(Previously, option names were only in "snake_case", but now both "kebab-case" and "snake_case" are available.)

Outputs

NameDescription
archiveArchive base name.
zip.zip archive file name.
tar.tar.gz archive file name.
tar-xz.tar.xz archive file name.
sha256SHA256 checksum file name.
sha512SHA512 checksum file name.
b2BLAKE2 checksum file name.
sha1SHA1 checksum file name.
md5MD5 checksum file name.

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: app1,app2# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: app-$target

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.# This is optional but it is recommended that this always be set to# clarify which target you are building for if macOS is included in# the matrix because GitHub Actions changed the default architecture# of macos-latest since macos-14.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
bin: ...# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: $bin-$tag-$target

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestfeatures: systemd,io_uring
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows# (optional) Build with the given set of features if any.features: ${{ matrix.features || '' }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest# Universal macOS binary is supported as universal-apple-darwin.
- target: universal-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- name: Install cross-compilation toolsuses: taiki-e/setup-cross-toolchain-action@v1with:
target: ${{ matrix.target }}runner: none # Skip installation of cross-testing related tools because we only do cross-compilation.if: startsWith(matrix.os, 'ubuntu')
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build-tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional)changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestbuild-tool: cargo-zigbuild# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17os: ubuntu-latestbuild-tool: cargo-zigbuild
- target: aarch64-apple-darwinos: macos-latestbuild-tool: cargoruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required)bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)build-tool: ${{ matrix.build-tool }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading-dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

You can use the bin-leading-dir option to create extra leading directory(s) for binary file(s) specified by bin option.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true# (optional) Create extra leading directory(s) for binary file(s) specified by `bin` option. default to empty.bin-leading-dir: opt/leading

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be uploaded separately (whitespace or comma separated list).# Note that glob pattern is not supported yet.asset: LICENSE,README.md

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = "symbols"

    Default is strip = debuginfo.

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
    push:
    tags:
    - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
    release:
    types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
ref: refs/tags/my_tag

Security

The @v<major> tags are updated with each release. If you want to enhance workflow stability and security against supply chain attacks, consider using the @v<major>.<minor>.<patch> tag or their hash to pin the version and regularly updating with dependency cooldown. Since all releases are immutable, pinning the version in either way should have the same effect.

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows).

To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash
  • GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Note that what this action installs for its setup (such as above tools) is considered an implementation detail if they are installed by this action's side, and there is no guarantee that they will be available in subsequent steps, because this action is not an action for installing those tools.

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

GitHub Action for building and uploading Rust binary to GitHub Releases.

Topics

Resources

Code of conduct

Security policy

Stars

323 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

upload-rust-binary-action

releasegithub actions

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

NameRequiredDescriptionTypeDefault
binBinary names (non-extension portion of filename) to build and upload (whitespace or comma separated list)String
tokenGitHub token for uploading assets to GitHub Releases (see action.yml for more)String${{ github.token }}
archiveArchive name (non-extension portion of filename) to be uploadedString$bin-$target
target[1]Target triple, default is host tripleString(host triple)
featuresCargo build features to enable (space or comma separated list)String
no-default-featuresWhether to disable cargo build default featuresBooleanfalse
all-featuresWhether to build with --all-features flagBooleanfalse
packagePackage names to build (whitespace or comma separated list)String
workspaceWhether to build with --workspace flagBooleanfalse
lockedWhether to build with --locked flagBooleanfalse
tarOn which platform to distribute the .tar.gz file (all, unix, windows, or none)Stringunix
tar-xzOn which platform to distribute the .tar.xz file (all, unix, windows, or none)Stringnone
zipOn which platform to distribute the .zip file (all, unix, windows, or none)Stringwindows
checksumAlgorithms to be used for checksum (sha256, sha512, b2, sha1, or md5) (whitespace or comma separated list).
Note: b2 is not available by default on macOS, install b2sum to use it. sha1 and md5 are insecure and strongly discouraged.
String
includeAdditional files to be included to the archive (whitespace or comma separated list)String
assetAdditional files to be uploaded separately (whitespace or comma separated list)String
leading-dirWhether to create the leading directory in the archive or notBooleanfalse
bin-leading-dirCreate extra leading directory(s) for binary file(s) specified by bin optionString
build-toolTool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more)String
refFully-formed tag ref for this release (see action.yml for more)String
manifest-pathPath to Cargo.tomlStringCargo.toml
profileThe cargo profile to build. This defaults to the release profile.Stringrelease
dry-runBuild and compress binaries, but do not upload them (see action.yml for more)Booleanfalse
dry-run-intendedSuppress informational dry-run warnings, keeping the restBooleanfalse
codesignSign build products using codesign on macOSString
codesign-prefixPrefix for the codesign identifier on macOSString
codesign-optionsSpecifies a set of option flags to be embedded in the code signature on macOS. See the codesign manpage for details.String

[1] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.

(Previously, option names were only in "snake_case", but now both "kebab-case" and "snake_case" are available.)

Outputs

NameDescription
archiveArchive base name.
zip.zip archive file name.
tar.tar.gz archive file name.
tar-xz.tar.xz archive file name.
sha256SHA256 checksum file name.
sha512SHA512 checksum file name.
b2BLAKE2 checksum file name.
sha1SHA1 checksum file name.
md5MD5 checksum file name.

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: app1,app2# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: app-$target

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.# This is optional but it is recommended that this always be set to# clarify which target you are building for if macOS is included in# the matrix because GitHub Actions changed the default architecture# of macos-latest since macos-14.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
bin: ...# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: $bin-$tag-$target

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestfeatures: systemd,io_uring
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows# (optional) Build with the given set of features if any.features: ${{ matrix.features || '' }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest# Universal macOS binary is supported as universal-apple-darwin.
- target: universal-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- name: Install cross-compilation toolsuses: taiki-e/setup-cross-toolchain-action@v1with:
target: ${{ matrix.target }}runner: none # Skip installation of cross-testing related tools because we only do cross-compilation.if: startsWith(matrix.os, 'ubuntu')
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build-tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional)changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestbuild-tool: cargo-zigbuild# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17os: ubuntu-latestbuild-tool: cargo-zigbuild
- target: aarch64-apple-darwinos: macos-latestbuild-tool: cargoruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required)bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)build-tool: ${{ matrix.build-tool }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading-dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

You can use the bin-leading-dir option to create extra leading directory(s) for binary file(s) specified by bin option.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true# (optional) Create extra leading directory(s) for binary file(s) specified by `bin` option. default to empty.bin-leading-dir: opt/leading

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be uploaded separately (whitespace or comma separated list).# Note that glob pattern is not supported yet.asset: LICENSE,README.md

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = "symbols"

    Default is strip = debuginfo.

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
    push:
    tags:
    - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
    release:
    types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
ref: refs/tags/my_tag

Security

The @v<major> tags are updated with each release. If you want to enhance workflow stability and security against supply chain attacks, consider using the @v<major>.<minor>.<patch> tag or their hash to pin the version and regularly updating with dependency cooldown. Since all releases are immutable, pinning the version in either way should have the same effect.

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows).

To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash
  • GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Note that what this action installs for its setup (such as above tools) is considered an implementation detail if they are installed by this action's side, and there is no guarantee that they will be available in subsequent steps, because this action is not an action for installing those tools.

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

GitHub Action for building and uploading Rust binary to GitHub Releases.

Topics

Resources

Code of conduct

Security policy

Stars

323 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

upload-rust-binary-action

releasegithub actions

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

NameRequiredDescriptionTypeDefault
binBinary names (non-extension portion of filename) to build and upload (whitespace or comma separated list)String
tokenGitHub token for uploading assets to GitHub Releases (see action.yml for more)String${{ github.token }}
archiveArchive name (non-extension portion of filename) to be uploadedString$bin-$target
target[1]Target triple, default is host tripleString(host triple)
featuresCargo build features to enable (space or comma separated list)String
no-default-featuresWhether to disable cargo build default featuresBooleanfalse
all-featuresWhether to build with --all-features flagBooleanfalse
packagePackage names to build (whitespace or comma separated list)String
workspaceWhether to build with --workspace flagBooleanfalse
lockedWhether to build with --locked flagBooleanfalse
tarOn which platform to distribute the .tar.gz file (all, unix, windows, or none)Stringunix
tar-xzOn which platform to distribute the .tar.xz file (all, unix, windows, or none)Stringnone
zipOn which platform to distribute the .zip file (all, unix, windows, or none)Stringwindows
checksumAlgorithms to be used for checksum (sha256, sha512, b2, sha1, or md5) (whitespace or comma separated list).
Note: b2 is not available by default on macOS, install b2sum to use it. sha1 and md5 are insecure and strongly discouraged.
String
includeAdditional files to be included to the archive (whitespace or comma separated list)String
assetAdditional files to be uploaded separately (whitespace or comma separated list)String
leading-dirWhether to create the leading directory in the archive or notBooleanfalse
bin-leading-dirCreate extra leading directory(s) for binary file(s) specified by bin optionString
build-toolTool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more)String
refFully-formed tag ref for this release (see action.yml for more)String
manifest-pathPath to Cargo.tomlStringCargo.toml
profileThe cargo profile to build. This defaults to the release profile.Stringrelease
dry-runBuild and compress binaries, but do not upload them (see action.yml for more)Booleanfalse
dry-run-intendedSuppress informational dry-run warnings, keeping the restBooleanfalse
codesignSign build products using codesign on macOSString
codesign-prefixPrefix for the codesign identifier on macOSString
codesign-optionsSpecifies a set of option flags to be embedded in the code signature on macOS. See the codesign manpage for details.String

[1] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.

(Previously, option names were only in "snake_case", but now both "kebab-case" and "snake_case" are available.)

Outputs

NameDescription
archiveArchive base name.
zip.zip archive file name.
tar.tar.gz archive file name.
tar-xz.tar.xz archive file name.
sha256SHA256 checksum file name.
sha512SHA512 checksum file name.
b2BLAKE2 checksum file name.
sha1SHA1 checksum file name.
md5MD5 checksum file name.

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: app1,app2# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: app-$target

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.# This is optional but it is recommended that this always be set to# clarify which target you are building for if macOS is included in# the matrix because GitHub Actions changed the default architecture# of macos-latest since macos-14.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
bin: ...# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: $bin-$tag-$target

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestfeatures: systemd,io_uring
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows# (optional) Build with the given set of features if any.features: ${{ matrix.features || '' }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest# Universal macOS binary is supported as universal-apple-darwin.
- target: universal-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- name: Install cross-compilation toolsuses: taiki-e/setup-cross-toolchain-action@v1with:
target: ${{ matrix.target }}runner: none # Skip installation of cross-testing related tools because we only do cross-compilation.if: startsWith(matrix.os, 'ubuntu')
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build-tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional)changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestbuild-tool: cargo-zigbuild# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17os: ubuntu-latestbuild-tool: cargo-zigbuild
- target: aarch64-apple-darwinos: macos-latestbuild-tool: cargoruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required)bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)build-tool: ${{ matrix.build-tool }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading-dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

You can use the bin-leading-dir option to create extra leading directory(s) for binary file(s) specified by bin option.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true# (optional) Create extra leading directory(s) for binary file(s) specified by `bin` option. default to empty.bin-leading-dir: opt/leading

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be uploaded separately (whitespace or comma separated list).# Note that glob pattern is not supported yet.asset: LICENSE,README.md

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = "symbols"

    Default is strip = debuginfo.

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
    push:
    tags:
    - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
    release:
    types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
ref: refs/tags/my_tag

Security

The @v<major> tags are updated with each release. If you want to enhance workflow stability and security against supply chain attacks, consider using the @v<major>.<minor>.<patch> tag or their hash to pin the version and regularly updating with dependency cooldown. Since all releases are immutable, pinning the version in either way should have the same effect.

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows).

To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash
  • GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Note that what this action installs for its setup (such as above tools) is considered an implementation detail if they are installed by this action's side, and there is no guarantee that they will be available in subsequent steps, because this action is not an action for installing those tools.

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

GitHub Action for building and uploading Rust binary to GitHub Releases.

Topics

Resources

Code of conduct

Security policy

Stars

323 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

upload-rust-binary-action

releasegithub actions

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

NameRequiredDescriptionTypeDefault
binBinary names (non-extension portion of filename) to build and upload (whitespace or comma separated list)String
tokenGitHub token for uploading assets to GitHub Releases (see action.yml for more)String${{ github.token }}
archiveArchive name (non-extension portion of filename) to be uploadedString$bin-$target
target[1]Target triple, default is host tripleString(host triple)
featuresCargo build features to enable (space or comma separated list)String
no-default-featuresWhether to disable cargo build default featuresBooleanfalse
all-featuresWhether to build with --all-features flagBooleanfalse
packagePackage names to build (whitespace or comma separated list)String
workspaceWhether to build with --workspace flagBooleanfalse
lockedWhether to build with --locked flagBooleanfalse
tarOn which platform to distribute the .tar.gz file (all, unix, windows, or none)Stringunix
tar-xzOn which platform to distribute the .tar.xz file (all, unix, windows, or none)Stringnone
zipOn which platform to distribute the .zip file (all, unix, windows, or none)Stringwindows
checksumAlgorithms to be used for checksum (sha256, sha512, b2, sha1, or md5) (whitespace or comma separated list).
Note: b2 is not available by default on macOS, install b2sum to use it. sha1 and md5 are insecure and strongly discouraged.
String
includeAdditional files to be included to the archive (whitespace or comma separated list)String
assetAdditional files to be uploaded separately (whitespace or comma separated list)String
leading-dirWhether to create the leading directory in the archive or notBooleanfalse
bin-leading-dirCreate extra leading directory(s) for binary file(s) specified by bin optionString
build-toolTool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more)String
refFully-formed tag ref for this release (see action.yml for more)String
manifest-pathPath to Cargo.tomlStringCargo.toml
profileThe cargo profile to build. This defaults to the release profile.Stringrelease
dry-runBuild and compress binaries, but do not upload them (see action.yml for more)Booleanfalse
dry-run-intendedSuppress informational dry-run warnings, keeping the restBooleanfalse
codesignSign build products using codesign on macOSString
codesign-prefixPrefix for the codesign identifier on macOSString
codesign-optionsSpecifies a set of option flags to be embedded in the code signature on macOS. See the codesign manpage for details.String

[1] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.

(Previously, option names were only in "snake_case", but now both "kebab-case" and "snake_case" are available.)

Outputs

NameDescription
archiveArchive base name.
zip.zip archive file name.
tar.tar.gz archive file name.
tar-xz.tar.xz archive file name.
sha256SHA256 checksum file name.
sha512SHA512 checksum file name.
b2BLAKE2 checksum file name.
sha1SHA1 checksum file name.
md5MD5 checksum file name.

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: app1,app2# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: app-$target

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.# This is optional but it is recommended that this always be set to# clarify which target you are building for if macOS is included in# the matrix because GitHub Actions changed the default architecture# of macos-latest since macos-14.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
bin: ...# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: $bin-$tag-$target

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestfeatures: systemd,io_uring
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows# (optional) Build with the given set of features if any.features: ${{ matrix.features || '' }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest# Universal macOS binary is supported as universal-apple-darwin.
- target: universal-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- name: Install cross-compilation toolsuses: taiki-e/setup-cross-toolchain-action@v1with:
target: ${{ matrix.target }}runner: none # Skip installation of cross-testing related tools because we only do cross-compilation.if: startsWith(matrix.os, 'ubuntu')
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build-tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional)changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestbuild-tool: cargo-zigbuild# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17os: ubuntu-latestbuild-tool: cargo-zigbuild
- target: aarch64-apple-darwinos: macos-latestbuild-tool: cargoruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required)bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)build-tool: ${{ matrix.build-tool }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading-dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

You can use the bin-leading-dir option to create extra leading directory(s) for binary file(s) specified by bin option.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true# (optional) Create extra leading directory(s) for binary file(s) specified by `bin` option. default to empty.bin-leading-dir: opt/leading

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be uploaded separately (whitespace or comma separated list).# Note that glob pattern is not supported yet.asset: LICENSE,README.md

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = "symbols"

    Default is strip = debuginfo.

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
    push:
    tags:
    - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
    release:
    types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
ref: refs/tags/my_tag

Security

The @v<major> tags are updated with each release. If you want to enhance workflow stability and security against supply chain attacks, consider using the @v<major>.<minor>.<patch> tag or their hash to pin the version and regularly updating with dependency cooldown. Since all releases are immutable, pinning the version in either way should have the same effect.

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows).

To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash
  • GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Note that what this action installs for its setup (such as above tools) is considered an implementation detail if they are installed by this action's side, and there is no guarantee that they will be available in subsequent steps, because this action is not an action for installing those tools.

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

GitHub Action for building and uploading Rust binary to GitHub Releases.

Topics

Resources

Code of conduct

Security policy

Stars

323 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

upload-rust-binary-action

releasegithub actions

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

NameRequiredDescriptionTypeDefault
binBinary names (non-extension portion of filename) to build and upload (whitespace or comma separated list)String
tokenGitHub token for uploading assets to GitHub Releases (see action.yml for more)String${{ github.token }}
archiveArchive name (non-extension portion of filename) to be uploadedString$bin-$target
target[1]Target triple, default is host tripleString(host triple)
featuresCargo build features to enable (space or comma separated list)String
no-default-featuresWhether to disable cargo build default featuresBooleanfalse
all-featuresWhether to build with --all-features flagBooleanfalse
packagePackage names to build (whitespace or comma separated list)String
workspaceWhether to build with --workspace flagBooleanfalse
lockedWhether to build with --locked flagBooleanfalse
tarOn which platform to distribute the .tar.gz file (all, unix, windows, or none)Stringunix
tar-xzOn which platform to distribute the .tar.xz file (all, unix, windows, or none)Stringnone
zipOn which platform to distribute the .zip file (all, unix, windows, or none)Stringwindows
checksumAlgorithms to be used for checksum (sha256, sha512, b2, sha1, or md5) (whitespace or comma separated list).
Note: b2 is not available by default on macOS, install b2sum to use it. sha1 and md5 are insecure and strongly discouraged.
String
includeAdditional files to be included to the archive (whitespace or comma separated list)String
assetAdditional files to be uploaded separately (whitespace or comma separated list)String
leading-dirWhether to create the leading directory in the archive or notBooleanfalse
bin-leading-dirCreate extra leading directory(s) for binary file(s) specified by bin optionString
build-toolTool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more)String
refFully-formed tag ref for this release (see action.yml for more)String
manifest-pathPath to Cargo.tomlStringCargo.toml
profileThe cargo profile to build. This defaults to the release profile.Stringrelease
dry-runBuild and compress binaries, but do not upload them (see action.yml for more)Booleanfalse
dry-run-intendedSuppress informational dry-run warnings, keeping the restBooleanfalse
codesignSign build products using codesign on macOSString
codesign-prefixPrefix for the codesign identifier on macOSString
codesign-optionsSpecifies a set of option flags to be embedded in the code signature on macOS. See the codesign manpage for details.String

[1] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.

(Previously, option names were only in "snake_case", but now both "kebab-case" and "snake_case" are available.)

Outputs

NameDescription
archiveArchive base name.
zip.zip archive file name.
tar.tar.gz archive file name.
tar-xz.tar.xz archive file name.
sha256SHA256 checksum file name.
sha512SHA512 checksum file name.
b2BLAKE2 checksum file name.
sha1SHA1 checksum file name.
md5MD5 checksum file name.

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: app1,app2# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: app-$target

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.# This is optional but it is recommended that this always be set to# clarify which target you are building for if macOS is included in# the matrix because GitHub Actions changed the default architecture# of macos-latest since macos-14.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
bin: ...# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: $bin-$tag-$target

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestfeatures: systemd,io_uring
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows# (optional) Build with the given set of features if any.features: ${{ matrix.features || '' }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest# Universal macOS binary is supported as universal-apple-darwin.
- target: universal-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- name: Install cross-compilation toolsuses: taiki-e/setup-cross-toolchain-action@v1with:
target: ${{ matrix.target }}runner: none # Skip installation of cross-testing related tools because we only do cross-compilation.if: startsWith(matrix.os, 'ubuntu')
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build-tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional)changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestbuild-tool: cargo-zigbuild# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17os: ubuntu-latestbuild-tool: cargo-zigbuild
- target: aarch64-apple-darwinos: macos-latestbuild-tool: cargoruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required)bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)build-tool: ${{ matrix.build-tool }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading-dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

You can use the bin-leading-dir option to create extra leading directory(s) for binary file(s) specified by bin option.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true# (optional) Create extra leading directory(s) for binary file(s) specified by `bin` option. default to empty.bin-leading-dir: opt/leading

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be uploaded separately (whitespace or comma separated list).# Note that glob pattern is not supported yet.asset: LICENSE,README.md

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = "symbols"

    Default is strip = debuginfo.

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
    push:
    tags:
    - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
    release:
    types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
ref: refs/tags/my_tag

Security

The @v<major> tags are updated with each release. If you want to enhance workflow stability and security against supply chain attacks, consider using the @v<major>.<minor>.<patch> tag or their hash to pin the version and regularly updating with dependency cooldown. Since all releases are immutable, pinning the version in either way should have the same effect.

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows).

To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash
  • GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Note that what this action installs for its setup (such as above tools) is considered an implementation detail if they are installed by this action's side, and there is no guarantee that they will be available in subsequent steps, because this action is not an action for installing those tools.

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

GitHub Action for building and uploading Rust binary to GitHub Releases.

Topics

Resources

Code of conduct

Security policy

Stars

323 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

upload-rust-binary-action

releasegithub actions

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

NameRequiredDescriptionTypeDefault
binBinary names (non-extension portion of filename) to build and upload (whitespace or comma separated list)String
tokenGitHub token for uploading assets to GitHub Releases (see action.yml for more)String${{ github.token }}
archiveArchive name (non-extension portion of filename) to be uploadedString$bin-$target
target[1]Target triple, default is host tripleString(host triple)
featuresCargo build features to enable (space or comma separated list)String
no-default-featuresWhether to disable cargo build default featuresBooleanfalse
all-featuresWhether to build with --all-features flagBooleanfalse
packagePackage names to build (whitespace or comma separated list)String
workspaceWhether to build with --workspace flagBooleanfalse
lockedWhether to build with --locked flagBooleanfalse
tarOn which platform to distribute the .tar.gz file (all, unix, windows, or none)Stringunix
tar-xzOn which platform to distribute the .tar.xz file (all, unix, windows, or none)Stringnone
zipOn which platform to distribute the .zip file (all, unix, windows, or none)Stringwindows
checksumAlgorithms to be used for checksum (sha256, sha512, b2, sha1, or md5) (whitespace or comma separated list).
Note: b2 is not available by default on macOS, install b2sum to use it. sha1 and md5 are insecure and strongly discouraged.
String
includeAdditional files to be included to the archive (whitespace or comma separated list)String
assetAdditional files to be uploaded separately (whitespace or comma separated list)String
leading-dirWhether to create the leading directory in the archive or notBooleanfalse
bin-leading-dirCreate extra leading directory(s) for binary file(s) specified by bin optionString
build-toolTool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more)String
refFully-formed tag ref for this release (see action.yml for more)String
manifest-pathPath to Cargo.tomlStringCargo.toml
profileThe cargo profile to build. This defaults to the release profile.Stringrelease
dry-runBuild and compress binaries, but do not upload them (see action.yml for more)Booleanfalse
dry-run-intendedSuppress informational dry-run warnings, keeping the restBooleanfalse
codesignSign build products using codesign on macOSString
codesign-prefixPrefix for the codesign identifier on macOSString
codesign-optionsSpecifies a set of option flags to be embedded in the code signature on macOS. See the codesign manpage for details.String

[1] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.

(Previously, option names were only in "snake_case", but now both "kebab-case" and "snake_case" are available.)

Outputs

NameDescription
archiveArchive base name.
zip.zip archive file name.
tar.tar.gz archive file name.
tar-xz.tar.xz archive file name.
sha256SHA256 checksum file name.
sha512SHA512 checksum file name.
b2BLAKE2 checksum file name.
sha1SHA1 checksum file name.
md5MD5 checksum file name.

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: app1,app2# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: app-$target

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.# This is optional but it is recommended that this always be set to# clarify which target you are building for if macOS is included in# the matrix because GitHub Actions changed the default architecture# of macos-latest since macos-14.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
bin: ...# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: $bin-$tag-$target

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestfeatures: systemd,io_uring
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows# (optional) Build with the given set of features if any.features: ${{ matrix.features || '' }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest# Universal macOS binary is supported as universal-apple-darwin.
- target: universal-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- name: Install cross-compilation toolsuses: taiki-e/setup-cross-toolchain-action@v1with:
target: ${{ matrix.target }}runner: none # Skip installation of cross-testing related tools because we only do cross-compilation.if: startsWith(matrix.os, 'ubuntu')
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build-tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional)changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestbuild-tool: cargo-zigbuild# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17os: ubuntu-latestbuild-tool: cargo-zigbuild
- target: aarch64-apple-darwinos: macos-latestbuild-tool: cargoruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required)bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)build-tool: ${{ matrix.build-tool }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading-dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

You can use the bin-leading-dir option to create extra leading directory(s) for binary file(s) specified by bin option.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true# (optional) Create extra leading directory(s) for binary file(s) specified by `bin` option. default to empty.bin-leading-dir: opt/leading

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be uploaded separately (whitespace or comma separated list).# Note that glob pattern is not supported yet.asset: LICENSE,README.md

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = "symbols"

    Default is strip = debuginfo.

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
    push:
    tags:
    - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
    release:
    types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
ref: refs/tags/my_tag

Security

The @v<major> tags are updated with each release. If you want to enhance workflow stability and security against supply chain attacks, consider using the @v<major>.<minor>.<patch> tag or their hash to pin the version and regularly updating with dependency cooldown. Since all releases are immutable, pinning the version in either way should have the same effect.

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows).

To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash
  • GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Note that what this action installs for its setup (such as above tools) is considered an implementation detail if they are installed by this action's side, and there is no guarantee that they will be available in subsequent steps, because this action is not an action for installing those tools.

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

GitHub Action for building and uploading Rust binary to GitHub Releases.

Topics

Resources

Code of conduct

Security policy

Stars

323 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

upload-rust-binary-action

releasegithub actions

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

NameRequiredDescriptionTypeDefault
binBinary names (non-extension portion of filename) to build and upload (whitespace or comma separated list)String
tokenGitHub token for uploading assets to GitHub Releases (see action.yml for more)String${{ github.token }}
archiveArchive name (non-extension portion of filename) to be uploadedString$bin-$target
target[1]Target triple, default is host tripleString(host triple)
featuresCargo build features to enable (space or comma separated list)String
no-default-featuresWhether to disable cargo build default featuresBooleanfalse
all-featuresWhether to build with --all-features flagBooleanfalse
packagePackage names to build (whitespace or comma separated list)String
workspaceWhether to build with --workspace flagBooleanfalse
lockedWhether to build with --locked flagBooleanfalse
tarOn which platform to distribute the .tar.gz file (all, unix, windows, or none)Stringunix
tar-xzOn which platform to distribute the .tar.xz file (all, unix, windows, or none)Stringnone
zipOn which platform to distribute the .zip file (all, unix, windows, or none)Stringwindows
checksumAlgorithms to be used for checksum (sha256, sha512, b2, sha1, or md5) (whitespace or comma separated list).
Note: b2 is not available by default on macOS, install b2sum to use it. sha1 and md5 are insecure and strongly discouraged.
String
includeAdditional files to be included to the archive (whitespace or comma separated list)String
assetAdditional files to be uploaded separately (whitespace or comma separated list)String
leading-dirWhether to create the leading directory in the archive or notBooleanfalse
bin-leading-dirCreate extra leading directory(s) for binary file(s) specified by bin optionString
build-toolTool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more)String
refFully-formed tag ref for this release (see action.yml for more)String
manifest-pathPath to Cargo.tomlStringCargo.toml
profileThe cargo profile to build. This defaults to the release profile.Stringrelease
dry-runBuild and compress binaries, but do not upload them (see action.yml for more)Booleanfalse
dry-run-intendedSuppress informational dry-run warnings, keeping the restBooleanfalse
codesignSign build products using codesign on macOSString
codesign-prefixPrefix for the codesign identifier on macOSString
codesign-optionsSpecifies a set of option flags to be embedded in the code signature on macOS. See the codesign manpage for details.String

[1] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.

(Previously, option names were only in "snake_case", but now both "kebab-case" and "snake_case" are available.)

Outputs

NameDescription
archiveArchive base name.
zip.zip archive file name.
tar.tar.gz archive file name.
tar-xz.tar.xz archive file name.
sha256SHA256 checksum file name.
sha512SHA512 checksum file name.
b2BLAKE2 checksum file name.
sha1SHA1 checksum file name.
md5MD5 checksum file name.

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: app1,app2# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: app-$target

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.# This is optional but it is recommended that this always be set to# clarify which target you are building for if macOS is included in# the matrix because GitHub Actions changed the default architecture# of macos-latest since macos-14.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
bin: ...# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: $bin-$tag-$target

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestfeatures: systemd,io_uring
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows# (optional) Build with the given set of features if any.features: ${{ matrix.features || '' }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest# Universal macOS binary is supported as universal-apple-darwin.
- target: universal-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- name: Install cross-compilation toolsuses: taiki-e/setup-cross-toolchain-action@v1with:
target: ${{ matrix.target }}runner: none # Skip installation of cross-testing related tools because we only do cross-compilation.if: startsWith(matrix.os, 'ubuntu')
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build-tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional)changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestbuild-tool: cargo-zigbuild# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17os: ubuntu-latestbuild-tool: cargo-zigbuild
- target: aarch64-apple-darwinos: macos-latestbuild-tool: cargoruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required)bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)build-tool: ${{ matrix.build-tool }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading-dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

You can use the bin-leading-dir option to create extra leading directory(s) for binary file(s) specified by bin option.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true# (optional) Create extra leading directory(s) for binary file(s) specified by `bin` option. default to empty.bin-leading-dir: opt/leading

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be uploaded separately (whitespace or comma separated list).# Note that glob pattern is not supported yet.asset: LICENSE,README.md

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = "symbols"

    Default is strip = debuginfo.

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
    push:
    tags:
    - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
    release:
    types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
ref: refs/tags/my_tag

Security

The @v<major> tags are updated with each release. If you want to enhance workflow stability and security against supply chain attacks, consider using the @v<major>.<minor>.<patch> tag or their hash to pin the version and regularly updating with dependency cooldown. Since all releases are immutable, pinning the version in either way should have the same effect.

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows).

To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash
  • GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Note that what this action installs for its setup (such as above tools) is considered an implementation detail if they are installed by this action's side, and there is no guarantee that they will be available in subsequent steps, because this action is not an action for installing those tools.

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

GitHub Action for building and uploading Rust binary to GitHub Releases.

Topics

Resources

Code of conduct

Security policy

Stars

323 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

upload-rust-binary-action

releasegithub actions

GitHub Action for building and uploading Rust binary to GitHub Releases.

Usage

This action builds and uploads Rust binary that specified by bin option to GitHub Releases.

Currently, this action is basically intended to be used in combination with an action like create-gh-release-action that creates a GitHub release when a tag is pushed. See also supported events.

Inputs

NameRequiredDescriptionTypeDefault
binBinary names (non-extension portion of filename) to build and upload (whitespace or comma separated list)String
tokenGitHub token for uploading assets to GitHub Releases (see action.yml for more)String${{ github.token }}
archiveArchive name (non-extension portion of filename) to be uploadedString$bin-$target
target[1]Target triple, default is host tripleString(host triple)
featuresCargo build features to enable (space or comma separated list)String
no-default-featuresWhether to disable cargo build default featuresBooleanfalse
all-featuresWhether to build with --all-features flagBooleanfalse
packagePackage names to build (whitespace or comma separated list)String
workspaceWhether to build with --workspace flagBooleanfalse
lockedWhether to build with --locked flagBooleanfalse
tarOn which platform to distribute the .tar.gz file (all, unix, windows, or none)Stringunix
tar-xzOn which platform to distribute the .tar.xz file (all, unix, windows, or none)Stringnone
zipOn which platform to distribute the .zip file (all, unix, windows, or none)Stringwindows
checksumAlgorithms to be used for checksum (sha256, sha512, b2, sha1, or md5) (whitespace or comma separated list).
Note: b2 is not available by default on macOS, install b2sum to use it. sha1 and md5 are insecure and strongly discouraged.
String
includeAdditional files to be included to the archive (whitespace or comma separated list)String
assetAdditional files to be uploaded separately (whitespace or comma separated list)String
leading-dirWhether to create the leading directory in the archive or notBooleanfalse
bin-leading-dirCreate extra leading directory(s) for binary file(s) specified by bin optionString
build-toolTool to build binaries (cargo, cross, or cargo-zigbuild, see cross-compilation example for more)String
refFully-formed tag ref for this release (see action.yml for more)String
manifest-pathPath to Cargo.tomlStringCargo.toml
profileThe cargo profile to build. This defaults to the release profile.Stringrelease
dry-runBuild and compress binaries, but do not upload them (see action.yml for more)Booleanfalse
dry-run-intendedSuppress informational dry-run warnings, keeping the restBooleanfalse
codesignSign build products using codesign on macOSString
codesign-prefixPrefix for the codesign identifier on macOSString
codesign-optionsSpecifies a set of option flags to be embedded in the code signature on macOS. See the codesign manpage for details.String

[1] This is optional but it is recommended that this always be set to clarify which target you are building for if macOS is included in the matrix because GitHub Actions changed the default architecture of macos-latest since macos-14.

(Previously, option names were only in "snake_case", but now both "kebab-case" and "snake_case" are available.)

Outputs

NameDescription
archiveArchive base name.
zip.zip archive file name.
tar.tar.gz archive file name.
tar-xz.tar.xz archive file name.
sha256SHA256 checksum file name.
sha512SHA512 checksum file name.
b2BLAKE2 checksum file name.
sha1SHA1 checksum file name.
md5MD5 checksum file name.

Example workflow: Basic usage

In this example, when a new tag is pushed, creating a new GitHub Release by using create-gh-release-action, then uploading Rust binary to the created GitHub Release.

An archive file with a name like $bin-$target.tar.gz will be uploaded to GitHub Release.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...

You can specify multiple binaries when the root manifest is a virtual manifest or specified binaries are in the same crate.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: app1,app2# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: app-$target

Example workflow: Basic usage (multiple platforms)

This action supports Linux, macOS, and Windows as a host OS and supports binaries for various targets.

See also cross-compilation example.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.# This is optional but it is recommended that this always be set to# clarify which target you are building for if macOS is included in# the matrix because GitHub Actions changed the default architecture# of macos-latest since macos-14.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows

Example workflow: Customize archive name

By default, this action will upload an archive file with a name like $bin-$target.$extension.

You can customize archive name by archive option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
bin: ...# (optional) Archive name (non-extension portion of filename) to be uploaded.# [default value: $bin-$target]# [possible values: the following variables and any string]# variables:# - $bin - Binary name (non-extension portion of filename).# - $target - Target triple.# - $tag - Tag of this release.# When multiple binary names are specified, default archive name or $bin variable cannot be used.archive: $bin-$tag-$target

Example workflow: Build with different features on different platforms

This action enables the systemd and io_uring features for Linux, and leave macOS, and Windows with default set of features.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestfeatures: systemd,io_uring
- target: x86_64-apple-darwinos: macos-latest
- target: x86_64-pc-windows-msvcos: windows-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) On which platform to distribute the `.tar.gz` file.# [default value: unix]# [possible values: all, unix, windows, none]tar: unix# (optional) On which platform to distribute the `.zip` file.# [default value: windows]# [possible values: all, unix, windows, none]zip: windows# (optional) Build with the given set of features if any.features: ${{ matrix.features || '' }}

Example workflow: Cross-compilation

cross

By default, this action uses cross for cross-compilation (if cross supports that target). In the following example, only aarch64-unknown-linux-gnu uses cross, the rest use cargo.

If cross is not installed, this action calls cargo install cross --locked to install cross. If you want to speed up the installation of cross or use an older version of cross, consider using install-action.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latest# Universal macOS binary is supported as universal-apple-darwin.
- target: universal-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

setup-cross-toolchain-action

However, if the host has another cross-compilation setup, it will be respected. The following is an example using setup-cross-toolchain-action. In this example, this action uses cargo for all targets.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: aarch64-unknown-linux-gnuos: ubuntu-latest
- target: aarch64-apple-darwinos: macos-latest
- target: x86_64-unknown-linux-gnuos: ubuntu-latest
- target: x86_64-apple-darwinos: macos-latestruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- name: Install cross-compilation toolsuses: taiki-e/setup-cross-toolchain-action@v1with:
target: ${{ matrix.target }}runner: none # Skip installation of cross-testing related tools because we only do cross-compilation.if: startsWith(matrix.os, 'ubuntu')
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}

cargo-zigbuild

if you want to use cargo-zigbuild, if the heuristic to detect host cross-compilation setups does not work well, or if you want to force the use of cargo or cross, you can use the build-tool input option.

If cargo-zigbuild is not installed, this action calls pip3 install cargo-zigbuild to install cargo-zigbuild.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional)changelog: CHANGELOG.mdupload-assets:
needs: create-releasestrategy:
matrix:
include:
- target: x86_64-unknown-linux-gnuos: ubuntu-latestbuild-tool: cargo-zigbuild# cargo-zigbuild's glibc version suffix is also supported.
- target: aarch64-unknown-linux-gnu.2.17os: ubuntu-latestbuild-tool: cargo-zigbuild
- target: aarch64-apple-darwinos: macos-latestbuild-tool: cargoruns-on: ${{ matrix.os }}permissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required)bin: ...# (optional) Target triple, default is host triple.target: ${{ matrix.target }}# (optional) Tool to build binaries (cargo, cross, or cargo-zigbuild)build-tool: ${{ matrix.build-tool }}

Example workflow: Include additional files

If you want include additional file to the archive, you can use the include option.

name: Releasepermissions:
contents: readon:
push:
tags:
- v[0-9]+.*jobs:
create-release:
runs-on: ubuntu-latestpermissions:
contents: write # for taiki-e/create-gh-release-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/create-gh-release-action@v1with:
# (optional) Path to changelog.changelog: CHANGELOG.mdupload-assets:
needs: create-releaseruns-on: ubuntu-latestpermissions:
contents: write # for taiki-e/upload-rust-binary-actionsteps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md

By default, the expanded archive does not include the leading directory. In the above example, the directory structure of the archive would be as follows:

/<bin>
/LICENSE
/README.md

You can use the leading-dir option to create the leading directory.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/<bin>
/<archive>/LICENSE
/<archive>/README.md

You can use the bin-leading-dir option to create extra leading directory(s) for binary file(s) specified by bin option.

- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be included to the archive (whitespace or comma separated list).# Note that glob pattern is not supported yet.include: LICENSE,README.md# (optional) Whether to create the leading directory in the archive or not. default to false.leading-dir: true# (optional) Create extra leading directory(s) for binary file(s) specified by `bin` option. default to empty.bin-leading-dir: opt/leading

In the above example, the directory structure of the archive would be as follows:

/<archive>/
/<archive>/opt/leading/<bin>
/<archive>/LICENSE
/<archive>/README.md

If you want upload additional file separately, you can use the asset option.

upload-assets:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v6
- uses: taiki-e/upload-rust-binary-action@v1with:
# (required) Binary names (non-extension portion of filename) to build and upload (whitespace or comma separated list).# Note that glob pattern is not supported yet.bin: ...# (optional) Additional files to be uploaded separately (whitespace or comma separated list).# Note that glob pattern is not supported yet.asset: LICENSE,README.md

In the above example, the following 3 files will be uploaded:

<bin>-<target>.tar.gz
LICENSE
README.md

Other examples

Optimize Rust binary

You can optimize performance or size of Rust binaries by passing the profile options. The profile options can be specified by [profile] table in Cargo.toml, cargo config, environment variables, etc.

The followings are examples to specify profile options:

  • lto

    With profile:

    [profile.release]
    lto = true

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_LTO: true
  • codegen-units

    With profile:

    [profile.release]
    codegen-units = 1

    With environment variable:

    env:
    CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
  • strip

    With profile:

    [profile.release]
    strip = "symbols"

    Default is strip = debuginfo.

Note: Some of these options may increase the build time.

Supported events

The following two events are supported by default:

  • tags (on.push.tags)

    For example:

    on:
    push:
    tags:
    - v[0-9]+.*
  • GitHub release (on.release)

    For example:

    on:
    release:
    types: [created]

You can upload binaries from arbitrary event to arbitrary tag by specifying the ref input option.

For example, to upload binaries to the my_tag tag, specify ref input option as follows:

with:
ref: refs/tags/my_tag

Security

The @v<major> tags are updated with each release. If you want to enhance workflow stability and security against supply chain attacks, consider using the @v<major>.<minor>.<patch> tag or their hash to pin the version and regularly updating with dependency cooldown. Since all releases are immutable, pinning the version in either way should have the same effect.

Compatibility

This action has been tested for GitHub-hosted runners (Ubuntu, macOS, Windows).

To use this action in self-hosted runners or in containers, at least the following tools are required:

  • rustup, cargo, rustc
  • bash
  • GNU tar
  • gh (GitHub CLI)
  • zip (only Unix-like)
  • 7z (only Windows)

Note that what this action installs for its setup (such as above tools) is considered an implementation detail if they are installed by this action's side, and there is no guarantee that they will be available in subsequent steps, because this action is not an action for installing those tools.

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

GitHub Action for building and uploading Rust binary to GitHub Releases.

Topics

Resources

Code of conduct

Security policy

Stars

323 stars

Watchers

2 watching

Forks

Releases

Sponsor this project

Used by

Contributors

Languages