Skip to content

Build Windows CPU wheel #5

Build Windows CPU wheel

Build Windows CPU wheel #5

name: Build and test Windows from source
on:
pull_request:
push:
branches:
- nightly
- main
- release/*
tags:
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
cancel-in-progress: true
permissions:
id-token: write
contents: read
defaults:
run:
shell: bash -l -eo pipefail {0}
jobs:
build-and-test:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.9']
ffmpeg-version: ['4.4.2', '5.1.2', '6.1.1', '7.0.1']
steps:
- name: Check out repo
uses: actions/checkout@v3
- name: Setup conda env
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
miniconda-version: "latest"
activate-environment: build
python-version: ${{ matrix.python-version }}
- name: Install FFmpeg
run: |
# Install FFmpeg and try to get development packages
conda install "ffmpeg=${{ matrix.ffmpeg-version }}" -c conda-forge --quiet
ffmpeg -version
# On Windows, ensure the conda Library/bin directory is in PATH
# This is needed for both pkg-config to find FFmpeg and for DLL loading
conda_env_path=$(conda info --base)/envs/build
library_bin_path="$conda_env_path/Library/bin"
library_lib_path="$conda_env_path/Library/lib"
library_include_path="$conda_env_path/Library/include"
echo "Adding conda Library paths:"
echo " bin: $library_bin_path"
echo " lib: $library_lib_path"
echo " include: $library_include_path"
echo "$library_bin_path" >> $GITHUB_PATH
# Also add Library/lib/pkgconfig to PKG_CONFIG_PATH for cmake to find FFmpeg
pkg_config_path="$conda_env_path/Library/lib/pkgconfig"
echo "Adding to PKG_CONFIG_PATH: $pkg_config_path"
echo "PKG_CONFIG_PATH=$pkg_config_path" >> $GITHUB_ENV
# Set additional environment variables that CMake might need
echo "CMAKE_PREFIX_PATH=$conda_env_path/Library" >> $GITHUB_ENV
echo "LIBRARY_PATH=$library_lib_path" >> $GITHUB_ENV
echo "INCLUDE_PATH=$library_include_path" >> $GITHUB_ENV
# Add the Library/lib directory to the linker path for Visual Studio
echo "LIB=$library_lib_path;$LIB" >> $GITHUB_ENV
echo "LIBPATH=$library_lib_path;$LIBPATH" >> $GITHUB_ENV
# Verify FFmpeg DLLs are accessible
echo "Checking if FFmpeg DLLs are in PATH:"
where avutil.dll || echo "avutil.dll not found in PATH"
where avcodec.dll || echo "avcodec.dll not found in PATH"
where avformat.dll || echo "avformat.dll not found in PATH"
- name: Install build dependencies
run: |
# Install pkg-config and pybind11 which are needed for Windows builds
conda install -y pkg-config pybind11 -c conda-forge --quiet
# Try to install missing dependencies that FFmpeg might need
echo "Installing additional dependencies that might be missing..."
conda install -y harfbuzz freetype zlib bzip2 -c conda-forge --quiet || echo "Some dependencies might already be installed"
# Inspect what's actually in the Library directory
echo "Contents of Library/lib:"
ls -la "$CONDA_PREFIX/Library/lib/" | head -20
echo "Looking for harfbuzz files:"
find "$CONDA_PREFIX/Library/" -name "*harfbuzz*" 2>/dev/null || echo "No harfbuzz files found"
echo "Looking for freetype files:"
find "$CONDA_PREFIX/Library/" -name "*freetype*" 2>/dev/null || echo "No freetype files found"
# Check if the .lib files exist with the exact names pkg-config expects
conda_env_path=$(conda info --base)/envs/build
library_lib_path="$conda_env_path/Library/lib"
echo "Checking for specific .lib files in $library_lib_path:"
ls -la "$library_lib_path/harfbuzz.lib" 2>/dev/null || echo "harfbuzz.lib not found"
ls -la "$library_lib_path/freetype.lib" 2>/dev/null || echo "freetype.lib not found"
ls -la "$library_lib_path/"*harfbuzz* 2>/dev/null || echo "No harfbuzz files in lib"
ls -la "$library_lib_path/"*freetype* 2>/dev/null || echo "No freetype files in lib"
# Verify pkg-config can find FFmpeg
echo "Testing pkg-config for FFmpeg libraries:"
pkg-config --exists libavcodec && echo "libavcodec found" || echo "libavcodec NOT found"
pkg-config --exists libavformat && echo "libavformat found" || echo "libavformat NOT found"
pkg-config --exists libavutil && echo "libavutil found" || echo "libavutil NOT found"
# Show what libraries pkg-config thinks we need
echo "pkg-config --libs libavcodec:"
pkg-config --libs libavcodec || true
echo "pkg-config --libs libavformat:"
pkg-config --libs libavformat || true
echo "pkg-config --libs libavutil:"
pkg-config --libs libavutil || true
echo "pkg-config --libs libswscale:"
pkg-config --libs libswscale || true
echo "pkg-config --libs libswresample:"
pkg-config --libs libswresample || true
echo "pkg-config --libs libavfilter:"
pkg-config --libs libavfilter || true
echo "pkg-config --libs libavdevice:"
pkg-config --libs libavdevice || true
- name: Update pip and install PyTorch
run: |
python -m pip install --upgrade pip
python -m pip install --pre torch --index-url https://download.pytorch.org/whl/nightly/cpu
- name: Create Windows build script
run: |
# Create a build script that sets up the VS environment and runs the build
cat > build_with_vs.bat << 'EOF'
@echo off
:: Get conda environment info
for /f "tokens=*" %%i in ('conda info --base') do set CONDA_BASE=%%i
set CONDA_ENV_PATH=%CONDA_BASE%\envs\build
set LIBRARY_LIB_PATH=%CONDA_ENV_PATH%\Library\lib
set LIBRARY_BIN_PATH=%CONDA_ENV_PATH%\Library\bin
set LIBRARY_INCLUDE_PATH=%CONDA_ENV_PATH%\Library\include
:: Add conda Library/bin to PATH for DLL loading
set PATH=%LIBRARY_BIN_PATH%;%PATH%
:: Set PKG_CONFIG_PATH
set PKG_CONFIG_PATH=%CONDA_ENV_PATH%\Library\lib\pkgconfig
:: Set additional paths for the linker
set LIB=%LIBRARY_LIB_PATH%;%LIB%
set LIBPATH=%LIBRARY_LIB_PATH%;%LIBPATH%
set INCLUDE=%LIBRARY_INCLUDE_PATH%;%INCLUDE%
:: Set CMAKE_ARGS with more comprehensive settings
set CMAKE_ARGS=-DCMAKE_BUILD_TYPE=Release -DTORCHCODEC_DISABLE_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_LIBRARY_PATH=%LIBRARY_LIB_PATH% -DCMAKE_INCLUDE_PATH=%LIBRARY_INCLUDE_PATH% -DCMAKE_PREFIX_PATH=%LIBRARY_LIB_PATH%;%LIBRARY_INCLUDE_PATH% -DCMAKE_VERBOSE_MAKEFILE=ON
echo Building with CMAKE_ARGS: %CMAKE_ARGS%
echo LIB path: %LIB%
echo PKG_CONFIG_PATH: %PKG_CONFIG_PATH%
echo PATH (first few entries):
echo %PATH% | cut -d; -f1-3
:: Debug: Show what libraries are available
echo Available .lib files in conda lib directory:
dir "%LIBRARY_LIB_PATH%\*.lib" 2>nul || echo No .lib files found
:: Debug: Test pkg-config within the script
echo Testing pkg-config from within build script:
pkg-config --exists libavcodec && echo libavcodec found || echo libavcodec NOT found
:: Use vc_env_helper.bat to set up VS environment and build
call packaging\vc_env_helper.bat python -m pip install -e . --no-build-isolation -v
EOF
- name: Verify Visual Studio environment and build
shell: cmd
run: |
echo Checking Visual Studio installation...
call packaging\vc_env_helper.bat echo Visual Studio environment setup complete
echo Running build with Visual Studio environment...
call build_with_vs.bat
- name: Test torchcodec import
run: |
echo "Testing torchcodec import..."
python -c "import torchcodec; print('TorchCodec import successful!')"
python -c "import torchcodec; print('FFmpeg versions:', torchcodec.get_ffmpeg_library_versions())"
- name: Install test dependencies
run: |
python -m pip install numpy pytest pillow
- name: Run Python tests
run: |
pytest test -v