distributable:
  url: https://github.com/Z3Prover/z3/archive/z3-{{version}}.tar.gz
  strip-components: 1

versions:
  github: Z3Prover/z3
  strip: /z3-/

build:
  dependencies:
    cmake.org: ^3
    python.org: '>=3<3.12'
  working-directory: build
  script: |
    cmake .. $ARGS
    make --jobs {{hw.concurrency}} install
  env:
    ARGS:
      - -DZ3_LINK_TIME_OPTIMIZATION=ON
      - -DZ3_INCLUDE_GIT_DESCRIBE=OFF
      - -DZ3_INCLUDE_GIT_HASH=OFF
      - -DZ3_INSTALL_PYTHON_BINDINGS=ON
      - -DZ3_BUILD_EXECUTABLE=ON
      - -DZ3_BUILD_TEST_EXECUTABLES=OFF
      - -DZ3_BUILD_PYTHON_BINDINGS=ON
      - -DZ3_BUILD_DOTNET_BINDINGS=OFF
      - -DZ3_BUILD_JAVA_BINDINGS=OFF
      - -DZ3_USE_LIB_GMP=OFF
      - -DCMAKE_INSTALL_PREFIX={{prefix}}
      - -DCMAKE_BUILD_TYPE=Release
      - -DCMAKE_INSTALL_PYTHON_PKG_DIR={{prefix}}/lib/python

runtime:
  env:
    PYTHONPATH: ${{prefix}}/lib/python

provides:
  - bin/z3

test:
  dependencies:
    gnu.org/wget: '*'
    python.org: ~3.11
  script: |
    wget https://raw.githubusercontent.com/Z3Prover/z3/master/examples/c/test_capi.c
    cc -lz3 test_capi.c

    # FIXME: this fails on ubuntu-latest
    # BUG: incorrect use of Z3.
    # Error code: 12
    test "{{hw.platform}}+{{hw.arch}}" != "linux+x86-64" &&
    ./a.out

    # FIXME: this fails on linux-aarch64, for some reason
    # /tmp/ffb7372b/xyz.tea.test.sh: line 27: 55494 Aborted \
    #    python -c 'import z3; print(z3.get_version_string())'
    if "{{hw.platform}}+{{hw.arch}}" != "linux+aarch"; then
      v="$(python -c 'import z3; print(z3.get_version_string())')"
      test "$v" = {{version}}
    fi