For test commands, there can be arguments passed to the test binary like `-- --ignored` or `-- --test-threads=1`. For these cases to work properly, the `args` parameter needs to be added to the end of the 'test' command.
128 lines
5.4 KiB
YAML
128 lines
5.4 KiB
YAML
name: "Build Rust Projects with Cross"
|
|
author: "Dave Rolsky <autarch@urth.org>"
|
|
branding:
|
|
icon: home
|
|
color: gray-dark
|
|
description: |
|
|
Cross compile your Rust projects with cross (https://github.com/cross-rs/cross).
|
|
inputs:
|
|
working-directory:
|
|
description: The working directory for each step
|
|
default: "."
|
|
command:
|
|
description: |
|
|
The commands to run (one of "build", "test", or "both").
|
|
default: build
|
|
target:
|
|
description: The target platform
|
|
required: true
|
|
toolchain:
|
|
description: |
|
|
The target toolchain to use (one of "stable", "beta", or "nightly").
|
|
default: stable
|
|
GITHUB_TOKEN:
|
|
description: |
|
|
A GitHub token, available in the secrets.GITHUB_TOKEN working-directory variable.
|
|
default: ${{ github.token }}
|
|
args:
|
|
description: |
|
|
The arguments to be passed to cross or cargo when building, as a
|
|
space-separated string.
|
|
default: ""
|
|
strip:
|
|
description: Strip the compiled binary
|
|
default: false
|
|
cross-version:
|
|
description: |
|
|
The version of cross to use. If not specified, then the latest version
|
|
will be used.
|
|
cache-cross-binary:
|
|
description: |
|
|
Cache the cross binary if one is installed. This is primarily for use in
|
|
tests of this action.
|
|
default: true
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Add this action's path to PATH
|
|
shell: bash
|
|
run: echo "${{ github.action_path }}" >> $GITHUB_PATH
|
|
- name: Determine whether we need to cross-compile
|
|
id: determine-cross-compile
|
|
shell: bash
|
|
run: set-cross-compile.sh ${{ inputs.target }}
|
|
- name: Install toolchain
|
|
uses: dtolnay/rust-toolchain@master
|
|
with:
|
|
targets: ${{ inputs.target }}
|
|
toolchain: ${{ inputs.toolchain }}
|
|
- name: Determine cross version
|
|
id: determine-cross-version
|
|
shell: bash
|
|
run: determine-cross-version.sh "${{ inputs.cross-version }}"
|
|
env:
|
|
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
|
|
if: steps.determine-cross-compile.outputs.needs-cross == 'true'
|
|
# We need to access this in both this YAML config and shell scripts. It
|
|
# doesn't seem like using ${{ env.RUNNER_TEMP }} works in the YAML config.
|
|
- name: Set directory for installing cross
|
|
id: set-cross-dir
|
|
shell: bash
|
|
run: set-cross-dir.sh
|
|
if: steps.determine-cross-compile.outputs.needs-cross == 'true'
|
|
- name: Cache cross
|
|
id: cache-cross
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ steps.set-cross-dir.outputs.cross-dir }}/cross
|
|
key: ${{ runner.os }}-${{ steps.determine-cross-version.outputs.cross-version }}
|
|
if: steps.determine-cross-compile.outputs.needs-cross == 'true' && inputs.cache-cross-binary == 'true'
|
|
- name: Install cross if cross-compiling (*nix)
|
|
shell: bash
|
|
run: install-cross-nix.sh ${{ steps.set-cross-dir.outputs.cross-dir }} ${{ steps.determine-cross-version.outputs.cross-version }}
|
|
if: steps.determine-cross-compile.outputs.needs-cross == 'true' && steps.cache-cross.outputs.cache-hit != 'true'
|
|
env:
|
|
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
|
|
- name: Install musl-tools on Linux if target includes "musl"
|
|
shell: bash
|
|
run: sudo apt-get update --yes && sudo apt-get install --yes musl-tools
|
|
if: steps.determine-cross-compile.outputs.needs-cross != 'true' && contains(inputs.target, 'musl')
|
|
- name: Set build command
|
|
id: set-build-command
|
|
shell: bash
|
|
run: set-build-command.sh ${{ steps.set-cross-dir.outputs.cross-dir }}
|
|
- name: Run tests (*nix)
|
|
working-directory: ${{ inputs.working-directory }}
|
|
shell: bash
|
|
run: |
|
|
${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} test --target ${{ inputs.target }} ${{ inputs.args }}
|
|
if: inputs.command != 'build' && runner.os != 'Windows'
|
|
# We want to run in Powershell on Windows to make sure we compile in a
|
|
# native Windows environment. Some things won't compile properly under
|
|
# msys, notably OpenSSL, which is compiled locally when using the
|
|
# `openssl` crate with the `vendored` feature.
|
|
- name: Run tests (Windows)
|
|
working-directory: ${{ inputs.working-directory }}
|
|
shell: powershell
|
|
run: |
|
|
& ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} test --target ${{ inputs.target }} ${{ inputs.args }}
|
|
if: inputs.command != 'build' && runner.os == 'Windows'
|
|
- name: Build binary (*nix)
|
|
working-directory: ${{ inputs.working-directory }}
|
|
shell: bash
|
|
run: |
|
|
${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} build ${{ inputs.args }} --target ${{ inputs.target }}
|
|
if: inputs.command != 'test' && runner.os != 'Windows'
|
|
- name: Build binary (Windows)
|
|
working-directory: ${{ inputs.working-directory }}
|
|
shell: powershell
|
|
run: |
|
|
& ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} build ${{ inputs.args }} --target ${{ inputs.target }}
|
|
if: inputs.command != 'test' && runner.os == 'Windows'
|
|
- name: Strip binary
|
|
working-directory: ${{ inputs.working-directory }}
|
|
shell: bash
|
|
run: strip-binary.sh ${{ inputs.target }}
|
|
# strip doesn't work with cross-arch binaries on Linux or Windows.
|
|
if: inputs.command != 'test' && inputs.strip == 'true' && steps.determine-cross-compile.outputs.needs-cross == 'false' && inputs.target != 'aarch64-pc-windows-msvc'
|