name: Build LDC & LDC D unittests & defaultlib unittest runners
inputs:
  cmake_flags:
    required: false
    default: ''
  arch:
    required: false # Windows only
  with_pgo:
    required: false
    default: false
runs:
  using: composite
  steps:

    - name: 'Posix: Build mimalloc'
      if: runner.os != 'Windows'
      uses: ./.github/actions/helper-mimalloc

    - name: Build LDC & LDC D unittests & defaultlib unittest runners
      uses: ./.github/actions/helper-build-ldc
      with:
        build_dir: build
        host_dc: ../bootstrap-ldc/bin/ldmd2
        specify_install_dir: true
        cmake_flags: >-
          ${{ runner.os != 'Windows' && '-DALTERNATIVE_MALLOC_O="$PWD/../build-mimalloc/CMakeFiles/mimalloc-obj.dir/src/static.c.o"' || '' }}
          ${{ inputs.cmake_flags }}
          ${{ inputs.with_pgo == 'true' && '-DDFLAGS_LDC=-fprofile-use=../pgo-ldc/merged.profdata' || '' }}
        build_targets: all ldc2-unittest all-test-runners
        arch: ${{ inputs.arch }}

    - run: ../build/bin/ldc2 --version
      shell: bash
