Make it possible to install cross from a git tag

This commit is contained in:
Dave Rolsky 2024-05-18 12:00:21 +08:00
parent a0b2ccd631
commit c464bd9469
No known key found for this signature in database
3 changed files with 25 additions and 11 deletions

View File

@ -1,3 +1,8 @@
## 0.0.13
- It's now possible to set `cross-version` to a git ref like a commit hash or `HEAD`. This will
install `cross` from its git repo.
## 0.0.12 - 2024-02-25
- Bumped the version of `actions/cache` used in this action to v4. The v3 version uses Node 16,

View File

@ -55,16 +55,16 @@ jobs:
This action takes the following parameters:
| Key | Type | Required? | Description |
| ------------------- | ---------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `command` | string (one of `build`, `test`, or `both`) | no | The command(s) to run. The default is `build`. Running the `test` command will fail with \*BSD targets, non-x86 Windows, and macOS ARM. |
| `target` | string | yes | The target triple to compile for. This should be one of the targets found by running `rustup target list`. |
| `working-directory` | string | no | The working directory in which to run the `cargo` or `cross` commands. Defaults to the current directory (`.`). |
| `toolchain` | string (one of `stable`, `beta`, or `nightly`) | no | The Rust toolchain version to install. The default is `stable`. |
| `GITHUB_TOKEN` | string | no | Defaults to the value of `${{ github.token }}`. |
| `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. If this is not set then the latest version will always be used. |
| Key | Type | Required? | Description |
| ------------------- | ---------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `command` | string (one of `build`, `test`, or `both`) | no | The command(s) to run. The default is `build`. Running the `test` command will fail with \*BSD targets, non-x86 Windows, and macOS ARM. |
| `target` | string | yes | The target triple to compile for. This should be one of the targets found by running `rustup target list`. |
| `working-directory` | string | no | The working directory in which to run the `cargo` or `cross` commands. Defaults to the current directory (`.`). |
| `toolchain` | string (one of `stable`, `beta`, or `nightly`) | no | The Rust toolchain version to install. The default is `stable`. |
| `GITHUB_TOKEN` | string | no | Defaults to the value of `${{ github.token }}`. |
| `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. |
## How it Works

View File

@ -1,3 +1,5 @@
#!/bin/bash
set -e
set -x
set -o pipefail
@ -5,12 +7,19 @@ set -o pipefail
CROSS_DIR="$1"
VERSION="$2"
cd "$CROSS_DIR"
if [[ -n "$VERSION" ]] && ! [[ "$VERSION" =~ ^v ]]; then
cargo install cross --git https://github.com/cross-rs/cross --rev "$VERSION"
mv "$HOME/.cargo/bin/cross" .
exit 0
fi
VERSION_ARGS=""
if [ -n "$VERSION" ]; then
VERSION_ARGS="--tag $VERSION"
fi
cd "$CROSS_DIR"
export TARGET=.
curl --silent --location \
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |