Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91d78d9182 | ||
|
|
30e7adeceb | ||
|
|
ec63efbd36 | ||
|
|
54e4a464ed | ||
|
|
d1d76ade32 | ||
|
|
2bfd2f169a | ||
|
|
42a1f46405 | ||
|
|
58c5e42ace | ||
|
|
2f68f636e2 | ||
|
|
5bd32448aa | ||
|
|
4dfe96e52b |
207
.github/workflows/test.yml
vendored
Normal file
207
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,207 @@
|
||||
name: Self-test
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
platform:
|
||||
- platform_name: FreeBSD-x86_64
|
||||
os: ubuntu-20.04
|
||||
target: x86_64-unknown-freebsd
|
||||
expect_cross: true
|
||||
expect_file: "x86-64.+FreeBSD"
|
||||
expect_stripped: false
|
||||
can_test: false
|
||||
|
||||
- platform_name: Linux-x86_64
|
||||
os: ubuntu-20.04
|
||||
target: x86_64-unknown-linux-musl
|
||||
expect_cross: false
|
||||
expect_file: "ELF.+x86-64"
|
||||
expect_stripped: true
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-aarch64
|
||||
os: ubuntu-20.04
|
||||
target: aarch64-unknown-linux-musl
|
||||
expect_cross: true
|
||||
expect_file: "aarch64"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-arm
|
||||
os: ubuntu-20.04
|
||||
target: arm-unknown-linux-musleabi
|
||||
expect_cross: true
|
||||
expect_file: "32.+ARM"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-i586
|
||||
os: ubuntu-20.04
|
||||
target: i586-unknown-linux-musl
|
||||
expect_cross: false
|
||||
expect_file: "ELF.+80386"
|
||||
expect_stripped: true
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-mips
|
||||
os: ubuntu-20.04
|
||||
target: mips-unknown-linux-musl
|
||||
expect_cross: true
|
||||
expect_file: "MIPS32.+mips-"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-mipsel
|
||||
os: ubuntu-20.04
|
||||
target: mipsel-unknown-linux-musl
|
||||
expect_cross: true
|
||||
expect_file: "MIPS32.+mipsel-"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-mips64
|
||||
os: ubuntu-20.04
|
||||
target: mips64-unknown-linux-muslabi64
|
||||
expect_cross: true
|
||||
expect_file: "MIPS64"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-mips64el
|
||||
os: ubuntu-20.04
|
||||
target: mips64el-unknown-linux-muslabi64
|
||||
expect_cross: true
|
||||
expect_file: "MIPS64"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-powerpc
|
||||
os: ubuntu-20.04
|
||||
target: powerpc-unknown-linux-gnu
|
||||
expect_cross: true
|
||||
expect_file: "32.+PowerPC"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-powerpc64
|
||||
os: ubuntu-20.04
|
||||
target: powerpc64-unknown-linux-gnu
|
||||
expect_cross: true
|
||||
expect_file: "64.+PowerPC"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-powerpc64le
|
||||
os: ubuntu-20.04
|
||||
target: powerpc64le-unknown-linux-gnu
|
||||
expect_cross: true
|
||||
expect_file: "64.+PowerPC"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-riscv64
|
||||
os: ubuntu-20.04
|
||||
target: riscv64gc-unknown-linux-gnu
|
||||
expect_cross: true
|
||||
expect_file: "64.+RISC-V"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: Linux-s390x
|
||||
os: ubuntu-20.04
|
||||
target: s390x-unknown-linux-gnu
|
||||
expect_cross: true
|
||||
expect_file: "64.+S/390"
|
||||
expect_stripped: false
|
||||
can_test: true
|
||||
|
||||
- platform_name: NetBSD-x86_64
|
||||
os: ubuntu-20.04
|
||||
target: x86_64-unknown-netbsd
|
||||
expect_cross: true
|
||||
expect_file: "x86-64.+NetBSD"
|
||||
expect_stripped: false
|
||||
can_test: false
|
||||
|
||||
- platform_name: Windows-aarch64
|
||||
os: windows-latest
|
||||
target: aarch64-pc-windows-msvc
|
||||
expect_cross: false
|
||||
expect_file: "Aarch64.+Windows"
|
||||
expect_stripped: false
|
||||
can_test: false
|
||||
|
||||
- platform_name: Windows-i686
|
||||
os: windows-latest
|
||||
target: i686-pc-windows-msvc
|
||||
expect_cross: false
|
||||
expect_file: "80386.+Windows"
|
||||
expect_stripped: true
|
||||
can_test: true
|
||||
|
||||
- platform_name: Windows-x86_64
|
||||
os: windows-latest
|
||||
target: x86_64-pc-windows-msvc
|
||||
expect_cross: false
|
||||
expect_file: "x86-64.+Windows"
|
||||
expect_stripped: true
|
||||
can_test: true
|
||||
|
||||
- platform_name: macOS-x86_64
|
||||
os: macOS-latest
|
||||
target: x86_64-apple-darwin
|
||||
expect_cross: false
|
||||
expect_file: "Mach-O.+x86_64"
|
||||
expect_stripped: true
|
||||
can_test: true
|
||||
|
||||
- platform_name: macOS-aarch64
|
||||
os: macOS-latest
|
||||
target: aarch64-apple-darwin
|
||||
expect_cross: false
|
||||
expect_file: "Mach-O.+arm64"
|
||||
expect_stripped: true
|
||||
can_test: false
|
||||
|
||||
runs-on: ${{ matrix.platform.os }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Copy test project to root
|
||||
shell: bash
|
||||
run: |
|
||||
cp -a test-project/* .
|
||||
rm -fr test-project
|
||||
- name: Run both commands
|
||||
uses: "houseabsolute/actions-rust-cross@v0"
|
||||
with:
|
||||
command: both
|
||||
target: ${{ matrix.platform.target }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
if: ${{ matrix.platform.can_test }}
|
||||
- name: Run test command
|
||||
uses: "houseabsolute/actions-rust-cross@v0"
|
||||
with:
|
||||
command: test
|
||||
target: ${{ matrix.platform.target }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
if: ${{ matrix.platform.can_test }}
|
||||
- name: Run build command
|
||||
uses: "houseabsolute/actions-rust-cross@v0"
|
||||
with:
|
||||
command: build
|
||||
target: ${{ matrix.platform.target }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
strip: true
|
||||
- name: Check binary and cross on ${{ matrix.platform.platform_name }}
|
||||
shell: bash
|
||||
run: |
|
||||
tests/check-binary.sh "${{ matrix.platform.target }}" "${{ matrix.platform.expect_cross }}" "${{ matrix.platform.expect_file }}" "${{ matrix.platform.expect_stripped }}"
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@
|
||||
/package.json
|
||||
.\#*
|
||||
\#*\#
|
||||
test-project/target/**
|
||||
|
||||
20
Changes.md
20
Changes.md
@@ -1,3 +1,23 @@
|
||||
## 0.0.5 - 2023-03-19
|
||||
|
||||
- Fix use of `dtolnay/rust-toolchain` action to allow passing a `toolchain`
|
||||
input.
|
||||
|
||||
## 0.0.4 - 2023-03-19
|
||||
|
||||
- Added a new `toolchain` parameter to allow selecting a Rust toolchain other
|
||||
than stable. This supports picking on of "stable", "beta", or "nightly".
|
||||
- Fixed binary stripping to work in more situations. Previously it depended on
|
||||
a very specific setup plus expected to be run in the context of the matrix I
|
||||
use for my own projects.
|
||||
- Fixed a reference to a matrix variable that should have referenced an input
|
||||
variable.
|
||||
|
||||
## 0.0.3 - 2023-03-17
|
||||
|
||||
- This action now supports running the `build` and `test` commands, or both,
|
||||
with a new input parameter, `command`. The default is `build`.
|
||||
|
||||
## 0.0.2 - 2023-03-05
|
||||
|
||||
- Fixed some typos in the `README.md` documentation.
|
||||
|
||||
18
README.md
18
README.md
@@ -18,18 +18,21 @@ jobs:
|
||||
target: x86_64-unknown-freebsd
|
||||
bin: precious
|
||||
name: precious-FreeBSD-x86_64.tar.gz
|
||||
command: build
|
||||
|
||||
- release_for: Windows-x86_64
|
||||
os: windows-latest
|
||||
target: x86_64-pc-windows-msvc
|
||||
bin: precious.exe
|
||||
name: precious-Windows-x86_64.zip
|
||||
command: both
|
||||
|
||||
- release_for: macOS-x86_64
|
||||
os: macOS-latest
|
||||
target: x86_64-apple-darwin
|
||||
bin: precious
|
||||
name: precious-Darwin-x86_64.tar.gz
|
||||
command: both
|
||||
|
||||
# more release targets here ...
|
||||
|
||||
@@ -40,6 +43,7 @@ jobs:
|
||||
- name: Build binary
|
||||
uses: houseabsolute/actions-rust-cross@v0
|
||||
with:
|
||||
command: ${{ matrix.platform.command }}
|
||||
target: ${{ matrix.platform.target }}
|
||||
args: "--locked --release"
|
||||
strip: true
|
||||
@@ -51,12 +55,14 @@ jobs:
|
||||
|
||||
This action takes the following parameters:
|
||||
|
||||
| Key | Type | Required? | Description |
|
||||
| -------------- | --------------------------- | --------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `target` | string | yes | The target triple to compile for. This should be one of the targets listed by running `rustup target list`. |
|
||||
| `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 binary will be stripped if possible. This is only possible for binaries which weren't cross-compiled. |
|
||||
| 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 fails 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 listed by running `rustup target list`. |
|
||||
| `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 binary will be stripped if possible. This is only possible for binaries which weren't cross-compiled. |
|
||||
|
||||
## How it Works
|
||||
|
||||
|
||||
36
action.yml
36
action.yml
@@ -6,9 +6,17 @@ branding:
|
||||
description: |
|
||||
Cross compile your Rust projects with cross (https://github.com/cross-rs/cross).
|
||||
inputs:
|
||||
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 context variable.
|
||||
@@ -32,9 +40,10 @@ runs:
|
||||
shell: bash
|
||||
run: set-cross-compile.sh ${{ inputs.target }}
|
||||
- name: Install toolchain if not cross-compiling
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
uses: dtolnay/rust-toolchain@master
|
||||
with:
|
||||
targets: ${{ matrix.platform.target }}
|
||||
targets: ${{ inputs.target }}
|
||||
toolchain: ${{ inputs.toolchain }}
|
||||
if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'false' }}
|
||||
- name: Install cross if cross-compiling (*nix)
|
||||
shell: bash
|
||||
@@ -52,23 +61,32 @@ runs:
|
||||
id: set-build-command
|
||||
shell: bash
|
||||
run: set-build-command.sh
|
||||
- name: Build binary (*nix)
|
||||
- name: Run tests (*nix)
|
||||
shell: bash
|
||||
run: |
|
||||
${{ steps.set-build-command.outputs.build-command }} build ${{ inputs.args }} --target ${{ inputs.target }}
|
||||
if: ${{ runner.os != 'Windows' }}
|
||||
${{ steps.set-build-command.outputs.build-command }} 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)
|
||||
shell: powershell
|
||||
run: |
|
||||
& ${{ steps.set-build-command.outputs.build-command }} test ${{ inputs.args }} --target ${{ inputs.target }}
|
||||
if: ${{ inputs.command != 'build' && runner.os == 'Windows' }}
|
||||
- name: Build binary (*nix)
|
||||
shell: bash
|
||||
run: |
|
||||
${{ steps.set-build-command.outputs.build-command }} build ${{ inputs.args }} --target ${{ inputs.target }}
|
||||
if: ${{ inputs.command != 'test' && runner.os != 'Windows' }}
|
||||
- name: Build binary (Windows)
|
||||
shell: powershell
|
||||
run: |
|
||||
& ${{ steps.set-build-command.outputs.build-command }} build ${{ inputs.args }} --target ${{ inputs.target }}
|
||||
if: ${{ runner.os == 'Windows' }}
|
||||
if: ${{ inputs.command != 'test' && runner.os == 'Windows' }}
|
||||
- name: Strip binary
|
||||
shell: bash
|
||||
run: |
|
||||
strip target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
|
||||
run: strip-binary.sh ${{ inputs.target }}
|
||||
# strip doesn't work with cross-arch binaries on Linux or Windows.
|
||||
if: ${{ inputs.strip == 'true' && steps.determine-cross-compile.outputs.needs-cross == 'false' && inputs.target != 'aarch64-pc-windows-msvc' }}
|
||||
if: ${{ inputs.command != 'test' && inputs.strip == 'true' && steps.determine-cross-compile.outputs.needs-cross == 'false' && inputs.target != 'aarch64-pc-windows-msvc' }}
|
||||
|
||||
33
strip-binary.sh
Executable file
33
strip-binary.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
set -e
|
||||
set -x
|
||||
|
||||
TARGET=$1
|
||||
|
||||
DIR=""
|
||||
for type in debug release; do
|
||||
if [ -d "target/$TARGET/$type" ]; then
|
||||
DIR="target/$TARGET/$type"
|
||||
break
|
||||
elif [ -d "target/$type" ]; then
|
||||
DIR="target/$type"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$DIR" ]; then
|
||||
echo "Could not find directory with binary in it under target/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $( uname -s ) =~ "Darwin" ]]; then
|
||||
EXE=$( find "$DIR" -maxdepth 1 -type f -perm +111 )
|
||||
else
|
||||
EXE=$( find "$DIR" -maxdepth 1 -type f -executable )
|
||||
fi
|
||||
|
||||
if [ -z "$EXE" ]; then
|
||||
echo "Could not find a binary to strip in $DIR"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
strip "$EXE"
|
||||
7
test-project/Cargo.lock
generated
Normal file
7
test-project/Cargo.lock
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "test-project"
|
||||
version = "0.1.0"
|
||||
6
test-project/Cargo.toml
Normal file
6
test-project/Cargo.toml
Normal file
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "test-project"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
11
test-project/src/main.rs
Normal file
11
test-project/src/main.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
#[test]
|
||||
fn test_something() {
|
||||
assert_eq!(1, 1);
|
||||
}
|
||||
}
|
||||
49
tests/check-binary.sh
Executable file
49
tests/check-binary.sh
Executable file
@@ -0,0 +1,49 @@
|
||||
set -e
|
||||
set -x
|
||||
|
||||
TARGET=$1
|
||||
EXPECT_CROSS=$2
|
||||
EXPECT_FILE_RE=$3
|
||||
EXPECT_STRIPPED=$4
|
||||
|
||||
if [ "$EXPECT_CROSS" == "true" ]; then
|
||||
if [ ! -f "$RUNNER_TEMP/cross" ]; then
|
||||
echo "Could not find cross in path: $PATH"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
if [ -f "$RUNNER_TEMP/cross" ]; then
|
||||
echo "Found cross in path: $PATH"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
FILE=$(file --brief ./target/$TARGET/debug/test-project)
|
||||
if [[ "$FILE" =~ $EXPECT_FILE_RE ]]; then
|
||||
echo "file output matches $EXPECT_FILE_RE"
|
||||
else
|
||||
echo "file output does not match $EXPECT_FILE_RE"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
if [[ $( uname -s ) =~ "Darwin" ]]; then
|
||||
# File on macOS doesn't report whether the binary is stripped or not.
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$FILE" =~ "not stripped" ]]; then
|
||||
echo "binary was not stripped"
|
||||
GOT_STRIPPED="false"
|
||||
elif [[ "$FILE" =~ "stripped" ]]; then
|
||||
echo "binary was stripped"
|
||||
GOT_STRIPPED="true"
|
||||
else
|
||||
# On Windows the aarch64 binary's file info doesn't include the word
|
||||
# "stripped" at all.
|
||||
echo "binary was not stripped"
|
||||
GOT_STRIPPED="false"
|
||||
fi
|
||||
|
||||
if [ "$EXPECT_STRIPPED" != "$GOT_STRIPPED" ]; then
|
||||
exit 3
|
||||
fi
|
||||
Reference in New Issue
Block a user