Dave Rolsky d788e00f15
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
Always pass "+toolchain" to cargo or cross
I don't think this was actually using the specified toolchain, at least not
when cross compiling.
2023-04-21 23:14:21 -05:00
2023-03-05 15:15:31 -06:00
2023-03-05 15:15:31 -06:00
2023-03-12 10:37:46 -04:00
2023-03-05 15:07:30 -06:00
2023-03-05 12:54:11 -06:00
2023-03-05 12:54:11 -06:00
2023-03-05 12:54:11 -06:00
2023-03-05 15:15:31 -06:00
2023-03-05 12:54:11 -06:00
2023-03-05 12:54:11 -06:00

GitHub Action to Cross Compile Rust Projects

This action lets you easily cross-compile Rust projects using cross.

Here's an example from the release workflow for my tool precious:

jobs:
  release:
    name: Release - ${{ matrix.platform.release_for }}
    strategy:
      matrix:
        platform:
          - release_for: FreeBSD-x86_64
            os: ubuntu-20.04
            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 ...

    runs-on: ${{ matrix.platform.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Build binary
        uses: houseabsolute/actions-rust-cross@v0
        with:
          command: ${{ matrix.platform.command }}
          target: ${{ matrix.platform.target }}
          args: "--locked --release"
          strip: true

    # more packaging stuff goes here ...

Input Parameters

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 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

Under the hood, this action will compile your binary with either cargo or cross, depending on the host machine and target. For Linux builds, it will always use cross except for builds targeting an x86 architecture like x86_64 or i686.

On Windows and macOS, it's possible to compile for all supported targets out of the box, so cross will not be used on those platforms.

If it needs to install cross, it will install the latest version by downloading a release using my tool ubi. This is much faster than using cargo to build cross.

When compiling on Windows, it will do so in a Powershell environment, which can matter in some corner cases, like compiling the openssl crate with the vendored feature.

Finally, it will run strip to strip the binary if the strip parameter is true. This is only possible for builds that are not done via cross. In addition, Windows builds for aarch64 cannot be stripped either.

Description
No description provided
Readme 320 KiB
Languages
Python 61.5%
Rust 24.4%
Shell 12.1%
Perl 2%