diff --git a/.github/scripts/winarm64/bootstrap_buildtools.bat b/.github/scripts/winarm64/bootstrap_buildtools.bat new file mode 100644 index 0000000000..a7ced81f0d --- /dev/null +++ b/.github/scripts/winarm64/bootstrap_buildtools.bat @@ -0,0 +1,67 @@ +@echo off + +echo Dependency MSVC Build Tools with C++ with ARM64/ARM64EC components installation started. + +:: Pre-check for downloads and dependencies folders +if not exist "%DOWNLOADS_DIR%" mkdir "%DOWNLOADS_DIR%" +if not exist "%DEPENDENCIES_DIR%" mkdir "%DEPENDENCIES_DIR%" + +:: Set download URL for the Visual Studio Installer +set DOWNLOAD_URL=https://aka.ms/vs/17/release/vs_BuildTools.exe +set INSTALLER_FILE=%DOWNLOADS_DIR%\vs_BuildTools.exe + +:: Download installer +echo Downloading Visual Studio Build Tools with C++ installer... +curl -L -o "%INSTALLER_FILE%" %DOWNLOAD_URL% + +:: Install the Visual Studio Build Tools with C++ components +echo Installing Visual Studio Build Tools with C++ components... +echo Installing MSVC %MSVC_VERSION% +if "%MSVC_VERSION%" == "latest" ( + "%INSTALLER_FILE%" --norestart --quiet --wait --installPath "%DEPENDENCIES_DIR%\VSBuildTools" ^ + --add Microsoft.VisualStudio.Workload.VCTools ^ + --add Microsoft.VisualStudio.Component.Windows10SDK ^ + --add Microsoft.VisualStudio.Component.Windows11SDK.22621 ^ + --add Microsoft.VisualStudio.Component.VC.ASAN ^ + --add Microsoft.VisualStudio.Component.VC.CMake.Project ^ + --add Microsoft.VisualStudio.Component.VC.CoreBuildTools ^ + --add Microsoft.VisualStudio.Component.VC.CoreIde ^ + --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest ^ + --add Microsoft.VisualStudio.Component.VC.Tools.ARM64EC ^ + --add Microsoft.VisualStudio.Component.VC.Tools.ARM64 ^ + --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 +) else if "%MSVC_VERSION%" == "14.40" ( + "%INSTALLER_FILE%" --norestart --nocache --quiet --wait --fix --installPath "%DEPENDENCIES_DIR%\VSBuildTools" ^ + --add Microsoft.VisualStudio.Workload.VCTools ^ + --add Microsoft.VisualStudio.Component.Windows10SDK ^ + --add Microsoft.VisualStudio.Component.Windows11SDK.22621 ^ + --add Microsoft.VisualStudio.Component.VC.ASAN ^ + --add Microsoft.VisualStudio.Component.VC.CMake.Project ^ + --add Microsoft.VisualStudio.Component.VC.CoreBuildTools ^ + --add Microsoft.VisualStudio.Component.VC.CoreIde ^ + --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest ^ + --add Microsoft.VisualStudio.Component.VC.14.40.17.10.ARM64 ^ + --add Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64 +) else if "%MSVC_VERSION%" == "14.36" ( + "%INSTALLER_FILE%" --norestart --nocache --quiet --wait --fix --installPath "%DEPENDENCIES_DIR%\VSBuildTools" ^ + --add Microsoft.VisualStudio.Workload.VCTools ^ + --add Microsoft.VisualStudio.Component.Windows10SDK ^ + --add Microsoft.VisualStudio.Component.Windows11SDK.22621 ^ + --add Microsoft.VisualStudio.Component.VC.ASAN ^ + --add Microsoft.VisualStudio.Component.VC.CMake.Project ^ + --add Microsoft.VisualStudio.Component.VC.CoreBuildTools ^ + --add Microsoft.VisualStudio.Component.VC.CoreIde ^ + --add Microsoft.VisualStudio.Component.VC.Redist.14.Latest ^ + --add Microsoft.VisualStudio.Component.VC.14.36.17.6.ARM64 ^ + --add Microsoft.VisualStudio.Component.VC.14.36.17.6.x86.x64 +) + +echo exitcode = %errorlevel% + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo Failed to install Visual Studio Build Tools with C++ components. + exit /b 1 +) + +echo Dependency Visual Studio Build Tools with C++ installation finished. \ No newline at end of file diff --git a/.github/scripts/winarm64/bootstrap_git.bat b/.github/scripts/winarm64/bootstrap_git.bat new file mode 100644 index 0000000000..53743b167c --- /dev/null +++ b/.github/scripts/winarm64/bootstrap_git.bat @@ -0,0 +1,55 @@ +@echo off +setlocal enabledelayedexpansion + + +echo Dependency Git installation started. + + +:: Pre-check for downloads and dependencies folders +set "DOWNLOADS_DIR=c:\temp\downloads" +set "DEPENDENCIES_DIR=c:\temp\dependencies" + + +if not exist "%DOWNLOADS_DIR%" mkdir "%DOWNLOADS_DIR%" +if not exist "%DEPENDENCIES_DIR%" mkdir "%DEPENDENCIES_DIR%" + + +:: Set download URL for the Git +set "DOWNLOAD_URL=https://github.com/git-for-windows/git/releases/download/v2.48.1.windows.1/Git-2.48.1-arm64.exe" +set "INSTALLER_FILE=%DOWNLOADS_DIR%\Git-2.48.1-arm64.exe" + + +:: Download installer +echo Downloading Git... +curl -L -o "%INSTALLER_FILE%" "%DOWNLOAD_URL%" + + +:: Verify download success +if not exist "%INSTALLER_FILE%" ( + echo Failed to download Git! + exit /b 1 +) + + +:: Install Git +echo Installing Git... +"%INSTALLER_FILE%" /VERYSILENT /DIR="%DEPENDENCIES_DIR%\git" + + +:: Verify installation success +if %errorlevel% neq 0 ( + echo Failed to install Git. (exitcode = %errorlevel%) + exit /b 1 +) + + +:: Enable long paths +call "%DEPENDENCIES_DIR%\git\cmd\git.exe" config --system core.longpaths true + + +:: Add Git to PATH (temporary for this session) +set "PATH=%DEPENDENCIES_DIR%\git\cmd\;%DEPENDENCIES_DIR%\git\bin\;%PATH%" + + +echo Dependency Git installation finished. +exit /b 0 \ No newline at end of file diff --git a/.github/scripts/winarm64/bootstrap_python.bat b/.github/scripts/winarm64/bootstrap_python.bat new file mode 100644 index 0000000000..e8c76ff119 --- /dev/null +++ b/.github/scripts/winarm64/bootstrap_python.bat @@ -0,0 +1,47 @@ +@echo off + +echo Dependency Python installation started. + +:: Pre-check for downloads and dependencies folders +if not exist "%DOWNLOADS_DIR%" mkdir %DOWNLOADS_DIR% +if not exist "%DEPENDENCIES_DIR%" mkdir %DEPENDENCIES_DIR% + +echo PYTHON_VERSION is %PYTHON_VERSION% + +if "%PYTHON_VERSION%" == "3.13" ( + echo Python version is set to 3.13 + set DOWNLOAD_URL=https://www.python.org/ftp/python/3.13.2/python-3.13.2-arm64.exe +) +else if "%PYTHON_VERSION%" == "3.12" ( + echo Python version is set to 3.12 + set DOWNLOAD_URL=https://www.python.org/ftp/python/3.12.7/python-3.12.7-arm64.exe +) else if "%PYTHON_VERSION%" == "3.11" ( + echo Python version is set to 3.11 + set DOWNLOAD_URL=https://www.python.org/ftp/python/3.11.9/python-3.11.9-arm64.exe +) else ( + echo PYTHON_VERSION not defined, Python version is set to 3.12 + set DOWNLOAD_URL=https://www.python.org/ftp/python/3.12.7/python-3.12.7-arm64.exe +) + +set INSTALLER_FILE=%DOWNLOADS_DIR%\python-installer.exe + +:: Download installer +echo Downloading Python... +curl -L -o "%INSTALLER_FILE%" "%DOWNLOAD_URL%" + +:: Install Python +echo Installing Python... +"%INSTALLER_FILE%" /quiet Include_debug=1 TargetDir="%DEPENDENCIES_DIR%\Python" + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed to install Python. (exitcode = %errorlevel%)" + exit /b 1 +) + +:: Add to PATH +echo %DEPENDENCIES_DIR%\Python\>> %GITHUB_PATH% +echo %DEPENDENCIES_DIR%\Python\scripts\>> %GITHUB_PATH% +echo %DEPENDENCIES_DIR%\Python\libs\>> %GITHUB_PATH% + +echo Dependency Python installation finished. \ No newline at end of file diff --git a/.github/scripts/winarm64/build_audio.bat b/.github/scripts/winarm64/build_audio.bat new file mode 100644 index 0000000000..6bd997b61f --- /dev/null +++ b/.github/scripts/winarm64/build_audio.bat @@ -0,0 +1,57 @@ +@echo on +set SRC_PATH=%GITHUB_WORKSPACE%\%SRC_DIR% +set CMAKE_BUILD_TYPE=%BUILD_TYPE% +set VCVARSALL_PATH=%DEPENDENCIES_DIR%\VSBuildTools\VC\Auxiliary\Build\vcvarsall.bat +set CONDA_PREFIX=%DEPENDENCIES_DIR% +set PATH=%PATH%;%CONDA_PREFIX%\Library\bin +set DISTUTILS_USE_SDK=1 +set USE_FFMPEG=1 +set FFMPEG_ROOT=%DEPENDENCIES_DIR%\Library + +:: Dependencies +if not exist "%DOWNLOADS_DIR%" mkdir %DOWNLOADS_DIR% +if not exist "%DEPENDENCIES_DIR%" mkdir %DEPENDENCIES_DIR% +echo * > %DOWNLOADS_DIR%\.gitignore +echo * > %DEPENDENCIES_DIR%\.gitignore + +:: install vcpkg +cd %DOWNLOADS_DIR% +:: for ffmpeg 6.1.1 - pinning the version of vcpkg +:: https://pytorch.org/audio/stable/installation.html +git clone https://github.com/microsoft/vcpkg.git -b 2024.07.12 +cd vcpkg +call bootstrap-vcpkg.bat + +:: install dependencies +vcpkg install ffmpeg[ffmpeg]:arm64-windows --x-install-root=%DEPENDENCIES_DIR% +robocopy /E %DEPENDENCIES_DIR%\arm64-windows %DEPENDENCIES_DIR%\Library +robocopy /E %DEPENDENCIES_DIR%\Library\tools\ffmpeg %DEPENDENCIES_DIR%\Library\bin +robocopy /E %DEPENDENCIES_DIR%\Library\bin %SRC_PATH%\src\torio\lib + +:: test ffmpeg +echo %FFMPEG_ROOT% +ffmpeg -version + +:: Source directory +cd %SRC_PATH% + +:: Virtual environment +python -m pip install --upgrade pip +python -m venv .venv --upgrade-deps +echo * > .venv\.gitignore +call .\.venv\Scripts\activate + +:: Install dependencies +pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu + +:: Activate visual studio +call "%VCVARSALL_PATH%" arm64 + +:: Creates wheel under dist folder +python setup.py bdist_wheel + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed on build_audio. (exitcode = %errorlevel%)" + exit /b 1 +) \ No newline at end of file diff --git a/.github/scripts/winarm64/build_vision.bat b/.github/scripts/winarm64/build_vision.bat new file mode 100644 index 0000000000..cae7358bb0 --- /dev/null +++ b/.github/scripts/winarm64/build_vision.bat @@ -0,0 +1,60 @@ +@echo on +set SRC_PATH=%GITHUB_WORKSPACE%\%SRC_DIR% +set CMAKE_BUILD_TYPE=%BUILD_TYPE% +set VCVARSALL_PATH=%DEPENDENCIES_DIR%\VSBuildTools\VC\Auxiliary\Build\vcvarsall.bat +set CONDA_PREFIX=%DEPENDENCIES_DIR% +set PATH=%PATH%;%CONDA_PREFIX%\Library\bin +set DISTUTILS_USE_SDK=1 + +:: Dependencies +if not exist "%DOWNLOADS_DIR%" mkdir %DOWNLOADS_DIR% +if not exist "%DEPENDENCIES_DIR%" mkdir %DEPENDENCIES_DIR% +echo * > %DOWNLOADS_DIR%\.gitignore +echo * > %DEPENDENCIES_DIR%\.gitignore + +:: install vcpkg +cd %DOWNLOADS_DIR% +git clone https://github.com/microsoft/vcpkg.git +cd vcpkg +call bootstrap-vcpkg.bat + +:: install dependencies +vcpkg install libjpeg-turbo:arm64-windows --x-install-root=%DEPENDENCIES_DIR% +vcpkg install libwebp:arm64-windows --x-install-root=%DEPENDENCIES_DIR% +vcpkg install libpng[tools]:arm64-windows --x-install-root=%DEPENDENCIES_DIR% +:: https://pytorch.org/vision/stable/index.html +:: Building with FFMPEG is disabled by default in the latest main +:: vcpkg install ffmpeg[ffmpeg]:arm64-windows --x-install-root=%DEPENDENCIES_DIR% +copy %DEPENDENCIES_DIR%\arm64-windows\lib\libpng16.lib %DEPENDENCIES_DIR%\arm64-windows\lib\libpng.lib +copy %DEPENDENCIES_DIR%\arm64-windows\bin\libpng16.dll %DEPENDENCIES_DIR%\arm64-windows\bin\libpng.dll +copy %DEPENDENCIES_DIR%\arm64-windows\bin\libpng16.pdb %DEPENDENCIES_DIR%\arm64-windows\bin\libpng.pdb +robocopy /E %DEPENDENCIES_DIR%\arm64-windows %DEPENDENCIES_DIR%\Library +robocopy /E %DEPENDENCIES_DIR%\Library\tools\libpng %DEPENDENCIES_DIR%\Library\bin +robocopy /E %DEPENDENCIES_DIR%\Library\bin %SRC_PATH%\torchvision *.dll + +:: Source directory +cd %SRC_PATH% + +:: Virtual environment +python -m pip install --upgrade pip +python -m venv .venv --upgrade-deps +echo * > .venv\.gitignore +call .\.venv\Scripts\activate + +:: Install dependencies +pip install numpy +pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu + +exit /b 0 + +:: Activate visual studio +call "%VCVARSALL_PATH%" arm64 + +:: Creates wheel under dist folder +python setup.py bdist_wheel + +:: Check if installation was successful +if %errorlevel% neq 0 ( + echo "Failed on build_vision. (exitcode = %errorlevel%)" + exit /b 1 +) \ No newline at end of file diff --git a/.github/workflows/build_wheels_windows_arm64.yml b/.github/workflows/build_wheels_windows_arm64.yml new file mode 100644 index 0000000000..b029f6a147 --- /dev/null +++ b/.github/workflows/build_wheels_windows_arm64.yml @@ -0,0 +1,116 @@ +name: Build Windows Arm64 Wheels + +on: + workflow_call: + inputs: + python_version: + required: false + default: "Python312" + type: string + msvc_version: + required: false + default: "latest" + type: string + build_type: + required: false + default: "Release" + type: string + repository_name: + required: true + type: string + default: "pytorch/vision" + repository_branch: + required: true + type: string + default: "main" + build_version: + required: false + type: string + +env: + DOWNLOADS_DIR: c:\temp\downloads\ + DEPENDENCIES_DIR: c:\temp\dependencies\ + SCRIPTS_DIR: test-infra\\.github\\scripts\\winarm64 + SRC_DIR: src\\${{ inputs.repository_name }} + PYTHON_VERSION: ${{ inputs.python_version }} + MSVC_VERSION: ${{ inputs.msvc_version }} + BUILD_TYPE: ${{ inputs.build_type }} + BUILD_VERSION : ${{ inputs.build_version }} + +permissions: + id-token: write + contents: read + +jobs: + build: + runs-on: windows-11-arm64 + name: Build wheel + steps: + - name: Checkout test-infra repository + uses: actions/checkout@v4 + with: + repository: alinpahontu2912/test-infra + # TODO update once merged to main + ref: winarm64_wheels + path: test-infra + - name: Checkout Target Repository (${{ inputs.repository_name }}) + uses: actions/checkout@v4 + with: + repository: ${{ inputs.repository_name }} + ref: ${{ inputs.repository_branch }} + path: src/${{ inputs.repository_name }} + submodules: recursive + - name: Run Bootstrap Git Script + shell: bash + run: | + echo Running bootstrap_git.bat... + cmd //c "$SCRIPTS_DIR\\bootstrap_git.bat" + - name: Bootstrap Python + shell: bash + run: | + echo Running bootstrap_python.bat... + cmd //c "$SCRIPTS_DIR\\bootstrap_python.bat" + - name: Bootstrap Build Tools + shell: bash + run: | + echo Running bootstrap_buildtools.bat... + cmd //c "$SCRIPTS_DIR\\bootstrap_buildtools.bat" + - name: Call Build Script + shell: bash + run: | + repository_name=$(basename "${{ inputs.repository_name }}") + echo "$repository_name" + echo "SCRIPTS_DIR: $SCRIPTS_DIR" + ls -l "$SCRIPTS_DIR" || echo "SCRIPTS_DIR does not exist" + + echo "repository_name=$repository_name" >> "$GITHUB_ENV" + if [ "$repository_name" = "audio" ]; then + echo "Attempting to run: $SCRIPTS_DIR/build_audio.bat" + cmd //c "$SCRIPTS_DIR\\build_audio.bat" + if [ $? -eq 0 ]; then + echo "Done Building Torchaudio" + else + echo "Error: Build Torchaudio failed" + exit 1 + fi + elif [ "$repository_name" = "vision" ]; then + echo "Attempting to run: $SCRIPTS_DIR/build_vision.bat" + cmd //c "$SCRIPTS_DIR\\build_vision.bat" + if [ $? -eq 0 ]; then + echo "Done Building Torchvision" + else + echo "Error: Build Torchvision failed" + exit 1 + fi + else + echo "Invalid repository name: $repository_name" + exit 1 + fi + ls -l "$SRC_DIR" + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ env.repository_name }}-wheel + path: ${{ env.SRC_DIR }}\dist\* + compression-level: 0 + retention-days: 3 \ No newline at end of file