Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3de92613ad | ||
|
|
c507aeb1b5 | ||
|
|
9fb7236944 | ||
|
|
883c7a0854 | ||
|
|
ef5051e603 |
15
.github/workflows/test.yml
vendored
15
.github/workflows/test.yml
vendored
@@ -35,6 +35,16 @@ jobs:
|
|||||||
expect_stripped: "--no-expect-stripped"
|
expect_stripped: "--no-expect-stripped"
|
||||||
can_test: true
|
can_test: true
|
||||||
|
|
||||||
|
- platform_name: Linux-aarch64-with-cross-v0.2.3
|
||||||
|
os: ubuntu-20.04
|
||||||
|
target: aarch64-unknown-linux-musl
|
||||||
|
cross-version: "v0.2.3"
|
||||||
|
expect_file_re: "aarch64"
|
||||||
|
expect_cross: "--expect-cross"
|
||||||
|
expect_cross_version: "0.2.3"
|
||||||
|
expect_stripped: "--no-expect-stripped"
|
||||||
|
can_test: true
|
||||||
|
|
||||||
- platform_name: Linux-arm
|
- platform_name: Linux-arm
|
||||||
os: ubuntu-20.04
|
os: ubuntu-20.04
|
||||||
target: arm-unknown-linux-musleabi
|
target: arm-unknown-linux-musleabi
|
||||||
@@ -183,6 +193,7 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
command: both
|
command: both
|
||||||
|
cross-version: ${{ matrix.platform.cross-version }}
|
||||||
target: ${{ matrix.platform.target }}
|
target: ${{ matrix.platform.target }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
if: ${{ matrix.platform.can_test }}
|
if: ${{ matrix.platform.can_test }}
|
||||||
@@ -190,6 +201,7 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
command: test
|
command: test
|
||||||
|
cross-version: ${{ matrix.platform.cross-version }}
|
||||||
target: ${{ matrix.platform.target }}
|
target: ${{ matrix.platform.target }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
if: ${{ matrix.platform.can_test }}
|
if: ${{ matrix.platform.can_test }}
|
||||||
@@ -197,6 +209,7 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
|
cross-version: ${{ matrix.platform.cross-version }}
|
||||||
target: ${{ matrix.platform.target }}
|
target: ${{ matrix.platform.target }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
strip: true
|
strip: true
|
||||||
@@ -204,6 +217,7 @@ jobs:
|
|||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
command: build
|
command: build
|
||||||
|
cross-version: ${{ matrix.platform.cross-version }}
|
||||||
working-directory: subcrate
|
working-directory: subcrate
|
||||||
target: ${{ matrix.platform.target }}
|
target: ${{ matrix.platform.target }}
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -214,5 +228,6 @@ jobs:
|
|||||||
tests/check-binary.pl \
|
tests/check-binary.pl \
|
||||||
--target "${{ matrix.platform.target }}" \
|
--target "${{ matrix.platform.target }}" \
|
||||||
--expect-file-re "${{ matrix.platform.expect_file_re }}" \
|
--expect-file-re "${{ matrix.platform.expect_file_re }}" \
|
||||||
|
--expect-cross-version "${{ matrix.platform.expect_cross_version }}" \
|
||||||
${{ matrix.platform.expect_cross }} \
|
${{ matrix.platform.expect_cross }} \
|
||||||
${{ matrix.platform.expect_stripped }}
|
${{ matrix.platform.expect_stripped }}
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
## 0.0.10 - 2023-12-10
|
||||||
|
|
||||||
|
- Fixed handling of crates with multiple binaries. Attempting to strip binaries for such a crate
|
||||||
|
caused the build to fail. Reported by Tomaž Hribernik. GH #8
|
||||||
|
- Added a new `cross-version` parameter. This can be specified to make this action use a specific
|
||||||
|
version of `cross`. If this is not specified, the latest version will be used.
|
||||||
|
|
||||||
## 0.0.9 - 2023-09-10
|
## 0.0.9 - 2023-09-10
|
||||||
|
|
||||||
- Added a `working-directory` parameter. By default this is the current directory (`.`) but you can
|
- Added a `working-directory` parameter. By default this is the current directory (`.`) but you can
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -55,15 +55,16 @@ jobs:
|
|||||||
|
|
||||||
This action takes the following parameters:
|
This action takes the following parameters:
|
||||||
|
|
||||||
| Key | Type | Required? | Description |
|
| 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. |
|
| `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 listed by running `rustup target list`. |
|
| `target` | string | yes | The target triple to compile for. This should be one of the targets listed 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 (`.`). |
|
| `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`. |
|
| `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 }}`. |
|
| `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`. |
|
| `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. |
|
| `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. |
|
||||||
|
| `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. |
|
||||||
|
|
||||||
## How it Works
|
## How it Works
|
||||||
|
|
||||||
|
|||||||
14
action.yml
14
action.yml
@@ -32,6 +32,10 @@ inputs:
|
|||||||
strip:
|
strip:
|
||||||
description: Strip the compiled binary
|
description: Strip the compiled binary
|
||||||
default: false
|
default: false
|
||||||
|
cross-version:
|
||||||
|
description: |
|
||||||
|
The version of cross to use. If not specified, then the latest version
|
||||||
|
will be used.
|
||||||
runs:
|
runs:
|
||||||
using: composite
|
using: composite
|
||||||
steps:
|
steps:
|
||||||
@@ -47,10 +51,10 @@ runs:
|
|||||||
with:
|
with:
|
||||||
targets: ${{ inputs.target }}
|
targets: ${{ inputs.target }}
|
||||||
toolchain: ${{ inputs.toolchain }}
|
toolchain: ${{ inputs.toolchain }}
|
||||||
- name: Determine latest cross version
|
- name: Determine cross version
|
||||||
id: determine-latest-cross-version
|
id: determine-cross-version
|
||||||
shell: bash
|
shell: bash
|
||||||
run: determine-latest-cross-version.sh
|
run: determine-cross-version.sh "${{ inputs.cross-version }}"
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
|
||||||
if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'true' }}
|
if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'true' }}
|
||||||
@@ -66,11 +70,11 @@ runs:
|
|||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ${{ steps.set-cross-dir.outputs.cross-dir }}/cross
|
path: ${{ steps.set-cross-dir.outputs.cross-dir }}/cross
|
||||||
key: ${{ runner.os }}-${{ steps.determine-latest-cross-version.outputs.cross-version }}
|
key: ${{ runner.os }}-${{ steps.determine-cross-version.outputs.cross-version }}
|
||||||
if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'true' }}
|
if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'true' }}
|
||||||
- name: Install cross if cross-compiling (*nix)
|
- name: Install cross if cross-compiling (*nix)
|
||||||
shell: bash
|
shell: bash
|
||||||
run: install-cross-nix.sh ${{ steps.set-cross-dir.outputs.cross-dir }}
|
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' }}
|
if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'true' && steps.cache-cross.outputs.cache-hit != 'true' }}
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
|
||||||
|
|||||||
15
determine-cross-version.sh
Executable file
15
determine-cross-version.sh
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
set -o pipefail
|
||||||
|
|
||||||
|
VERSION=$1
|
||||||
|
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
JSON=$( curl \
|
||||||
|
--request GET \
|
||||||
|
--header "Authorization: Bearer $GITHUB_TOKEN" \
|
||||||
|
https://api.github.com/repos/cross-rs/cross/releases/latest )
|
||||||
|
VERSION=$( echo "$JSON" | jq -r ".tag_name")
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "cross-version=$VERSION" >> $GITHUB_OUTPUT
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
set -e
|
|
||||||
set -x
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
JSON=$( curl \
|
|
||||||
--request GET \
|
|
||||||
--header "Authorization: Bearer $GITHUB_TOKEN" \
|
|
||||||
https://api.github.com/repos/cross-rs/cross/releases/latest )
|
|
||||||
VERSION=$( echo "$JSON" | jq -r ".tag_name")
|
|
||||||
|
|
||||||
echo "cross-version=$VERSION" >> $GITHUB_OUTPUT
|
|
||||||
@@ -3,9 +3,16 @@ set -x
|
|||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
CROSS_DIR="$1"
|
CROSS_DIR="$1"
|
||||||
|
VERSION="$2"
|
||||||
|
|
||||||
|
VERSION_ARGS=""
|
||||||
|
if [ -n "$VERSION" ]; then
|
||||||
|
VERSION_ARGS="--tag $VERSION"
|
||||||
|
fi
|
||||||
|
|
||||||
cd "$CROSS_DIR"
|
cd "$CROSS_DIR"
|
||||||
export TARGET=.
|
export TARGET=.
|
||||||
curl --silent --location \
|
curl --silent --location \
|
||||||
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
|
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
|
||||||
sh
|
sh
|
||||||
./ubi --project cross-rs/cross --matching musl --in .
|
./ubi --project cross-rs/cross --matching musl --in . $VERSION_ARGS
|
||||||
|
|||||||
@@ -2,20 +2,29 @@ set -e
|
|||||||
set -x
|
set -x
|
||||||
|
|
||||||
TARGET=$1
|
TARGET=$1
|
||||||
stripped=""
|
did_strip=""
|
||||||
|
|
||||||
strip_binary () {
|
strip_binary () {
|
||||||
if [[ $( uname -s ) =~ "Darwin" ]]; then
|
if [[ $( uname -s ) =~ "Darwin" ]]; then
|
||||||
EXE=$( find "$1" -maxdepth 1 -type f -perm +111 )
|
stripped=$(
|
||||||
|
find "$1" -maxdepth 1 -type f -perm +111 | while read exe; do
|
||||||
|
strip "$exe"
|
||||||
|
echo "stripped $exe"
|
||||||
|
done
|
||||||
|
)
|
||||||
else
|
else
|
||||||
EXE=$( find "$1" -maxdepth 1 -type f -executable )
|
stripped=$(
|
||||||
|
find "$1" -maxdepth 1 -type f -executable | while read exe; do
|
||||||
|
strip "$exe"
|
||||||
|
echo "stripped $exe"
|
||||||
|
done
|
||||||
|
)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$EXE" ]; then
|
if [ -z "$stripped" ]; then
|
||||||
echo "Could not find a binary to strip in $1"
|
echo "Could not find any binaries to strip in $1"
|
||||||
else
|
else
|
||||||
strip "$EXE"
|
did_strip="true"
|
||||||
stripped="$EXE"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +36,7 @@ for type in debug release; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$stripped" ]; then
|
if [ -z "$did_strip" ]; then
|
||||||
echo "No binaries were stripped"
|
echo "No binaries were stripped"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -3,4 +3,14 @@ name = "test-project"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
# For testing it would be nice to create a binary with spaces in the name, but
|
||||||
|
# right now the `name` value must be a valid crate name, and there's no
|
||||||
|
# separate setting for the compiled executable's name. See
|
||||||
|
# https://github.com/rust-lang/cargo/issues/9778.
|
||||||
|
[[bin]]
|
||||||
|
name = "bin1"
|
||||||
|
path = "src/bin1.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "bin2"
|
||||||
|
path = "src/bin2.rs"
|
||||||
|
|||||||
11
test-project/src/bin2.rs
Normal file
11
test-project/src/bin2.rs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fn main() {
|
||||||
|
println!("Hello, world!");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
#[test]
|
||||||
|
fn test_something() {
|
||||||
|
assert_eq!(1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,20 +19,26 @@ use Test::More;
|
|||||||
sub main {
|
sub main {
|
||||||
my $target;
|
my $target;
|
||||||
my $expect_cross;
|
my $expect_cross;
|
||||||
|
my $expect_cross_version;
|
||||||
my $expect_file_re;
|
my $expect_file_re;
|
||||||
my $expect_stripped;
|
my $expect_stripped;
|
||||||
|
|
||||||
GetOptions(
|
GetOptions(
|
||||||
'target=s' => \$target,
|
'target=s' => \$target,
|
||||||
'expect-file-re=s' => \$expect_file_re,
|
'expect-file-re=s' => \$expect_file_re,
|
||||||
'expect-cross!' => \$expect_cross,
|
'expect-cross!' => \$expect_cross,
|
||||||
'expect-stripped!' => \$expect_stripped,
|
'expect-cross-version=s' => \$expect_cross_version,
|
||||||
|
'expect-stripped!' => \$expect_stripped,
|
||||||
);
|
);
|
||||||
|
|
||||||
check_cross( path( $ENV{RUNNER_TEMP} ), $expect_cross );
|
check_cross(
|
||||||
|
path( $ENV{RUNNER_TEMP} ), $expect_cross,
|
||||||
|
$expect_cross_version
|
||||||
|
);
|
||||||
|
|
||||||
for my $bin (
|
for my $bin (
|
||||||
path( qw( . target ), $target, qw( debug test-project ) ),
|
path( qw( . target ), $target, qw( debug bin1 ) ),
|
||||||
|
path( qw( . target ), $target, qw( debug bin2 ) ),
|
||||||
path( qw( . subcrate target ), $target, qw( debug subcrate ) )
|
path( qw( . subcrate target ), $target, qw( debug subcrate ) )
|
||||||
) {
|
) {
|
||||||
check_binary( $bin, $expect_file_re, $expect_stripped );
|
check_binary( $bin, $expect_file_re, $expect_stripped );
|
||||||
@@ -41,10 +47,17 @@ sub main {
|
|||||||
done_testing();
|
done_testing();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub check_cross ( $bin_dir, $expect_cross ) {
|
sub check_cross ( $bin_dir, $expect_cross, $expect_cross_version ) {
|
||||||
my $cross = $bin_dir->child('cross');
|
my $cross = $bin_dir->child('cross');
|
||||||
if ($expect_cross) {
|
if ($expect_cross) {
|
||||||
ok( $cross->is_file && -x $cross, 'found `cross` in $PATH' );
|
ok( $cross->is_file && -x $cross, 'found `cross` in $PATH' );
|
||||||
|
if ($expect_cross_version) {
|
||||||
|
my $version = capturex( $cross, '--version' );
|
||||||
|
like(
|
||||||
|
$version, qr/\Q$expect_cross_version/,
|
||||||
|
'cross version matches expected version'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ok( !$cross->exists, 'did not find `cross` in $PATH' );
|
ok( !$cross->exists, 'did not find `cross` in $PATH' );
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
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