Skip to content

Add Windows build workflow in the CI. #4041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# yamllint disable rule:line-length
name: CI_WINDOWS

on:
workflow_dispatch:
workflow_call:
push:
branches: [main]

concurrency:
# A PR number if a pull request and otherwise the commit hash. This cancels
# queued and in-progress runs for the same PR (presubmit) or commit
# (postsubmit).
group: ci-build-test-cpp-windows-${{ github.event.number || github.sha }}
cancel-in-progress: true

jobs:

build-test-windows:
strategy:
fail-fast: true
matrix:
torch-version: [nightly]
name: Build (Windows, torch-${{ matrix.torch-version }})
runs-on: windows-latest
defaults:
run:
shell: bash
env:
CACHE_DIR: ${{ github.workspace }}\.container-cache
steps:
- name: "Checking out repository"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true

- name: Setup workspace
uses: ./.github/actions/setup-build

- name: Enable cache
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
with:
path: ${{ env.CACHE_DIR }}
# Use as cache key a PR number if a pull request and otherwise the commit hash. This reuses the cache for a PR irrespective of the commit hash. Otherwise, it uses commit hash for merges into the main branch
key: build-test-cpp-asserts-windows-${{ matrix.torch-version }}-v2-${{ github.event.number || github.sha }}
restore-keys: |
build-test-cpp-asserts-windows-${{ matrix.torch-version }}-v2-

- name: "Configuring MSVC"
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0

- name: Install python deps (torch-${{ matrix.torch-version }})
run: |
./build_tools/ci/install_python_deps.sh ${{ matrix.torch-version }}

- name: ccache
uses: hendrikmuhs/ccache-action@53911442209d5c18de8a31615e0923161e435875 # v1.2.16
with:
key: ${{ github.job }}-${{ matrix.torch-version }}
save: ${{ needs.setup.outputs.write-caches == 1 }}

- name: Build project
run: |
cache_dir="${{ env.CACHE_DIR }}" \
./build_tools/python_deploy/build_windows_ci.sh

- name: Save cache
uses: actions/cache/save@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
if: ${{ !cancelled() }}
with:
path: ${{ env.CACHE_DIR }}
key: build-test-cpp-asserts-windows-${{ matrix.torch-version }}-v2-${{ github.event.number || github.sha }}

# todo: enable when use of `signal` for timeout is enhanced to be platform-agnostic
# - name: Integration tests (torch-${{ matrix.torch-version }})
# run: |
# ./build_tools/ci/test_posix.sh ${{ matrix.torch-version }}
42 changes: 39 additions & 3 deletions build_tools/python_deploy/build_windows_ci.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
#!/usr/bin/env bash
set -eo pipefail
set -eu -o errtrace

echo "Building torch-mlir"

cache_dir="${cache_dir:-}"
this_dir="$(cd $(dirname $0) && pwd)"
repo_root="$(cd ${this_dir}/../.. && pwd)"

# Setup cache dir.
if [ -z "${cache_dir}" ]; then
cache_dir="${repo_root}/.build-cache"
mkdir -p "${cache_dir}"
cache_dir="$(cd ${cache_dir} && pwd)"
fi

echo "Caching to ${cache_dir}"
mkdir -p "${cache_dir}/ccache"
mkdir -p "${cache_dir}/pip"

export CCACHE_DIR="${cache_dir}/ccache"
export CCACHE_MAXSIZE="350M"

# Clear ccache stats.
ccache -z

echo "::group::CMake configure"
cmake -GNinja -Bbuild \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
Expand All @@ -14,9 +36,23 @@ cmake -GNinja -Bbuild \
-DLLVM_EXTERNAL_PROJECTS="torch-mlir" \
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$PWD" \
-DPython3_EXECUTABLE="$(which python)" \
-DPython_EXECUTABLE="$(which python)" \
-DTORCH_MLIR_ENABLE_STABLEHLO=OFF \
$GITHUB_WORKSPACE/externals/llvm-project/llvm
-DTORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS=ON \
-DTORCH_MLIR_ENABLE_LTC=OFF \
-DTORCH_MLIR_ENABLE_JIT_IR_IMPORTER=ON \
${repo_root}/externals/llvm-project/llvm
echo "::endgroup::"

cmake --build build --config Release
echo "::group::Build"
cmake --build ${repo_root}/build --target tools/torch-mlir/all -- -k 0
echo "::endgroup::"

echo "Build completed successfully"

echo "::group::Unit tests"
cmake --build ${repo_root}/build --target check-torch-mlir
echo "::endgroup::"

# Show ccache stats.
ccache --show-stats
Loading
Loading