build-wheel-windows.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. #!/usr/bin/env bash
  2. set -euxo pipefail
  3. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)"
  4. WORKSPACE_DIR="${ROOT_DIR}/.."
  5. PY_VERSIONS=("3.9" "3.10" "3.11" "3.12")
  6. bazel_preclean() {
  7. "${WORKSPACE_DIR}"/ci/run/bazel.py preclean "mnemonic(\"Genrule\", deps(//:*))"
  8. }
  9. get_python_version() {
  10. python -s -c "import sys; sys.stdout.write('%s.%s' % sys.version_info[:2])"
  11. }
  12. is_python_version() {
  13. local expected result=0
  14. expected="$1"
  15. case "$(get_python_version).0." in
  16. "${expected}".*) ;;
  17. *) result=1;;
  18. esac
  19. case "$(pip --version | tr -d "\r")" in
  20. *" (python ${expected})") ;;
  21. *) result=1;;
  22. esac
  23. return "${result}"
  24. }
  25. refreshenv() {
  26. # https://gist.github.com/jayvdb/1daf8c60e20d64024f51ec333f5ce806
  27. powershell -NonInteractive - <<\EOF
  28. Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
  29. Update-SessionEnvironment
  30. # Print out the list of env vars we're going to export.
  31. # Sometimes the bash source fails, this will help with debugging.
  32. gci env:
  33. # Round brackets in variable names cause problems with bash
  34. Get-ChildItem env:* | %{
  35. if (!($_.Name.Contains('('))) {
  36. $value = $_.Value
  37. if ($_.Name -eq 'PATH') {
  38. $value = $value -replace ';',':'
  39. }
  40. # Use heredocs to wrap values. This fixes problems with environment variables containing single quotes.
  41. # An environment variable containing the string REFRESHENV_EOF could still cause problems, but is
  42. # far less likely than a single quote.
  43. Write-Output ("export " + $_.Name + "=$`(cat <<- 'REFRESHENV_EOF'`n" + $value + "`nREFRESHENV_EOF`)")
  44. }
  45. } | Out-File -Encoding ascii $env:TEMP\refreshenv.sh
  46. EOF
  47. source "$TEMP/refreshenv.sh"
  48. }
  49. install_ray() {
  50. # TODO(mehrdadn): This function should be unified with the one in ci/ci.sh.
  51. (
  52. pip install wheel
  53. pushd python/ray/dashboard/client
  54. choco install nodejs -y
  55. refreshenv
  56. # https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported
  57. export NODE_OPTIONS=--openssl-legacy-provider
  58. npm install
  59. npm run build
  60. popd
  61. cd "${WORKSPACE_DIR}"/python
  62. "${WORKSPACE_DIR}"/ci/keep_alive pip install -v -e .
  63. )
  64. }
  65. uninstall_ray() {
  66. pip uninstall -y ray
  67. python -s -c "import runpy, sys; runpy.run_path(sys.argv.pop(), run_name='__api__')" clean "${ROOT_DIR}"/setup.py
  68. }
  69. build_wheel_windows() {
  70. local ray_uninstall_status=0
  71. uninstall_ray || ray_uninstall_status=1
  72. local local_dir="python/dist"
  73. {
  74. echo "build --announce_rc";
  75. echo "build --config=ci";
  76. echo "startup --output_user_root=c:/raytmp";
  77. echo "build --remote_cache=${BUILDKITE_BAZEL_CACHE_URL}";
  78. } >> ~/.bazelrc
  79. if [[ "${BUILDKITE_PIPELINE_ID:-}" == "0189942e-0876-4b8f-80a4-617f988ec59b" || "${BUILDKITE_CACHE_READONLY:-}" == "true" ]]; then
  80. # Do not upload cache results for premerge pipeline
  81. echo "build --remote_upload_local_results=false" >> ~/.bazelrc
  82. fi
  83. for pyversion in "${PY_VERSIONS[@]}"; do
  84. if [[ "${BUILD_ONE_PYTHON_ONLY:-}" != "" && "${pyversion}" != "${BUILD_ONE_PYTHON_ONLY}" ]]; then
  85. continue
  86. fi
  87. bazel_preclean
  88. git clean -q -f -f -x -d -e "${local_dir}" -e python/ray/dashboard/client
  89. git checkout -q -f -- .
  90. # Start a subshell to prevent PATH and cd from affecting our shell environment
  91. (
  92. if ! is_python_version "${pyversion}"; then
  93. conda install -y conda=24.1.2 python="${pyversion}"
  94. fi
  95. if ! is_python_version "${pyversion}"; then
  96. echo "Expected pip for Python ${pyversion} but found Python $(get_python_version) with $(pip --version); exiting..." 1>&2
  97. exit 1
  98. fi
  99. unset PYTHON2_BIN_PATH PYTHON3_BIN_PATH # make sure these aren't set by some chance
  100. install_ray
  101. cd "${WORKSPACE_DIR}"/python
  102. # Set the commit SHA in _version.py.
  103. if [ -n "$BUILDKITE_COMMIT" ]; then
  104. sed -i.bak "s/{{RAY_COMMIT_SHA}}/$BUILDKITE_COMMIT/g" ray/_version.py && rm ray/_version.py.bak
  105. else
  106. echo "BUILDKITE_COMMIT variable not set - required to populated ray.__commit__."
  107. exit 1
  108. fi
  109. # build ray wheel
  110. python setup.py --quiet bdist_wheel
  111. # build ray-cpp wheel
  112. RAY_INSTALL_CPP=1 python setup.py --quiet bdist_wheel
  113. uninstall_ray
  114. )
  115. done
  116. bazel_preclean
  117. if [ 0 -eq "${ray_uninstall_status}" ]; then # If Ray was previously installed, restore it
  118. install_ray
  119. fi
  120. }
  121. build_wheel_windows "$@"