pessimize 3.0.2

More efficient Rust compiler optimization barriers
Documentation
name: 'Check lints'
description: 'Make sure the code emits no clippy and rustc lints'
inputs:
  toolchain:
    description: 'Rust toolchain to be used'
    default: 'stable'
  cargo-flags:
    description: 'Extra cargo flags, for enabling/disabling cargo features'
    default: ''
  rust-flags:
    description: 'Extra rustc flags, for enabling/disabling target features'
    default: ''
  cross-target-apt:
    description: 'For cross-compilation, set this to the target name used in ubuntu APT repositories and also set cross-target-rust'
    default: ''
  cross-target-rust:
    description: 'For cross-compilation, set this to the target name used in rustup and also set cross-target-apt'
    default: ''
runs:
  using: "composite"
  steps:
    - name: Set up Rust compilation flags
      shell: bash
      run: |
        echo RUSTFLAGS="-D warnings ${{ inputs.rust-flags }}" >> $GITHUB_ENV

        CARGO_FLAGS="--workspace ${{ inputs.cargo-flags }}"
        if [[ "${{ inputs.toolchain }}" == 'nightly' ]]; then
          CARGO_FLAGS="${CARGO_FLAGS} --features=nightly"
        fi
        if [[ -n "${{ inputs.cross-target-rust }}" ]]; then
          CARGO_FLAGS="${CARGO_FLAGS} --target=${{ inputs.cross-target-rust }}"
        else
          # HACK: This does hardcode the target to be linux with glibc, but we
          #       need that to ensure that cargo does not apply RUSTFLAGS when
          #       compiling the build.rs of dependencies.
          #
          #       Will be able to replace this once cargo's
          #       target-applies-to-host feature becomes stabilized.
          CARGO_FLAGS="${CARGO_FLAGS} --target=x86_64-unknown-linux-gnu"
        fi
        echo CARGO_FLAGS="${CARGO_FLAGS}" >> $GITHUB_ENV

    - name: Install a cross-compiler using APT
      if: inputs.cross-target-apt != ''
      uses: Eeems-Org/apt-cache-action@v1
      with:
        packages: gcc-12-${{ inputs.cross-target-apt }}

    - name: Set up a Rust toolchain for native compilation
      if: inputs.cross-target-rust == ''
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        toolchain: ${{ inputs.toolchain }}
        components: clippy

    - name: Set up a Rust toolchain for cross-compilation
      if: inputs.cross-target-rust != ''
      uses: actions-rust-lang/setup-rust-toolchain@v1
      with:
        toolchain: ${{ inputs.toolchain }}
        target: ${{ inputs.cross-target-rust }}
        components: clippy

    - name: Configure Cargo to use the cross-compiler as a linker
      if: inputs.cross-target-apt != '' && inputs.cross-target-rust != ''
      shell: bash
      run: |
        echo "[target.${{ inputs.cross-target-rust }}]" > ~/.cargo/config.toml
        echo "linker = \"/usr/bin/${{ inputs.cross-target-apt }}-gcc-12\"" >> ~/.cargo/config.toml

    - name: Check clippy lints
      shell: bash
      run: |
        cargo clippy ${CARGO_FLAGS} --all-targets -- -D warnings

    - name: Build docs
      shell: bash
      run: cargo doc ${CARGO_FLAGS}