From 834563dab55099cb2236db58c21359596313f08a Mon Sep 17 00:00:00 2001 From: Matthew Orris <--help> Date: Fri, 8 Mar 2024 09:50:15 -0700 Subject: [PATCH] feat: wip: bring rust-cross action into repo for experimentation --- .../workflows/common/rust-cross/action.yml | 123 ++++++++++++++++++ .github/workflows/verify-pr-commit.yml | 2 +- 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/common/rust-cross/action.yml diff --git a/.github/workflows/common/rust-cross/action.yml b/.github/workflows/common/rust-cross/action.yml new file mode 100644 index 0000000000..9522e2ac1a --- /dev/null +++ b/.github/workflows/common/rust-cross/action.yml @@ -0,0 +1,123 @@ +name: "Build Rust Projects with Cross" +author: "Dave Rolsky " +branding: + icon: home + color: gray-dark +description: | + Cross compile your Rust projects with cross (https://github.com/cross-rs/cross). +inputs: + working-directory: + description: The working directory for each step + default: "." + 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 working-directory variable. + default: ${{ github.token }} + args: + description: | + The arguments to be passed to cross or cargo when building, as a + space-separated string. + default: "" + strip: + description: Strip the compiled binary + default: false + cross-version: + description: | + The version of cross to use. If not specified, then the latest version + will be used. +runs: + using: composite + steps: + - name: Add this action's path to PATH + shell: bash + run: echo "${{ github.action_path }}" >> $GITHUB_PATH + - name: Determine whether we need to cross-compile + id: determine-cross-compile + shell: bash + run: set-cross-compile.sh ${{ inputs.target }} + - name: Install toolchain + shell: bash + # uses: dtolnay/rust-toolchain@master + # with: + # targets: ${{ inputs.target }} + # toolchain: ${{ inputs.toolchain }} + run: | + rustup toolchain install ${{ inputs.toolchain }} + rustup target add ${{ inputs.target }} + rustup default ${{ inputs.toolchain }} + - name: Determine cross version + id: determine-cross-version + shell: bash + run: determine-cross-version.sh "${{ inputs.cross-version }}" + env: + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} + if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'true' }} + # We need to accesss this in both this YAML config and shell scripts. It + # doesn't seem like using ${{ env.RUNNER_TEMP }} works in the YAML config. + - name: Set directory for installing cross + id: set-cross-dir + shell: bash + run: set-cross-dir.sh + if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'true' }} + - name: Cache cross + id: cache-cross + uses: actions/cache@v4 + with: + path: ${{ steps.set-cross-dir.outputs.cross-dir }}/cross + key: ${{ runner.os }}-${{ steps.determine-cross-version.outputs.cross-version }} + if: ${{ steps.determine-cross-compile.outputs.needs-cross == 'true' }} + - name: Install cross if cross-compiling (*nix) + shell: bash + 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' }} + env: + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} + - name: Set build command + id: set-build-command + shell: bash + run: set-build-command.sh ${{ steps.set-cross-dir.outputs.cross-dir }} + - name: Run tests (*nix) + working-directory: ${{ inputs.working-directory }} + shell: bash + run: | + ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} 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) + working-directory: ${{ inputs.working-directory }} + shell: powershell + run: | + & ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} test ${{ inputs.args }} --target ${{ inputs.target }} + if: ${{ inputs.command != 'build' && runner.os == 'Windows' }} + - name: Build binary (*nix) + working-directory: ${{ inputs.working-directory }} + shell: bash + run: | + ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} build ${{ inputs.args }} --target ${{ inputs.target }} + if: ${{ inputs.command != 'test' && runner.os != 'Windows' }} + - name: Build binary (Windows) + working-directory: ${{ inputs.working-directory }} + shell: powershell + run: | + & ${{ steps.set-build-command.outputs.build-command }} +${{inputs.toolchain}} build ${{ inputs.args }} --target ${{ inputs.target }} + if: ${{ inputs.command != 'test' && runner.os == 'Windows' }} + - name: Strip binary + working-directory: ${{ inputs.working-directory }} + shell: bash + run: strip-binary.sh ${{ inputs.target }} + # strip doesn't work with cross-arch binaries on Linux or Windows. + if: ${{ inputs.command != 'test' && inputs.strip == 'true' && steps.determine-cross-compile.outputs.needs-cross == 'false' && inputs.target != 'aarch64-pc-windows-msvc' }} diff --git a/.github/workflows/verify-pr-commit.yml b/.github/workflows/verify-pr-commit.yml index 8242e5bf31..46531de7c1 100644 --- a/.github/workflows/verify-pr-commit.yml +++ b/.github/workflows/verify-pr-commit.yml @@ -137,7 +137,7 @@ jobs: - run: echo "Cross Build ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }}" - uses: actions/checkout@v4 - name: Build Binary - uses: houseabsolute/actions-rust-cross@a0b2ccd63176060d61d875a04fabe94da5c75921 + uses: ./.github/workflows/common/rust-cross with: command: "build" target: ${{ matrix.platform.target }}