parameters:
  interpreter: ''
  rustup: ''
  target: ''
  toolchain: ''

steps:
- script: |
    curl $(rustup) -o rustup-init.exe
    rustup-init.exe -y --default-host $(target) --default-toolchain $(toolchain)-$(target) --profile minimal
    set PATH=%PATH%;%USERPROFILE%\.cargo\bin
    rustup default $(toolchain)-$(target)
    rustup component add rust-src
    mkdir .cargo
    cp ci/config.toml .cargo/config.toml
    echo "##vso[task.setvariable variable=PATH;]%PATH%;%USERPROFILE%\.cargo\bin"
  displayName: rustup
- script: python.exe -m pip install --upgrade pip "maturin>=1,<2" wheel
  displayName: build dependencies
- script: python.exe -m pip install -r test\requirements.txt -r integration\requirements.txt
  displayName: test dependencies
- script: maturin.exe build --release --features=no-panic,unstable-simd,yyjson --strip --interpreter $(interpreter) --target $(target)
  displayName: build
  env:
    CFLAGS: "-Os -flto"
    LDFLAGS: "-Wl,--as-needed"
    RUSTFLAGS: "-C lto=fat -Z mir-opt-level=4 -Z virtual-function-elimination -D warnings"
    CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
    UNSAFE_PYO3_SKIP_VERSION_CHECK: "1"
- script: python.exe -m pip install orjson --no-index --find-links=D:\a\1\s\target\wheels
  displayName: install
- script: python.exe -m pytest -s -rxX -v test
  env:
    PYTHONMALLOC: "debug"
  displayName: pytest
- script: python.exe integration\thread
  displayName: thread
- script: python.exe integration\init
  displayName: init
- bash: ./ci/deploy /d/a/1/s/target/wheels/*.whl
  displayName: deploy
