version: 2
jobs:
  air:
    docker:
      - image: circleci/rust:latest
    resource_class: medium+
    environment:
      RUST_BACKTRACE: 1
      RUST_TEST_THREADS: 1
    steps:
      - checkout
      - restore_cache:
          keys:
            - air01-{{ checksum "Cargo.lock" }}
      - run: |
          rustup toolchain install nightly-2022-03-20-x86_64-unknown-linux-gnu
          rustup default nightly-2022-03-20-x86_64-unknown-linux-gnu

          rustup target add wasm32-wasi
          rustup component add rustfmt
          rustup component add clippy

          cargo install --force marine

          # build a Wasm binary for interpreter
          (cd air-interpreter; marine build --features marine)

          # build Wasm binaries for tests
          (cd air/tests/test_module; ./build_test_binaries.sh)

          cargo fmt --all -- --check --color always
          cargo check
          cargo test --release
          cargo clippy -v

      - save_cache:
          paths:
            - ~/.cargo
            - ~/.rustup
          key: air01-{{ checksum "Cargo.lock" }}
workflows:
  version: 2
  air:
    jobs:
      - air