Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
play

GitHub Action

Setup toolchains for cross compilation and cross testing for Rust

v1.6.1

Setup toolchains for cross compilation and cross testing for Rust

play

Setup toolchains for cross compilation and cross testing for Rust

GitHub Action for setup toolchains for cross compilation and cross testing for Rust

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Setup toolchains for cross compilation and cross testing for Rust

uses: taiki-e/setup-cross-toolchain-action@v1.6.1

Learn more about this action in taiki-e/setup-cross-toolchain-action

Choose a version

setup-cross-toolchain-action

build status

GitHub Action for setup toolchains for cross compilation and cross testing for Rust.

Usage

Inputs

Name Required Description Type Default
target true Target triple String
runner false Test runner String

Example workflow: Basic usage

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Rust
        run: rustup update stable
      - name: Install cross-compilation tools
        uses: taiki-e/setup-cross-toolchain-action@v1
        with:
          target: aarch64-unknown-linux-gnu
      # setup-cross-toolchain-action sets the `CARGO_BUILD_TARGET` environment variable,
      # so there is no need for an explicit `--target` flag.
      - run: cargo test --verbose
      # `cargo run` also works.
      - run: cargo run --verbose
      # You can also run the cross-compiled binaries directly.
      - run: ./target/aarch64-unknown-linux-gnu/debug/my-app

Example workflow: Multiple targets

jobs:
  test:
    strategy:
      matrix:
        target:
          - aarch64-unknown-linux-gnu
          - riscv64gc-unknown-linux-gnu
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Rust
        run: rustup update stable
      - name: Install cross-compilation tools
        uses: taiki-e/setup-cross-toolchain-action@v1
        with:
          target: ${{ matrix.target }}
      - run: cargo test --verbose

Example workflow: Doctest

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Rust
        run: rustup update nightly && rustup default nightly
      - name: Install cross-compilation tools
        uses: taiki-e/setup-cross-toolchain-action@v1
        with:
          target: aarch64-unknown-linux-gnu
      - run: cargo test --verbose -Z doctest-xcompile

Cross-testing of doctest is currently available only on nightly. If you want to use stable and nightly in the same matrix, you can use the DOCTEST_XCOMPILE environment variable set by this action to enable doctest only in nightly.

jobs:
  test:
    strategy:
      matrix:
        rust:
          - stable
          - nightly
        target:
          - aarch64-unknown-linux-gnu
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Rust
        run: rustup update ${{ matrix.rust }} && rustup default ${{ matrix.rust }}
      - name: Install cross-compilation tools
        uses: taiki-e/setup-cross-toolchain-action@v1
        with:
          target: ${{ matrix.target }}
      # On nightly and `-Z doctest-xcompile` is available,
      # `$DOCTEST_XCOMPILE` is `-Zdoctest-xcompile`.
      #
      # On stable, `$DOCTEST_XCOMPILE` is not set.
      # Once `-Z doctest-xcompile` is stabilized, the corresponding flag
      # will be set to `$DOCTEST_XCOMPILE` (if it is available).
      - run: cargo test --verbose $DOCTEST_XCOMPILE

Platform Support

Linux (GNU)

C++ test
✓ (libstdc++)

Supported targets:

target host runner note
aarch64-unknown-linux-gnu Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
aarch64_be-unknown-linux-gnu Ubuntu ( 18.04, 22.04) [4] qemu-user (default) tier3
arm-unknown-linux-gnueabi Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
armv5te-unknown-linux-gnueabi Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
armv7-unknown-linux-gnueabi Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
armv7-unknown-linux-gnueabihf Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
i586-unknown-linux-gnu Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default), native
i686-unknown-linux-gnu Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) native (default), qemu-user
mips-unknown-linux-gnu Ubuntu ( 18.04 [2], 22.04 [3]) qemu-user (default)
mips64-unknown-linux-gnuabi64 Ubuntu ( 18.04 [2], 22.04 [3]) qemu-user (default)
mips64el-unknown-linux-gnuabi64 Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
mipsel-unknown-linux-gnu Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
mipsisa32r6-unknown-linux-gnu Ubuntu ( 22.04 [3]) qemu-user (default) [6] tier3
mipsisa32r6el-unknown-linux-gnu Ubuntu (20.04 [1], 22.04 [3]) qemu-user (default) [6] tier3
mipsisa64r6-unknown-linux-gnuabi64 Ubuntu ( 22.04 [3]) qemu-user (default) tier3
mipsisa64r6el-unknown-linux-gnuabi64 Ubuntu (20.04 [1], 22.04 [3]) qemu-user (default) tier3
powerpc-unknown-linux-gnu Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
powerpc64-unknown-linux-gnu Ubuntu ( 18.04 [2], 22.04 [3]) qemu-user (default)
powerpc64le-unknown-linux-gnu Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
riscv32gc-unknown-linux-gnu Ubuntu (20.04, 18.04, 22.04) [5] qemu-user (default)
riscv64gc-unknown-linux-gnu ubuntu (20.04 [1], 22.04 [3]) qemu-user (default)
s390x-unknown-linux-gnu Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
sparc64-unknown-linux-gnu Ubuntu ( 18.04 [2], 22.04 [3]) qemu-user (default)
thumbv7neon-unknown-linux-gnueabihf Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) qemu-user (default)
x86_64-unknown-linux-gnu Ubuntu (20.04 [1], 18.04 [2], 22.04 [3]) native (default), qemu-user

[1] GCC 9, glibc 2.31
[2] GCC 7, glibc 2.27
[3] GCC 11, glibc 2.35
[4] GCC 10, glibc 2.31
[5] GCC 11, glibc 2.33
[6] binfmt doesn't work

FreeBSD

C++ test
✓ (libc++)

Supported targets:

target version host note
i686-unknown-freebsd 12.3 Ubuntu (18.04 [1], 20.04 [2], 22.04 [2])
x86_64-unknown-freebsd 12.3 Ubuntu (18.04 [1], 20.04 [2], 22.04 [2])

[1] Clang 13
[2] Clang 15

Windows (GNU)

C++ test
✓ (libstdc++)

Supported targets:

target host runner note
x86_64-pc-windows-gnu Ubuntu (22.04 [2]) wine (default) [3]

[2] GCC 10, MinGW-w64 8
[3] binfmt doesn't work

The current default version of Wine is 7.13. You can select/pin the version by using runner input option. For example:

- uses: taiki-e/setup-cross-toolchain-action@v1
  with:
    target: x86_64-pc-windows-gnu
    runner: wine@7.13

WASI

C++ test
? (libc++)

Supported targets:

target host runner note
wasm32-wasi Ubuntu (20.04, 22.04) [1] wasmtime (default) [2]

[1] clang 14, wasi-sdk 16 (wasi-libc 30094b6)
[2] binfmt doesn't work

Related Projects

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.