12 Commits

Author SHA1 Message Date
Dave Rolsky
601d02e82d Add release date for 1.0.2
Some checks failed
Lint / Check that code is lint clean using precious (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:false can-execute:true cross-version:19be834 expect-cross:--expect-cross expect-cross-version:19be834 expect-file-re:aarch64 expect-stripped: platform_name:Linux-aarch64 with cross 19be834 (no cache) runs-on:ubuntu-2… (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:false can-execute:true cross-version:v0.2.3 expect-cross:--expect-cross expect-cross-version:0.2.3 expect-file-re:aarch64 expect-stripped: platform_name:Linux-aarch64 with cross v0.2.3 (no cache) runs-on:ubuntu-24.04… (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:false can-execute:true expect-cross:--expect-cross expect-file-re:aarch64 expect-stripped: platform_name:Linux-aarch64 (no cache) runs-on:ubuntu-24.04 target:aarch64-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:false expect-cross:--expect-cross expect-file-re:x86-64.+FreeBSD expect-stripped: platform_name:FreeBSD-x86_64 runs-on:ubuntu-24.04 target:x86_64-unknown-freebsd]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:false expect-cross:--expect-cross expect-file-re:x86-64.+NetBSD expect-stripped: platform_name:NetBSD-x86_64 runs-on:ubuntu-24.04 target:x86_64-unknown-netbsd]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true cross-version:19be834 expect-cross:--expect-cross expect-cross-version:19be834 expect-file-re:aarch64 expect-stripped: platform_name:Linux-aarch64 with cross 19be834 runs-on:ubuntu-24.04 target:… (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true cross-version:v0.2.3 expect-cross:--expect-cross expect-cross-version:0.2.3 expect-file-re:aarch64 expect-stripped: platform_name:Linux-aarch64 with cross v0.2.3 runs-on:ubuntu-24.04 target:aarc… (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross: expect-file-re:ELF.+x86-64 expect-stripped:--expect-stripped platform_name:Linux-x86_64 runs-on:ubuntu-24.04 target:x86_64-unknown-linux-musl]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:32.+ARM expect-stripped: platform_name:Linux-arm runs-on:ubuntu-24.04 target:arm-unknown-linux-gnueabi]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:32.+PowerPC expect-stripped: platform_name:Linux-powerpc runs-on:ubuntu-24.04 target:powerpc-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:64.+PowerPC expect-stripped: platform_name:Linux-powerpc64 runs-on:ubuntu-24.04 target:powerpc64-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:64.+PowerPC expect-stripped: platform_name:Linux-powerpc64le runs-on:ubuntu-24.04 target:powerpc64le-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:64.+RISC-V expect-stripped: platform_name:Linux-riscv64 runs-on:ubuntu-24.04 target:riscv64gc-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:64.+S/390 expect-stripped: platform_name:Linux-s390x runs-on:ubuntu-24.04 target:s390x-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:ELF.+80386 expect-stripped: platform_name:Linux-i586 runs-on:ubuntu-24.04 target:i586-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:ELF.+80386 expect-stripped: platform_name:Linux-i686 runs-on:ubuntu-24.04 target:i686-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:ELF.+x86-64 expect-stripped: force-use-cross:true platform_name:Linux-x86_64 (force cross) runs-on:ubuntu-24.04 target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross:--expect-cross expect-file-re:aarch64 expect-stripped: platform_name:Linux-aarch64 runs-on:ubuntu-24.04 target:aarch64-unknown-linux-musl]) (push) Failing after 0s
Self-test / Test validate-inputs (push) Failing after 0s
Self-test / Test action (map[cache-cross-binary:true can-execute:false expect-cross: expect-file-re:Aarch64.+Windows expect-stripped: platform_name:Windows-aarch64 runs-on:windows-latest target:aarch64-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test action (map[cache-cross-binary:true can-execute:false expect-cross: expect-file-re:Mach-O.+arm64 expect-stripped:--expect-stripped platform_name:macOS-aarch64 runs-on:macOS-latest target:aarch64-apple-darwin]) (push) Has been cancelled
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross: expect-file-re:80386.+Windows expect-stripped:--expect-stripped platform_name:Windows-i686 runs-on:windows-latest target:i686-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-cross: expect-file-re:Mach-O.+x86_64 expect-stripped:--expect-stripped platform_name:macOS-x86_64 runs-on:macOS-latest target:x86_64-apple-darwin]) (push) Has been cancelled
Self-test / Test action (map[cache-cross-binary:true can-execute:true expect-file-re:x86-64.+Windows expect-stripped:--expect-stripped platform_name:Windows-x86_64 runs-on:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
2025-02-16 11:30:23 -06:00
Dave Rolsky
2c7c51e283 Tweak matrix description for test case 2025-02-16 11:22:07 -06:00
Dave Rolsky
9a022034a6 Add comment to remind myself why we need cross for Linux i586/i686 targets 2025-02-16 11:15:45 -06:00
Dave Rolsky
dc1022bc69 Mostly use GNU targets on Linux
This avoids having to install the `musl-tools`, which in turn speeds test runs up a little bit.
2025-02-16 11:15:44 -06:00
Dave Rolsky
b4ab796093 Fix typo in Changes.md 2025-02-16 11:15:21 -06:00
Dave Rolsky
b094471e7c Improve run-test assertion output 2025-02-16 11:15:21 -06:00
Dave Rolsky
885ad4bc41 Fix validator to always print input names with dashes in errors 2025-02-16 11:15:21 -06:00
Dave Rolsky
c40b27b8f9 Add a force-use-cross input 2025-02-16 11:15:19 -06:00
Dave Rolsky
7619b10b9f Add more newlines in action.yml 2025-02-16 10:28:55 -06:00
Dave Rolsky
a72a5f146c Update README.md to use ubuntu-24.04 in examples 2025-02-15 12:54:54 -06:00
Dave Rolsky
f0ceffbf58 Update all CI jobs using ubuntu to 24.04 2025-02-15 12:54:42 -06:00
Dave Rolsky
c04b5a0b3e Add docs on using mise 2025-02-09 17:55:51 -06:00
8 changed files with 160 additions and 47 deletions

View File

@@ -8,7 +8,7 @@ env:
jobs:
lint:
name: Check that code is lint clean using precious
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install mise

View File

@@ -12,7 +12,7 @@ jobs:
matrix:
platform:
- platform_name: FreeBSD-x86_64
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
target: x86_64-unknown-freebsd
cache-cross-binary: true
expect-file-re: "x86-64.+FreeBSD"
@@ -21,7 +21,9 @@ jobs:
can-execute: false
- platform_name: Linux-x86_64
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
# It's important to use a musl target here to make sure that the step to install
# musl-tools works.
target: x86_64-unknown-linux-musl
cache-cross-binary: true
expect-file-re: "ELF.+x86-64"
@@ -29,8 +31,18 @@ jobs:
expect-stripped: "--expect-stripped"
can-execute: true
- platform_name: Linux-x86_64 (force cross)
runs-on: ubuntu-24.04
target: x86_64-unknown-linux-gnu
force-use-cross: true
cache-cross-binary: true
expect-file-re: "ELF.+x86-64"
expect-cross: "--expect-cross"
expect-stripped: ""
can-execute: true
- platform_name: Linux-aarch64
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
target: aarch64-unknown-linux-musl
cache-cross-binary: true
expect-file-re: "aarch64"
@@ -39,8 +51,8 @@ jobs:
can-execute: true
- platform_name: Linux-aarch64 (no cache)
runs-on: ubuntu-22.04
target: aarch64-unknown-linux-musl
runs-on: ubuntu-24.04
target: aarch64-unknown-linux-gnu
cache-cross-binary: false
expect-file-re: "aarch64"
expect-cross: "--expect-cross"
@@ -48,8 +60,8 @@ jobs:
can-execute: true
- platform_name: Linux-aarch64 with cross v0.2.3
runs-on: ubuntu-22.04
target: aarch64-unknown-linux-musl
runs-on: ubuntu-24.04
target: aarch64-unknown-linux-gnu
cross-version: "v0.2.3"
cache-cross-binary: true
expect-file-re: "aarch64"
@@ -59,8 +71,8 @@ jobs:
can-execute: true
- platform_name: Linux-aarch64 with cross v0.2.3 (no cache)
runs-on: ubuntu-22.04
target: aarch64-unknown-linux-musl
runs-on: ubuntu-24.04
target: aarch64-unknown-linux-gnu
cross-version: "v0.2.3"
cache-cross-binary: false
expect-file-re: "aarch64"
@@ -70,8 +82,8 @@ jobs:
can-execute: true
- platform_name: Linux-aarch64 with cross 19be834
runs-on: ubuntu-22.04
target: aarch64-unknown-linux-musl
runs-on: ubuntu-24.04
target: aarch64-unknown-linux-gnu
cross-version: "19be834"
cache-cross-binary: true
expect-file-re: "aarch64"
@@ -80,9 +92,9 @@ jobs:
expect-stripped: ""
can-execute: true
- platform_name: Linux-aarch64 with cross 19be834
runs-on: ubuntu-22.04
target: aarch64-unknown-linux-musl
- platform_name: Linux-aarch64 with cross 19be834 (no cache)
runs-on: ubuntu-24.04
target: aarch64-unknown-linux-gnu
cross-version: "19be834"
cache-cross-binary: false
expect-file-re: "aarch64"
@@ -92,8 +104,8 @@ jobs:
can-execute: true
- platform_name: Linux-arm
runs-on: ubuntu-22.04
target: arm-unknown-linux-musleabi
runs-on: ubuntu-24.04
target: arm-unknown-linux-gnueabi
cache-cross-binary: true
expect-file-re: "32.+ARM"
expect-cross: "--expect-cross"
@@ -101,8 +113,8 @@ jobs:
can-execute: true
- platform_name: Linux-i586
runs-on: ubuntu-22.04
target: i586-unknown-linux-musl
runs-on: ubuntu-24.04
target: i586-unknown-linux-gnu
cache-cross-binary: true
expect-file-re: "ELF.+80386"
expect-cross: "--expect-cross"
@@ -110,8 +122,8 @@ jobs:
can-execute: true
- platform_name: Linux-i686
runs-on: ubuntu-22.04
target: i686-unknown-linux-musl
runs-on: ubuntu-24.04
target: i686-unknown-linux-gnu
cache-cross-binary: true
expect-file-re: "ELF.+80386"
expect-cross: "--expect-cross"
@@ -119,7 +131,7 @@ jobs:
can-execute: true
- platform_name: Linux-powerpc
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
target: powerpc-unknown-linux-gnu
cache-cross-binary: true
expect-file-re: "32.+PowerPC"
@@ -128,7 +140,7 @@ jobs:
can-execute: true
- platform_name: Linux-powerpc64
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
target: powerpc64-unknown-linux-gnu
cache-cross-binary: true
expect-file-re: "64.+PowerPC"
@@ -137,7 +149,7 @@ jobs:
can-execute: true
- platform_name: Linux-powerpc64le
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
target: powerpc64le-unknown-linux-gnu
cache-cross-binary: true
expect-file-re: "64.+PowerPC"
@@ -146,7 +158,7 @@ jobs:
can-execute: true
- platform_name: Linux-riscv64
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
target: riscv64gc-unknown-linux-gnu
cache-cross-binary: true
expect-file-re: "64.+RISC-V"
@@ -155,7 +167,7 @@ jobs:
can-execute: true
- platform_name: Linux-s390x
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
target: s390x-unknown-linux-gnu
cache-cross-binary: true
expect-file-re: "64.+S/390"
@@ -164,7 +176,7 @@ jobs:
can-execute: true
- platform_name: NetBSD-x86_64
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
target: x86_64-unknown-netbsd
cache-cross-binary: true
expect-file-re: "x86-64.+NetBSD"
@@ -229,6 +241,7 @@ jobs:
uses: ./
with:
command: both
force-use-cross: ${{ matrix.platform.force-use-cross || false }}
cross-version: ${{ matrix.platform.cross-version }}
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
target: ${{ matrix.platform.target }}
@@ -238,6 +251,7 @@ jobs:
uses: ./
with:
command: test
force-use-cross: ${{ matrix.platform.force-use-cross || false }}
cross-version: ${{ matrix.platform.cross-version }}
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
target: ${{ matrix.platform.target }}
@@ -247,6 +261,7 @@ jobs:
uses: ./
with:
command: test
force-use-cross: ${{ matrix.platform.force-use-cross || false }}
cross-version: ${{ matrix.platform.cross-version }}
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
target: ${{ matrix.platform.target }}
@@ -257,6 +272,7 @@ jobs:
uses: ./
with:
command: build
force-use-cross: ${{ matrix.platform.force-use-cross || false }}
cross-version: ${{ matrix.platform.cross-version }}
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
target: ${{ matrix.platform.target }}
@@ -278,6 +294,7 @@ jobs:
uses: ./
with:
command: build
force-use-cross: ${{ matrix.platform.force-use-cross || false }}
cross-version: ${{ matrix.platform.cross-version }}
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
working-directory: subcrate
@@ -301,6 +318,7 @@ jobs:
uses: ./
with:
command: bench
force-use-cross: ${{ matrix.platform.force-use-cross || false }}
cross-version: ${{ matrix.platform.cross-version }}
cache-cross-binary: ${{ matrix.platform.cache-cross-binary }}
target: ${{ matrix.platform.target }}
@@ -310,7 +328,7 @@ jobs:
test-validate-inputs:
name: Test validate-inputs
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4

View File

@@ -1,3 +1,9 @@
## 1.0.2 - 2025-02-16
- Added a new `force-use-cross` input, which does what it says. It will force the use of `cross`
even when it is not required for given platform/target combination. Note that this only works on
Linux hosts.
## 1.0.1 - 2025-01-20
- Fixed a bug where this action would attempt to use `cross` when compiling for an ARM Linux target
@@ -32,7 +38,7 @@ bumped to v1.0.0 because of this change.
- This action will now configure and use `Swatinem/rust-cache` by default for you. It will include
the `target` parameter as part of the cache key automatically. Suggested by @jennydaman (Jennings
Zhang). GH #23.
- This action now validates its input and will exit early if they are not valid. GH #35.
- This action now validates its inputs and will exit early if they are not valid. GH #35.
## 0.0.17 - 2024-11-23

View File

@@ -14,19 +14,19 @@ jobs:
matrix:
platform:
- os-name: FreeBSD-x86_64
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
target: x86_64-unknown-freebsd
- os-name: Linux-x86_64
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
target: x86_64-unknown-linux-musl
- os-name: Linux-aarch64
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
target: aarch64-unknown-linux-musl
- os-name: Linux-riscv64
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
target: riscv64gc-unknown-linux-gnu
- os-name: Windows-x86_64
@@ -60,7 +60,7 @@ jobs:
Note that for Linux or BSD targets, you should always set the `runs-on` key to a Linux x86-64
architecture runner.
If you _only_ want to do native ARM compilation, for example using the `ubuntu-latest-arm` runner,
If you _only_ want to do native ARM compilation, for example using the `ubuntu-24.04-arm` runner,
then there's no need to use this action. However, if you want to compile for _many_ platforms,
including Linux ARM, using this action will simplify your config. This action is only tested on
Ubuntu x86-64, Windows, and macOS runners.
@@ -79,6 +79,7 @@ This action takes the following parameters:
| `args` | string | no | A string-separated list of arguments to be passed to `cross build`, like `--release --locked`. |
| `strip` | boolean (`true` or `false`) | no | If this is true, then the resulting binaries will be stripped if possible. This is only possible for binaries which weren't cross-compiled. |
| `cross-version` | string | no | This can be used to set the version of `cross` to use. If specified, it should be a specific `cross` release tag (like `v0.2.3`) or a git ref (commit hash, `HEAD`, etc.). If this is not set then the latest released version will always be used. If this is set to a git ref then the version corresponding to that ref will be installed. |
| `force-use-cross` | boolean (`true` or `false`) | no | If this is true, then the action will use `cross` even if it is not needed for the given target. If this is set to `true`, then the resulting binary will not be stripped, regardless of whether `strip` is `true` or not. This only works on Linux hosts. Forcing the use of `cross` on other hosts is not supported. |
| `use-rust-cache` | boolean | no | Whether or not to use [the `Swatinem/rust-cache@v2` action](https://github.com/Swatinem/rust-cache). This defaults to true. |
| `rust-cache-parameters` | string (containing JSON) | no | This must be a string containing valid JSON. The JSON should be an object where the keys are the parameters for [the `Swatinem/rust-cache@v2` action](https://github.com/Swatinem/rust-cache). |
@@ -161,3 +162,29 @@ you can avoid this issue by structuring your workflow as follows:
4. Run the release steps for crate B.
When structured this way, it does not matter if the output of crate A is deleted in step 3.
## Linting and Tidying this Code
The code in this repo is linted and tidied with
[`precious`](https://github.com/houseabsolute/precious). This repo contains a `mise.toml` file.
[Mise](https://mise.jdx.dev/) is a tool for managing dev tools with per-repo configuration. You can
install `mise` and use it to run `precious` as follows:
```
# Installs mise
curl https://mise.run | sh
# Installs precious and other dev tools
mise install
```
Once this is done, you can run `precious` via `mise`:
```
# Lints all code
mise exec -- precious lint -a
# Tidies all code
mise exec -- precious tidy -a
```
If you want to use `mise` for other projects, see [its documentation](https://mise.jdx.dev/) for
more details on how you can configure your shell to always activate `mise`.

View File

@@ -1,55 +1,74 @@
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:
target:
description: The target platform
required: true
command:
description: |
The commands to run. This must be one of "build", "test", "both" (build and test), or "bench".
default: build
toolchain:
description: |
The target toolchain to use (one of "stable", "beta", or "nightly").
default: stable
working-directory:
description: The working directory for each step
default: "."
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
force-use-cross:
description: |
If this is true, the action will use cross even for targets where it is not needed.
default: false
use-rust-cache:
description: |
Use `Swatinem/rust-cache@v2`. Defaults to true.
default: true
rust-cache-parameters:
description: |
A JSON string containing parameters to pass to `Swatinem/rust-cache@v2`. You can use the
`toJSON()` function in your action to make passing this easier.
default: "{}"
runs:
using: composite
steps:
@@ -57,9 +76,11 @@ runs:
shell: bash
run: |
echo '${{ toJSON(inputs) }}'
- name: Add this action's path to PATH
shell: bash
run: echo "${{ github.action_path }}" >> $GITHUB_PATH
- name: Validate inputs
shell: bash
run: |
@@ -71,17 +92,21 @@ runs:
INPUTS_working_directory: ${{ inputs.working-directory }}
INPUTS_strip: ${{ inputs.strip }}
INPUTS_cache_cross_binary: ${{ inputs.cache-cross-binary }}
INPUTS_force_use_cross: ${{ inputs.force-use-cross }}
INPUTS_use_rust_cache: ${{ inputs.use-rust-cache }}
INPUTS_rust_cache_parameters: ${{ inputs.rust-cache-parameters }}
- name: Determine whether we need to cross-compile
id: determine-cross-compile
shell: bash
run: set-cross-compile.py ${{ inputs.target }}
run: set-cross-compile.py ${{ inputs.target }} ${{ inputs.force-use-cross }}
- 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
@@ -89,6 +114,7 @@ runs:
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
@@ -96,6 +122,7 @@ runs:
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
@@ -103,12 +130,14 @@ runs:
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: |
@@ -118,14 +147,17 @@ runs:
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: Determine which cargo commands to run
id: determine-cargo-commands
shell: bash
run: determine-cargo-commands.sh ${{ inputs.command }}
- name: Parse `rust-cache-parameters` and set inputs for `Swatinem/rust-cache@v2`
id: parse-rust-cache-parameters
shell: bash
@@ -144,16 +176,19 @@ runs:
env:
RUST_CACHE_PARAMETERS: ${{ inputs.rust-cache-parameters }}
if: inputs.use-rust-cache == 'true'
- name: Cache cargo & target directories
uses: Swatinem/rust-cache@v2
with: ${{ steps.parse-rust-cache-parameters.outputs }}
if: inputs.use-rust-cache == 'true'
- 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: steps.determine-cargo-commands.outputs.test == 'true' && 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
@@ -164,30 +199,35 @@ runs:
run: |
& ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} test --target ${{ inputs.target }} ${{ inputs.args }}
if: steps.determine-cargo-commands.outputs.test == 'true' && runner.os == 'Windows'
- name: Run benchmarks (*nix)
working-directory: ${{ inputs.working-directory }}
shell: bash
run: |
${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} bench --target ${{ inputs.target }} ${{ inputs.args }}
if: steps.determine-cargo-commands.outputs.bench == 'true' && runner.os != 'Windows'
- name: Run benchmarks (Windows)
working-directory: ${{ inputs.working-directory }}
shell: powershell
run: |
& ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} bench --target ${{ inputs.target }} ${{ inputs.args }}
if: steps.determine-cargo-commands.outputs.bench == 'true' && 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: steps.determine-cargo-commands.outputs.build == 'true' && 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: steps.determine-cargo-commands.outputs.build == 'true' && runner.os == 'Windows'
- name: Strip binary
working-directory: ${{ inputs.working-directory }}
shell: bash

View File

@@ -79,7 +79,11 @@ fn check_cross(bin_dir: &Path, expect_cross: bool, expect_cross_version: Option<
let cross_path = bin_dir.join("cross");
if expect_cross {
assert!(cross_path.is_file(), "`cross` exists");
assert!(
cross_path.is_file(),
"`cross` exists at {}",
cross_path.display()
);
if let Some(expected_version) = expect_cross_version {
let output = Command::new(&cross_path)
@@ -90,7 +94,7 @@ fn check_cross(bin_dir: &Path, expect_cross: bool, expect_cross_version: Option<
.expect("`cross --version` stdout was not valid UTF-8");
assert!(
version.contains(expected_version),
"`cross` version matches expected version"
"`cross` version matches expected version: {expected_version}",
);
}
} else {
@@ -136,25 +140,29 @@ fn check_binary(bin_path: &PathBuf, expect_file_re: Option<&str>, expect_strippe
if expect_stripped {
assert!(
!file_output.contains("not stripped"),
"`file` does not report {} as not stripped",
"`file` does not report {} as 'not stripped': `{}`",
bin_path.display(),
file_output,
);
assert!(
file_output.contains("stripped"),
"`file` reports {} as stripped",
"`file` reports {} as 'stripped': `{}`",
bin_path.display(),
file_output,
);
} else if cfg!(windows) {
assert!(
!file_output.contains("stripped"),
"`file` does not report {} as stripped",
"`file` does not report {} as 'stripped': `{}`",
bin_path.display(),
file_output,
);
} else {
assert!(
file_output.contains("not stripped"),
"`file` reports {} as not stripped",
"`file` reports {} as 'not stripped': `{}`",
bin_path.display(),
file_output,
);
}
}

View File

@@ -16,12 +16,20 @@ def main() -> int:
Returns:
Exit code (0 for success)
"""
if len(sys.argv) < 2:
print("Error: Target architecture argument is required", file=sys.stderr)
if len(sys.argv) < 3:
print(
"Error: Target architecture and force cross arguments are required",
file=sys.stderr,
)
return 1
target = sys.argv[1]
needs_cross = check_needs_cross(target)
force_use_cross = sys.argv[2]
if force_use_cross == "true":
needs_cross = True
else:
needs_cross = check_needs_cross(target)
write_github_output(needs_cross)
return 0
@@ -53,6 +61,10 @@ def check_needs_cross(target: str) -> bool:
):
return False
# It's tempting to not use cross when the host is Linux x86-64 and we're compiling for Linux
# i586 or i686. This sort of works, but if there's any C being compiled, things get weird,
# because then we need 32-bit C headers, 32-bit C libs to link to, etc.
# Check if both host and target are ARM Linux. I'm assuming here that for things like
# "arm-linux-androideabi" or "armv7-unknown-linux-ohos" we'd still need cross.
if (

View File

@@ -9,6 +9,8 @@ from typing import Dict, List, Union
import tempfile
import unittest
boolean_flags = {"cache_cross_binary", "force_use_cross", "strip", "use_rust_cache"}
class InputValidator:
"""Validate inputs for a GitHub Action."""
@@ -72,10 +74,11 @@ class InputValidator:
)
# Validate boolean flags
boolean_flags = {"cache_cross_binary", "strip", "use_rust_cache"}
for flag in boolean_flags:
if flag in self.inputs and self.inputs[flag] not in {"true", "false"}:
validation_errors.append(f"'{flag}' must be either 'true' or 'false'")
# Turn the underscores into dashes
dashes = flag.replace("_", "-")
validation_errors.append(f"'{dashes}' must be either 'true' or 'false'")
# Validate rust-cache-parameters JSON if present
if "rust_cache_parameters" in self.inputs:
@@ -212,7 +215,6 @@ class TestInputValidator(unittest.TestCase):
def test_validate_boolean_flags(self) -> None:
"""Test validation of boolean flags."""
boolean_flags = ["cache-cross-binary", "strip", "use-rust-cache"]
# Test valid boolean values
for flag in boolean_flags: