xref: /aosp_15_r20/external/pytorch/.ci/pytorch/win-build.sh (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1#!/bin/bash
2
3# If you want to rebuild, run this with REBUILD=1
4# If you want to build with CUDA, run this with USE_CUDA=1
5# If you want to build without CUDA, run this with USE_CUDA=0
6
7if [ ! -f setup.py ]; then
8  echo "ERROR: Please run this build script from PyTorch root directory."
9  exit 1
10fi
11
12SCRIPT_PARENT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
13# shellcheck source=./common.sh
14source "$SCRIPT_PARENT_DIR/common.sh"
15# shellcheck source=./common-build.sh
16source "$SCRIPT_PARENT_DIR/common-build.sh"
17
18export TMP_DIR="${PWD}/build/win_tmp"
19TMP_DIR_WIN=$(cygpath -w "${TMP_DIR}")
20export TMP_DIR_WIN
21export PYTORCH_FINAL_PACKAGE_DIR=${PYTORCH_FINAL_PACKAGE_DIR:-/c/w/build-results}
22if [[ -n "$PYTORCH_FINAL_PACKAGE_DIR" ]]; then
23    mkdir -p "$PYTORCH_FINAL_PACKAGE_DIR" || true
24fi
25
26export SCRIPT_HELPERS_DIR=$SCRIPT_PARENT_DIR/win-test-helpers
27
28set +ex
29grep -E -R 'PyLong_(From|As)(Unsigned|)Long\(' --exclude=python_numbers.h --exclude=eval_frame.c torch/
30PYLONG_API_CHECK=$?
31if [[ $PYLONG_API_CHECK == 0 ]]; then
32  echo "Usage of PyLong_{From,As}{Unsigned}Long API may lead to overflow errors on Windows"
33  echo "because \`sizeof(long) == 4\` and \`sizeof(unsigned long) == 4\`."
34  echo "Please include \"torch/csrc/utils/python_numbers.h\" and use the correspoding APIs instead."
35  echo "PyLong_FromLong -> THPUtils_packInt32 / THPUtils_packInt64"
36  echo "PyLong_AsLong -> THPUtils_unpackInt (32-bit) / THPUtils_unpackLong (64-bit)"
37  echo "PyLong_FromUnsignedLong -> THPUtils_packUInt32 / THPUtils_packUInt64"
38  echo "PyLong_AsUnsignedLong -> THPUtils_unpackUInt32 / THPUtils_unpackUInt64"
39  exit 1
40fi
41set -ex
42
43"$SCRIPT_HELPERS_DIR"/build_pytorch.bat
44
45assert_git_not_dirty
46
47echo "BUILD PASSED"
48