language: cpp

cache: ccache

env:
  global:
    - VERILATOR_CACHE=$HOME/verilator_cache
    - VERILATOR_ROOT=$PWD/verilator
    - VERILATOR_NUM_JOBS=$((`nproc` + 1))
    - OBJCACHE=ccache
    - PATH=$PATH:$VERILATOR_ROOT/bin
    - VERILATOR=$VERILATOR_ROOT/bin/verilator
    - RV_ROOT=$PWD

cache:
  directories:
    - $VERILATOR_CACHE

before_install:
  - git clone https://github.com/verilator/verilator.git $VERILATOR_ROOT
# This is the first revision with the build_verilator.sh script.
# Once a Verilator release captures this, it would be best to check out
# a release tag instead.
  - git -C $VERILATOR_ROOT checkout 46ab907f6afdcacbf848ea090dce66f1334de663

before_script:
  - $VERILATOR_ROOT/ci/build_verilator.sh

stages:
  - build
  - test

jobs:
  include:
    - stage: build
      name: Build Verilator
      script: echo "Done building Verilator"
    - stage: test
      name: Run Tests
      script:
        - configs/swerv.config -snapshot=mybuild
        - make -j 4 -f tools/Makefile verilator snapshot=mybuild
        - make -f tools/Makefile verilator-run snapshot=mybuild |& tee sim.log
        - grep -q "Hello World from SweRV" sim.log
