Skip to content

Fix Test wheels step for WIndows #24

Fix Test wheels step for WIndows

Fix Test wheels step for WIndows #24

Workflow file for this run

name: Build Wheels
on:
push:
branches: [main]
tags:
- 'v*'
pull_request:
branches: [main]
workflow_dispatch:
workflow_call:
jobs:
build-dawn-linux:
name: Build Dawn (Linux)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Show environment
run: |
echo "Linux version:"
uname -a
cat /etc/os-release
echo "Available disk space:"
df -h
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y cmake ninja-build libx11-dev libx11-xcb-dev libxcb1-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
- name: Clone Dawn
run: |
git clone --depth 1 https://dawn.googlesource.com/dawn
echo "Dawn cloned successfully"
- name: Configure Dawn
run: |
cd dawn
mkdir -p out/Release
cmake -S . -B out/Release \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/dawn-install \
-DBUILD_SHARED_LIBS=OFF \
-DDAWN_BUILD_MONOLITHIC_LIBRARY=SHARED \
-DDAWN_FETCH_DEPENDENCIES=ON \
-DDAWN_ENABLE_D3D11=OFF \
-DDAWN_ENABLE_D3D12=OFF \
-DDAWN_ENABLE_NULL=OFF \
-DDAWN_ENABLE_DESKTOP_GL=OFF \
-DDAWN_ENABLE_OPENGLES=OFF \
-DDAWN_BUILD_SAMPLES=OFF \
-DTINT_BUILD_TESTS=OFF \
-DTINT_BUILD_CMD_TOOLS=OFF
echo "CMake configure completed"
- name: Build Dawn
run: |
cd dawn
cmake --build out/Release --target webgpu_dawn -j$(nproc)
echo "Build completed"
- name: Find and install library
run: |
echo "=== Searching for library ==="
find dawn -name "libwebgpu_dawn*" 2>/dev/null || echo "No library found"
echo "=== Contents of dawn/out/Release/src/dawn/native ==="
ls -la dawn/out/Release/src/dawn/native/ 2>/dev/null || echo "Directory not found"
mkdir -p dawn-install/lib dawn-install/include
# Copy the shared library (.so on Linux)
if [ -f "dawn/out/Release/src/dawn/native/libwebgpu_dawn.so" ]; then
cp dawn/out/Release/src/dawn/native/libwebgpu_dawn.so dawn-install/lib/
echo "Copied .so from src/dawn/native/"
else
echo "ERROR: libwebgpu_dawn.so not found"
echo "=== All libraries in out/Release ==="
find dawn/out/Release -name "libwebgpu_dawn*" 2>/dev/null
exit 1
fi
# Copy headers
cp -r dawn/include/webgpu dawn-install/include/ 2>/dev/null || true
cp -r dawn/include/dawn dawn-install/include/ 2>/dev/null || true
cp -r dawn/out/Release/gen/include/dawn dawn-install/include/ 2>/dev/null || true
cp -r dawn/out/Release/gen/include/webgpu dawn-install/include/ 2>/dev/null || true
- name: Verify installation
run: |
echo "=== dawn-install contents ==="
find dawn-install -type f
echo "=== Library check ==="
ls -la dawn-install/lib/
file dawn-install/lib/libwebgpu_dawn.so
- name: Upload Dawn artifact
uses: actions/upload-artifact@v4
with:
name: dawn-linux-x86_64
path: dawn-install
retention-days: 7
build-dawn-macos:
name: Build Dawn (macOS)
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Show environment
run: |
echo "macOS version:"
sw_vers
echo "Xcode version:"
xcodebuild -version
echo "Available disk space:"
df -h
- name: Install dependencies
run: |
brew install cmake ninja
- name: Clone Dawn
run: |
git clone --depth 1 https://dawn.googlesource.com/dawn
echo "Dawn cloned successfully"
- name: Configure Dawn
run: |
cd dawn
mkdir -p out/Release
cmake -S . -B out/Release \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/dawn-install \
-DBUILD_SHARED_LIBS=OFF \
-DDAWN_BUILD_MONOLITHIC_LIBRARY=SHARED \
-DDAWN_FETCH_DEPENDENCIES=ON \
-DDAWN_ENABLE_D3D11=OFF \
-DDAWN_ENABLE_D3D12=OFF \
-DDAWN_ENABLE_NULL=OFF \
-DDAWN_ENABLE_DESKTOP_GL=OFF \
-DDAWN_ENABLE_OPENGLES=OFF \
-DDAWN_BUILD_SAMPLES=OFF \
-DTINT_BUILD_TESTS=OFF \
-DTINT_BUILD_CMD_TOOLS=OFF
echo "CMake configure completed"
- name: Build Dawn
run: |
cd dawn
cmake --build out/Release --target webgpu_dawn -j$(sysctl -n hw.ncpu)
echo "Build completed"
- name: Find and install library
run: |
echo "=== Searching for library ==="
find dawn -name "libwebgpu_dawn*" 2>/dev/null || echo "No library found"
echo "=== Contents of dawn/out/Release/src/dawn/native ==="
ls -la dawn/out/Release/src/dawn/native/ 2>/dev/null || echo "Directory not found"
mkdir -p dawn-install/lib dawn-install/include
# Copy the shared library (dylib on macOS)
if [ -f "dawn/out/Release/src/dawn/native/libwebgpu_dawn.dylib" ]; then
cp dawn/out/Release/src/dawn/native/libwebgpu_dawn.dylib dawn-install/lib/
echo "Copied dylib from src/dawn/native/"
else
echo "ERROR: libwebgpu_dawn.dylib not found"
echo "=== All libraries in out/Release ==="
find dawn/out/Release -name "libwebgpu_dawn*" 2>/dev/null
exit 1
fi
# Copy headers
cp -r dawn/include/webgpu dawn-install/include/ 2>/dev/null || true
cp -r dawn/include/dawn dawn-install/include/ 2>/dev/null || true
cp -r dawn/out/Release/gen/include/dawn dawn-install/include/ 2>/dev/null || true
cp -r dawn/out/Release/gen/include/webgpu dawn-install/include/ 2>/dev/null || true
- name: Verify installation
run: |
echo "=== dawn-install contents ==="
find dawn-install -type f
echo "=== Library check ==="
ls -la dawn-install/lib/
file dawn-install/lib/libwebgpu_dawn.dylib
- name: Upload Dawn artifact
uses: actions/upload-artifact@v4
with:
name: dawn-macos-arm64
path: dawn-install
retention-days: 7
build-dawn-windows:
name: Build Dawn (Windows)
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Cache Dawn
id: cache-dawn
uses: actions/cache@v4
with:
path: dawn-install
key: dawn-v5-windows-x86_64-${{ hashFiles('scripts/build-dawn.sh') }}
- name: Check if cache is valid
id: check-cache
shell: bash
run: |
if [ -f "dawn-install/lib/webgpu_dawn.dll" ]; then
echo "valid=true" >> $GITHUB_OUTPUT
else
echo "valid=false" >> $GITHUB_OUTPUT
fi
- name: Setup MSVC
if: steps.check-cache.outputs.valid != 'true'
uses: ilammy/msvc-dev-cmd@v1
- name: Install dependencies
if: steps.check-cache.outputs.valid != 'true'
run: |
choco install cmake ninja git -y
- name: Build Dawn
if: steps.check-cache.outputs.valid != 'true'
shell: bash
run: |
rm -rf dawn-install dawn
chmod +x scripts/build-dawn.sh
./scripts/build-dawn.sh dawn-install
- name: Verify build
shell: bash
run: |
ls -la dawn-install/lib/
test -f dawn-install/lib/webgpu_dawn.dll
test -f dawn-install/lib/webgpu_dawn.lib
- name: Upload Dawn artifact
uses: actions/upload-artifact@v4
with:
name: dawn-windows-x86_64
path: dawn-install
retention-days: 7
build-wheels-linux:
name: Build wheels (Linux)
needs: build-dawn-linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download Dawn
uses: actions/download-artifact@v4
with:
name: dawn-linux-x86_64
path: dawn-install
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install patchelf
run: |
sudo apt-get update
sudo apt-get install -y patchelf
- name: Install build dependencies
run: |
pip install build wheel numpy
pip install --index-url https://download.pytorch.org/whl/cpu --extra-index-url https://pypi.org/simple torch
- name: Build wheel
env:
DAWN_PREFIX: ${{ github.workspace }}/dawn-install
ARCHFLAGS: "-arch arm64"
run: |
pip wheel . --no-deps --no-build-isolation -w dist/
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-linux-x86_64
path: dist/*.whl
retention-days: 30
build-wheels-macos:
name: Build wheels (macOS)
needs: build-dawn-macos
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Download Dawn
uses: actions/download-artifact@v4
with:
name: dawn-macos-arm64
path: dawn-install
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install build dependencies
run: |
pip install build wheel torch numpy
- name: Build wheel
env:
DAWN_PREFIX: ${{ github.workspace }}/dawn-install
DISTUTILS_USE_SDK: "1"
run: |
pip wheel . --no-deps --no-build-isolation -w dist/
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-macos-arm64
path: dist/*.whl
retention-days: 30
build-wheels-windows:
name: Build wheels (Windows)
needs: build-dawn-windows
runs-on: windows-latest
env:
DISTUTILS_USE_SDK: "1"
USE_NINJA: "0"
steps:
- uses: actions/checkout@v4
- name: Download Dawn
uses: actions/download-artifact@v4
with:
name: dawn-windows-x86_64
path: dawn-install
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Setup MSVC
uses: ilammy/msvc-dev-cmd@v1
- name: Install build dependencies
run: |
pip install build wheel torch numpy
- name: Build wheel
env:
DAWN_PREFIX: ${{ github.workspace }}/dawn-install
run: |
pip wheel -v . --no-deps --no-build-isolation -w dist/
- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheel-windows-x86_64
path: dist/*.whl
retention-days: 30
test-wheels:
name: Test wheels
needs: [build-wheels-linux, build-wheels-macos, build-wheels-windows]
strategy:
matrix:
include:
- os: ubuntu-latest
artifact: wheel-linux-x86_64
- os: macos-latest
artifact: wheel-macos-arm64
- os: windows-latest
artifact: wheel-windows-x86_64
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Download wheel
uses: actions/download-artifact@v4
with:
name: ${{ matrix.artifact }}
path: dist/
- name: Install wheel
shell: bash
run: |
pip install torch numpy
pip install dist/*.whl
- name: Test import
shell: bash
run: |
python -c "import torch_webgpu; print('torch_webgpu imported successfully')"
- name: Run basic test
shell: bash
run: |
python -c "
import torch
import torch_webgpu
x = torch.tensor([1.0, 2.0, 3.0], device='webgpu')
y = x * 2
print(f'Result: {y}')
print('Basic test passed!')
"