14 Commits

Author SHA1 Message Date
Dave Rolsky
91d78d9182 Use dtolnay/rust-toolchain@master instead of @stable
Some checks failed
Self-test / Test (map[can_test:false expect_cross:false expect_file:Aarch64.+Windows expect_stripped:false os:windows-latest platform_name:Windows-aarch64 target:aarch64-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:false expect_file:Mach-O.+arm64 expect_stripped:true os:macOS-latest platform_name:macOS-aarch64 target:aarch64-apple-darwin]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:true expect_file:x86-64.+FreeBSD expect_stripped:false os:ubuntu-20.04 platform_name:FreeBSD-x86_64 target:x86_64-unknown-freebsd]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:true expect_file:x86-64.+NetBSD expect_stripped:false os:ubuntu-20.04 platform_name:NetBSD-x86_64 target:x86_64-unknown-netbsd]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:80386.+Windows expect_stripped:true os:windows-latest platform_name:Windows-i686 target:i686-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:ELF.+80386 expect_stripped:true os:ubuntu-20.04 platform_name:Linux-i586 target:i586-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:ELF.+x86-64 expect_stripped:true os:ubuntu-20.04 platform_name:Linux-x86_64 target:x86_64-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:Mach-O.+x86_64 expect_stripped:true os:macOS-latest platform_name:macOS-x86_64 target:x86_64-apple-darwin]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:x86-64.+Windows expect_stripped:true os:windows-latest platform_name:Windows-x86_64 target:x86_64-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:32.+ARM expect_stripped:false os:ubuntu-20.04 platform_name:Linux-arm target:arm-unknown-linux-musleabi]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:32.+PowerPC expect_stripped:false os:ubuntu-20.04 platform_name:Linux-powerpc target:powerpc-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+PowerPC expect_stripped:false os:ubuntu-20.04 platform_name:Linux-powerpc64 target:powerpc64-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+PowerPC expect_stripped:false os:ubuntu-20.04 platform_name:Linux-powerpc64le target:powerpc64le-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+RISC-V expect_stripped:false os:ubuntu-20.04 platform_name:Linux-riscv64 target:riscv64gc-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+S/390 expect_stripped:false os:ubuntu-20.04 platform_name:Linux-s390x target:s390x-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS32.+mips- expect_stripped:false os:ubuntu-20.04 platform_name:Linux-mips target:mips-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS32.+mipsel- expect_stripped:false os:ubuntu-20.04 platform_name:Linux-mipsel target:mipsel-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS64 expect_stripped:false os:ubuntu-20.04 platform_name:Linux-mips64 target:mips64-unknown-linux-muslabi64]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS64 expect_stripped:false os:ubuntu-20.04 platform_name:Linux-mips64el target:mips64el-unknown-linux-muslabi64]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:aarch64 expect_stripped:false os:ubuntu-20.04 platform_name:Linux-aarch64 target:aarch64-unknown-linux-musl]) (push) Has been cancelled
This allows passing the `toolchain` input.
2023-03-20 12:18:06 -04:00
Dave Rolsky
30e7adeceb Add toolchain input to README.md docs 2023-03-19 17:43:22 -04:00
Dave Rolsky
ec63efbd36 Changes for 0.0.4
Some checks failed
Self-test / Test (map[can_test:false expect_cross:false expect_file:Aarch64.+Windows expect_stripped:false os:windows-latest platform_name:Windows-aarch64 target:aarch64-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:false expect_file:Mach-O.+arm64 expect_stripped:true os:macOS-latest platform_name:macOS-aarch64 target:aarch64-apple-darwin]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:true expect_file:x86-64.+FreeBSD expect_stripped:false os:ubuntu-20.04 platform_name:FreeBSD-x86_64 target:x86_64-unknown-freebsd]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:true expect_file:x86-64.+NetBSD expect_stripped:false os:ubuntu-20.04 platform_name:NetBSD-x86_64 target:x86_64-unknown-netbsd]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:80386.+Windows expect_stripped:true os:windows-latest platform_name:Windows-i686 target:i686-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:ELF.+80386 expect_stripped:true os:ubuntu-20.04 platform_name:Linux-i586 target:i586-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:ELF.+x86-64 expect_stripped:true os:ubuntu-20.04 platform_name:Linux-x86_64 target:x86_64-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:Mach-O.+x86_64 expect_stripped:true os:macOS-latest platform_name:macOS-x86_64 target:x86_64-apple-darwin]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:x86-64.+Windows expect_stripped:true os:windows-latest platform_name:Windows-x86_64 target:x86_64-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:32.+ARM expect_stripped:false os:ubuntu-20.04 platform_name:Linux-arm target:arm-unknown-linux-musleabi]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:32.+PowerPC expect_stripped:false os:ubuntu-20.04 platform_name:Linux-powerpc target:powerpc-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+PowerPC expect_stripped:false os:ubuntu-20.04 platform_name:Linux-powerpc64 target:powerpc64-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+PowerPC expect_stripped:false os:ubuntu-20.04 platform_name:Linux-powerpc64le target:powerpc64le-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+RISC-V expect_stripped:false os:ubuntu-20.04 platform_name:Linux-riscv64 target:riscv64gc-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+S/390 expect_stripped:false os:ubuntu-20.04 platform_name:Linux-s390x target:s390x-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS32.+mips- expect_stripped:false os:ubuntu-20.04 platform_name:Linux-mips target:mips-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS32.+mipsel- expect_stripped:false os:ubuntu-20.04 platform_name:Linux-mipsel target:mipsel-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS64 expect_stripped:false os:ubuntu-20.04 platform_name:Linux-mips64 target:mips64-unknown-linux-muslabi64]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS64 expect_stripped:false os:ubuntu-20.04 platform_name:Linux-mips64el target:mips64el-unknown-linux-muslabi64]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:aarch64 expect_stripped:false os:ubuntu-20.04 platform_name:Linux-aarch64 target:aarch64-unknown-linux-musl]) (push) Has been cancelled
2023-03-19 17:41:41 -04:00
Dave Rolsky
54e4a464ed Remove tests that $PATH is left alone
This test isn't really needed, and it's causing spurious CI failures because
it's hitting GitHub API rate limits.
2023-03-19 17:41:41 -04:00
Dave Rolsky
d1d76ade32 Fix stripping and test it 2023-03-19 17:41:41 -04:00
Dave Rolsky
2bfd2f169a Fix target to use the input, not a matrix 2023-03-19 11:03:24 -04:00
Dave Rolsky
42a1f46405 Add support for specifying which toolchain to use 2023-03-19 11:03:05 -04:00
Dave Rolsky
58c5e42ace Pass GITHUB_TOKEN in self-test workflow 2023-03-17 11:17:02 -04:00
Dave Rolsky
2f68f636e2 Add support for running test command as well as build
Some checks failed
Self-test / Test (map[can_test:false expect_cross:false expect_file:Aarch64.+Windows os:windows-latest platform_name:Windows-aarch64 target:aarch64-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:false expect_file:Mach-O.+arm64 os:macOS-latest platform_name:macOS-aarch64 target:aarch64-apple-darwin]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:true expect_file:x86-64.+FreeBSD os:ubuntu-20.04 platform_name:FreeBSD-x86_64 target:x86_64-unknown-freebsd]) (push) Has been cancelled
Self-test / Test (map[can_test:false expect_cross:true expect_file:x86-64.+NetBSD os:ubuntu-20.04 platform_name:NetBSD-x86_64 target:x86_64-unknown-netbsd]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:80386.+Windows os:windows-latest platform_name:Windows-i686 target:i686-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:ELF.+80386 os:ubuntu-20.04 platform_name:Linux-i586 target:i586-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:ELF.+x86-64 os:ubuntu-20.04 platform_name:Linux-x86_64 target:x86_64-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:Mach-O.+x86_64 os:macOS-latest platform_name:macOS-x86_64 target:x86_64-apple-darwin]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:false expect_file:x86-64.+Windows os:windows-latest platform_name:Windows-x86_64 target:x86_64-pc-windows-msvc]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:32.+ARM os:ubuntu-20.04 platform_name:Linux-arm target:arm-unknown-linux-musleabi]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:32.+PowerPC os:ubuntu-20.04 platform_name:Linux-powerpc target:powerpc-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+PowerPC os:ubuntu-20.04 platform_name:Linux-powerpc64 target:powerpc64-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+PowerPC os:ubuntu-20.04 platform_name:Linux-powerpc64le target:powerpc64le-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+RISC-V os:ubuntu-20.04 platform_name:Linux-riscv64 target:riscv64gc-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:64.+S/390 os:ubuntu-20.04 platform_name:Linux-s390x target:s390x-unknown-linux-gnu]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS32.+mips- os:ubuntu-20.04 platform_name:Linux-mips target:mips-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS32.+mipsel- os:ubuntu-20.04 platform_name:Linux-mipsel target:mipsel-unknown-linux-musl]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS64 os:ubuntu-20.04 platform_name:Linux-mips64 target:mips64-unknown-linux-muslabi64]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:MIPS64 os:ubuntu-20.04 platform_name:Linux-mips64el target:mips64el-unknown-linux-muslabi64]) (push) Has been cancelled
Self-test / Test (map[can_test:true expect_cross:true expect_file:aarch64 os:ubuntu-20.04 platform_name:Linux-aarch64 target:aarch64-unknown-linux-musl]) (push) Has been cancelled
2023-03-17 11:12:36 -04:00
Dave Rolsky
5bd32448aa Add self-test workflow 2023-03-12 18:30:36 -04:00
Dave Rolsky
4dfe96e52b Add Rust project for self-testing 2023-03-12 10:37:46 -04:00
Dave Rolsky
9a602122c2 Changes for v0.0.2 2023-03-05 15:16:31 -06:00
Dave Rolsky
b34ced72c6 Add dev tooling to use precious 2023-03-05 15:15:31 -06:00
Dave Rolsky
aa7ccd3cba Fix typos in README.md 2023-03-05 15:15:22 -06:00
14 changed files with 494 additions and 17 deletions

207
.github/workflows/test.yml vendored Normal file
View 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 }}"

6
.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
/node_modules
/package-lock.json
/package.json
.\#*
\#*\#
test-project/target/**

View File

@@ -1,3 +1,27 @@
## 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.
## 0.0.1 - 2023-03-05
* First release upon an unsuspecting world.
- First release upon an unsuspecting world.

View File

@@ -3,7 +3,7 @@
This action lets you easily cross-compile Rust projects using
[cross](https://github.com/cross-rs/cross).
Here's an example from the release workflor for
Here's an example from the release workflow for
[my tool `precious`](https://github.com/houseabsolute/precious):
```yaml
@@ -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 the `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

View File

@@ -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' }}

43
dev/bin/install-dev-tools.sh Executable file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
set -eo pipefail
function run () {
echo $1
eval $1
}
function install_tools () {
curl --silent --location \
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
sh
run "rustup component add clippy"
run "ubi --project houseabsolute/precious --in ~/bin"
run "npm install prettier"
}
if [ "$1" == "-v" ]; then
set -x
fi
mkdir -p $HOME/bin
set +e
echo ":$PATH:" | grep --extended-regexp ":$HOME/bin:" >& /dev/null
if [ "$?" -eq "0" ]; then
path_has_home_bin=1
fi
set -e
if [ -z "$path_has_home_bin" ]; then
PATH=$HOME/bin:$PATH
fi
install_tools
echo "Tools were installed into $HOME/bin."
if [ -z "$path_has_home_bin" ]; then
echo "You should add $HOME/bin to your PATH."
fi
exit 0

15
git/hooks/pre-commit.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash
status=0
PRECIOUS=$(which precious)
if [[ -z $PRECIOUS ]]; then
PRECIOUS=./bin/precious
fi
"$PRECIOUS" lint -s
if (( $? != 0 )); then
status+=1
fi
exit $status

26
git/setup.pl Executable file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Cwd qw( abs_path );
symlink_hook('pre-commit');
sub symlink_hook {
my $hook = shift;
my $dot = ".git/hooks/$hook";
my $file = "git/hooks/$hook.sh";
my $link = "../../$file";
if ( -e $dot ) {
if ( -l $dot ) {
return if readlink $dot eq $link;
}
warn "You already have a hook at $dot!\n";
return;
}
symlink $link, $dot;
}

26
precious.toml Normal file
View File

@@ -0,0 +1,26 @@
exclude = [
"target",
]
[commands.prettier]
type = "both"
include = [ "**/*.md", "**/*.yml" ]
cmd = [ "./node_modules/.bin/prettier", "--no-config" ]
lint_flags = "--check"
tidy_flags = "--write"
ok_exit_codes = 0
lint_failure_exit_codes = 1
ignore_stderr = [ "Code style issues" ]
[commands.omegasort-gitignore]
type = "both"
include = "**/.gitignore"
cmd = [ "omegasort", "--sort", "path", "--unique" ]
lint_flags = "--check"
tidy_flags = "--in-place"
ok_exit_codes = 0
lint_failure_exit_codes = 1
ignore_stderr = [
"The .+ file is not sorted",
"The .+ file is not unique",
]

33
strip-binary.sh Executable file
View 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
View 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
View File

@@ -0,0 +1,6 @@
[package]
name = "test-project"
version = "0.1.0"
edition = "2021"
[dependencies]

11
test-project/src/main.rs Normal file
View 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
View 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