Skip to content

Commit

Permalink
feat: wip: bring rust-cross action into repo for experimentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Orris committed Mar 8, 2024
1 parent c35342a commit 834563d
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
123 changes: 123 additions & 0 deletions .github/workflows/common/rust-cross/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: "Build Rust Projects with Cross"
author: "Dave Rolsky <[email protected]>"
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.
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
shell: bash
# uses: dtolnay/rust-toolchain@master
# with:
# targets: ${{ inputs.target }}
# toolchain: ${{ inputs.toolchain }}
run: |
rustup toolchain install ${{ inputs.toolchain }}
rustup target add ${{ inputs.target }}
rustup default ${{ 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 accesss 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' }}
- 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: 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 ${{ inputs.args }} --target ${{ inputs.target }}
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 ${{ inputs.args }} --target ${{ inputs.target }}
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' }}
2 changes: 1 addition & 1 deletion .github/workflows/verify-pr-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
- run: echo "Cross Build ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }}"
- uses: actions/checkout@v4
- name: Build Binary
uses: houseabsolute/actions-rust-cross@a0b2ccd63176060d61d875a04fabe94da5c75921
uses: ./.github/workflows/common/rust-cross
with:
command: "build"
target: ${{ matrix.platform.target }}
Expand Down

0 comments on commit 834563d

Please sign in to comment.