image: "redoxos/redoxer:latest"

variables:
  GIT_SUBMODULE_STRATEGY: recursive

stages:
    - build
    - test

default:
    cache:
        paths:
            - target/

build:linux:
    stage: build
    script:
        - rustup show      # Print version info for debugging
        - make -j "$(nproc)" all

build:redox:
    stage: build
    variables:
        TARGET: x86_64-unknown-redox
    script:
        - export RUSTUP_TOOLCHAIN="$HOME/.redoxer/toolchain"
        - export PATH="$RUSTUP_TOOLCHAIN/bin:$PATH"
        - rustup show      # Print version info for debugging
        - make -j "$(nproc)" all

test:linux:
    stage: test
    needs:
        - build:linux
    dependencies:
        - build:linux
    script:
        - make test

test:redox:
    stage: test
    needs:
        - build:redox
    dependencies:
        - build:redox
    variables:
        TARGET: x86_64-unknown-redox
    script:
        - export CARGO_TEST="redoxer"
        - export RUSTUP_TOOLCHAIN="$HOME/.redoxer/toolchain"
        - export PATH="$RUSTUP_TOOLCHAIN/bin:$PATH"
        - export TEST_RUNNER="redoxer exec --folder . -- sh --"
        - make test
    # TODO: Out of memory
    allow_failure: true

fmt:
    stage: test
    needs: []
    script:
        - rustup component add rustfmt-preview
        - ./fmt.sh -- --check
