name: 'Android: Cross-compile x86 libraries & copy to install dir'
inputs:
  arch:
    required: true
runs:
  using: composite
  steps:
    - shell: bash
      run: |
        set -eux
        cd ..

        arch='${{ inputs.arch }}'
        triple="$arch-${CROSS_TRIPLE#*-}"
        abi="$arch"
        if [[ "$arch" == i686 ]]; then
          abi=x86
        fi

        # convert CROSS_CMAKE_FLAGS to array, stripping all `-D` prefixes
        IFS=$'\n' flags=( $(xargs -n1 <<<"$CROSS_CMAKE_FLAGS" | cut -b3-) )

        # use bootstrap-ldc, which is guaranteed to be native
        bootstrap-ldc/bin/ldc-build-runtime --ninja \
          --buildDir="build-libs-$arch" \
          --dFlags="-mtriple=$triple;-fvisibility=hidden" \
          --ldcSrcDir="$PWD/ldc" \
          "${flags[@]}" \
          ANDROID_ABI="$abi" # override the one in CROSS_CMAKE_FLAGS

        mkdir "installed/lib-$arch"
        cp "build-libs-$arch"/lib/*.a "installed/lib-$arch/"
