Convert build_windows_packages to powershell. (#14643)

Bash scripts work fine on Windows... if you have your environment
configured for them (e.g. using https://cmder.app/ and/or Git BASH).
Powershell scripts run more natively, some many developers who work
primarily on Windows prefer them.

Tested on CI here:
https://github.com/openxla/iree/actions/runs/5836756202. I also tested
this a bit locally, but something about my Python install is broken
(errors linking nanobind) so I can't fully verify it.

skip-ci: not tested on presubmit
diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.yml
index b078063..dc3f5e2 100644
--- a/.github/workflows/build_package.yml
+++ b/.github/workflows/build_package.yml
@@ -171,14 +171,13 @@
 
       - name: Build runtime wheels (Windows)
         if: "matrix.build-package == 'py-runtime-pkg' && matrix.build-family == 'windows'"
-        shell: bash
+        shell: powershell
         env:
           package_suffix: ${{ github.event.inputs.package_suffix }}
           packages: "iree-runtime"
           output_dir: "${{ github.workspace }}/bindist"
           override_python_versions: "3.11"
-        run: |
-          ./c/build_tools/python_deploy/build_windows_packages.sh
+        run: ./c/build_tools/python_deploy/build_windows_packages.ps1
 
       ##########################################################################
       # py-compiler-pkg
@@ -208,14 +207,13 @@
 
       - name: Build compiler wheels (Windows)
         if: "matrix.build-package == 'py-compiler-pkg' && matrix.build-family == 'windows'"
-        shell: bash
+        shell: powershell
         env:
           package_suffix: ${{ github.event.inputs.package_suffix }}
           packages: "iree-compiler"
           output_dir: "${{ github.workspace }}/bindist"
           override_python_versions: "3.11"
-        run: |
-          ./c/build_tools/python_deploy/build_windows_packages.sh
+        run: ./c/build_tools/python_deploy/build_windows_packages.ps1
 
       ##########################################################################
       # TF Compiler Tools
diff --git a/build_tools/python_deploy/build_windows_packages.ps1 b/build_tools/python_deploy/build_windows_packages.ps1
new file mode 100644
index 0000000..43906f8
--- /dev/null
+++ b/build_tools/python_deploy/build_windows_packages.ps1
@@ -0,0 +1,91 @@
+# Copyright 2023 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+# One stop build of IREE Python packages for Windows. This presumes that
+# dependencies are installed from install_windows_deps.ps1.
+
+# Configure settings with script parameters.
+param(
+    [array]$python_versions=@("3.11"),
+    [array]$packages=@("iree-runtime", "iree-compiler"),
+    [System.String]$output_dir
+)
+
+# Also allow setting parameters via environment variables.
+if ($env:override_python_versions) { $python_versions = $env:override_python_versions -split ' '};
+if ($env:packages) { $packages = $env:packages -split ' '};
+if ($env:output_dir) { $output_dir = $env:output_dir };
+# Default output directory requires evaluating an expression.
+if (!$output_dir) { $output_dir = "${PSScriptRoot}\wheelhouse" };
+
+$repo_root = resolve-path "${PSScriptRoot}\..\.."
+
+# Canonicalize paths.
+md -Force ${output_dir} | Out-Null
+$output_dir = resolve-path "${output_dir}"
+
+function run() {
+  Write-Host "Using Python versions: ${python_versions}"
+
+  $installed_versions_output = py --list | Out-String
+
+  # Build phase.
+  for($i=0 ; $i -lt $packages.Length; $i++) {
+    $package = $packages[$i]
+
+    echo "******************** BUILDING PACKAGE ${package} ********************"
+    for($j=0 ; $j -lt $python_versions.Length; $j++) {
+      $python_version = $python_versions[$j]
+
+      if (!("${installed_versions_output}" -like "*${python_version}*")) {
+        Write-Host "ERROR: Could not find python version: ${python_version}"
+        continue
+      }
+
+      Write-Host ":::: Version: $(py -${python_version} --version)"
+      switch ($package) {
+          "iree-runtime" {
+            clean_wheels iree_runtime $python_version
+            build_iree_runtime $python_version
+          }
+          "iree-compiler" {
+            clean_wheels iree_compiler $python_version
+            build_iree_compiler $python_version
+          }
+          Default {
+            Write-Host "Unrecognized package '$package'"
+            exit 1
+          }
+      }
+    }
+  }
+}
+
+function build_iree_runtime() {
+  param($python_version)
+  $env:IREE_HAL_DRIVER_VULKAN = "ON"
+  & py -${python_version} -m pip wheel -v -w $output_dir $repo_root/runtime/
+}
+
+function build_iree_compiler() {
+  param($python_version)
+  py -${python_version} -m pip wheel -v -w $output_dir $repo_root/compiler/
+}
+
+function clean_wheels() {
+  param($wheel_basename, $python_version)
+  Write-Host ":::: Clean wheels $wheel_basename $python_version"
+
+  # python_version is something like "3.11", but we'd want something like "cp311".
+  $python_version_parts = $python_version.Split(".")
+  $python_version_major = $python_version_parts[0]
+  $python_version_minor = $python_version_parts[1]
+  $cpython_version_string = "cp${python_version_major}${python_version_minor}"
+
+  Get-ChildItem ${output_dir} | Where{$_.Name -Match "${wheel_basename}-.*-${cpython_version_string}-.*.whl"} | Remove-Item
+}
+
+run
diff --git a/build_tools/python_deploy/build_windows_packages.sh b/build_tools/python_deploy/build_windows_packages.sh
deleted file mode 100644
index 7b27e33..0000000
--- a/build_tools/python_deploy/build_windows_packages.sh
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-# Copyright 2023 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-# build_windows_packages.sh
-# One stop build of IREE Python packages for Windows. This presumes that
-# dependencies are installed from install_windows_deps.ps1.
-#
-# Valid packages:
-#   iree-runtime
-#   iree-compiler
-
-set -eu -o errtrace
-
-this_dir="$(cd $(dirname $0) && pwd)"
-repo_root="$(cd $this_dir/../../ && pwd)"
-python_versions="${override_python_versions:-3.11}"
-output_dir="${output_dir:-${this_dir}/wheelhouse}"
-packages="${packages:-iree-runtime iree-compiler}"
-
-# Canonicalize paths.
-mkdir -p "$output_dir"
-output_dir="$(cd $output_dir && pwd)"
-
-function run() {
-  echo "Using python versions: ${python_versions}"
-
-  local orig_path="$PATH"
-
-  # Build phase.
-  for package in $packages; do
-    echo "******************** BUILDING PACKAGE ${package} ********************"
-    for python_version in $python_versions; do
-      if [[ $(py --list) != *${python_version}* ]]; then
-        echo "ERROR: Could not find python version: ${python_version}"
-        continue
-      fi
-
-      echo ":::: Version: $(py -${python_version} --version)"
-      case "$package" in
-        iree-runtime)
-          clean_wheels iree_runtime $python_version
-          build_iree_runtime $python_version
-          ;;
-        iree-compiler)
-          clean_wheels iree_compiler $python_version
-          build_iree_compiler $python_version
-          ;;
-        *)
-          echo "Unrecognized package '$package'"
-          exit 1
-          ;;
-      esac
-    done
-  done
-
-  echo "******************** BUILD COMPLETE ********************"
-  echo "Generated binaries:"
-  ls -l $output_dir
-}
-
-function build_iree_runtime() {
-  local python_version="$1"
-  export IREE_RUNTIME_BUILD_TRACY=ON
-  IREE_HAL_DRIVER_VULKAN=ON \
-  py -${python_version} -m pip wheel -v -w $output_dir $repo_root/runtime/
-}
-
-function build_iree_compiler() {
-  local python_version="$1"
-  py -${python_version} -m pip wheel -v -w $output_dir $repo_root/compiler/
-}
-
-function clean_wheels() {
-  local wheel_basename="$1"
-  local python_version="$2"
-  echo ":::: Clean wheels $wheel_basename $python_version"
-  # python_version is something like "3.11", but we'd want something like "cp311".
-  local cpython_version_string="cp${python_version%.*}${python_version#*.}"
-  rm -f -v ${output_dir}/${wheel_basename}-*-${cpython_version_string}-*.whl
-}
-
-run