name: Build

on:
  push:
    branches:
      - master
      - plugins
  pull_request: {}

jobs:
  # typical build with various feature combinations
  build:
    name: Build
    runs-on: ${{ matrix.os }}
    continue-on-error: ${{ matrix.experimental }}
    strategy:
      matrix:
        os: [ubuntu-latest]
        flags:
          - ""
          - "--features metadata,serde,internals"
          - "--features unchecked"
          - "--features sync"
          - "--features no_position"
          - "--features no_optimize"
          - "--features no_float"
          - "--features f32_float,serde,metadata,internals"
          - "--features decimal"
          - "--features no_float,decimal"
          - "--tests --features only_i32,serde,metadata,internals"
          - "--features only_i64"
          - "--features no_index"
          - "--features no_object"
          - "--features no_function"
          - "--features no_module"
          - "--features no_closure"
          - "--features unicode-xid-ident"
          - "--features sync,no_function,no_float,no_position,no_optimize,no_module,no_closure,metadata,serde,unchecked"
          - "--features no_function,no_float,no_position,no_index,no_object,no_optimize,no_module,no_closure,unchecked"
        toolchain: [stable]
        experimental: [false]
        include:
          # smoketests for future and experimental toolchains
          - {toolchain: stable, os: windows-latest, experimental: false, flags: ""}
          - {toolchain: stable, os: macos-latest, experimental: false, flags: ""}
          - {toolchain: beta, os: ubuntu-latest, experimental: false, flags: ""}
          - {toolchain: nightly, os: ubuntu-latest, experimental: true, flags: ""}
      fail-fast: false
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Setup Toolchain
      uses: actions-rs/toolchain@v1
      with:
        toolchain: ${{matrix.toolchain}}
        override: true
    - name: Test
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: ${{matrix.flags}}
  # no-std builds are a bit more extensive to test
  no_std_build:
    name: NoStdBuild
    runs-on: ${{matrix.os}}
    continue-on-error: ${{matrix.experimental}}
    strategy:
      matrix:
        include:
          - {os: ubuntu-latest, flags: "--profile unix -Z unstable-options", experimental: false}
          - {os: windows-latest, flags: "--profile windows -Z unstable-options", experimental: true}
          - {os: macos-latest, flags: "--profile macos -Z unstable-options", experimental: false}
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Setup Toolchain
      uses: actions-rs/toolchain@v1
      with:
        toolchain: nightly
        override: true
    - name: Build Project
      uses: actions-rs/cargo@v1
      with:
        command: build
        args: --manifest-path=no_std/no_std_test/Cargo.toml ${{matrix.flags}}
  rustfmt:
    name: Check Formatting
    runs-on: windows-latest
    continue-on-error: true
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Setup Toolchain
      uses: actions-rs/toolchain@v1
      with:
        toolchain: nightly
        override: true
        components: rustfmt, clippy
    - name: Run Rustfmt
      uses: actions-rs/cargo@v1
      with:
        command: fmt
        args: --all -- --check
    - name: Run Clippy
      uses: actions-rs/cargo@v1
      with:
        command: clippy
        args: --all -- -Aclippy::all -Dclippy::perf
  codegen_build:
    name: Codegen Build
    runs-on: ${{matrix.os}}
    continue-on-error: ${{matrix.experimental}}
    strategy:
      matrix:
        include:
          - {toolchain: nightly, os: ubuntu-latest, experimental: false, flags: "--features metadata"}
          - {toolchain: nightly, os: windows-latest, experimental: false, flags: "--features metadata"}
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Setup Toolchain
      uses: actions-rs/toolchain@v1
      with:
        toolchain: ${{matrix.toolchain}}
        override: true
    - name: Build Project
      uses: actions-rs/cargo@v1
      with:
        command: test
        args: --manifest-path=codegen/Cargo.toml ${{matrix.flags}}