image: "rustlang/rust:nightly"

stages:
    - build
    - test

before_script:
    - git submodule update --init --recursive
    - rustup toolchain add "$(cat rust-toolchain)"
    - rustup target add x86_64-unknown-redox --toolchain "$(cat rust-toolchain)"
    - rustup show      # Print version info for debugging

# Cache caused some issues with a header not being generated:
# cache:
#     untracked: true

build:linux:
    stage: build
    script:
        - make all

build:redox:
    stage: build
    variables:
        TARGET: x86_64-unknown-redox
    script:
        # Install x86_64-unknown-redox-gcc
        # This can't be in before_script because that overrides
        # the global before_script.
        - apt-get update -qq
        - apt-get install -qq tar
        - rm -rf prefix
        - mkdir prefix
        - wget -O - https://static.redox-os.org/toolchain/x86_64-unknown-redox/gcc-install.tar.gz |
          tar --extract --gzip --directory prefix

        # Main script
        - env PATH="${PWD}/prefix/bin:$PATH" make all

test:linux:
    stage: test
    dependencies:
        - build:linux
    script:
        - make test
        - cd tests && make verify

fmt:
    stage: test
    script:
        - rustup component add rustfmt-preview
        - ./fmt.sh -- --check
    allow_failure: true
