diff --git a/.github/containers/windows/Dockerfile b/.github/containers/windows/Dockerfile new file mode 100644 index 00000000000..aae78ecbf61 --- /dev/null +++ b/.github/containers/windows/Dockerfile @@ -0,0 +1,28 @@ +# Windows container for building XRT with cl.exe (MSVC) and vcpkg. +# Build: docker build -t xrt-build:windows -m 2GB . +# Run (interactive): docker run -it -v C:\path\to\XRT:C:\XRT xrt-build:windows +# Then inside container: cd C:\XRT && .\build\build22.bat -opt +# Or use this image as the runner image for a self-hosted GitHub Actions Windows runner. +# escape=` + +FROM mcr.microsoft.com/windows/servercore:ltsc2022 + +SHELL ["cmd", "/S", "/C"] + +RUN ` + curl -SL --output vs_buildtools.exe https://aka.ms/vs/17/release/vs_buildtools.exe ` + && (start /w vs_buildtools.exe --quiet --wait --norestart --nocache ` + --installPath "%ProgramFiles(x86)%\Microsoft Visual Studio\2022\BuildTools" ` + --add Microsoft.VisualStudio.Workload.VCTools ` + --remove Microsoft.VisualStudio.Component.Windows10SDK.10240 ` + --remove Microsoft.VisualStudio.Component.Windows10SDK.10586 ` + --remove Microsoft.VisualStudio.Component.Windows10SDK.14393 ` + --remove Microsoft.VisualStudio.Component.Windows81SDK ` + || IF "%ERRORLEVEL%"=="3010" EXIT 0) ` + && del /q vs_buildtools.exe + +# Git and vcpkg: install when running the container, or add further RUN steps here. +# The GitHub Actions workflow uses the host's Git and clones vcpkg in the job. + +# Developer command prompt + PowerShell (cl.exe in PATH) +ENTRYPOINT ["C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\VsDevCmd.bat", "-arch=amd64", "&&", "powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] diff --git a/.github/containers/windows/README.md b/.github/containers/windows/README.md new file mode 100644 index 00000000000..ac5d481e480 --- /dev/null +++ b/.github/containers/windows/README.md @@ -0,0 +1,39 @@ +# Windows container for building XRT + +This directory contains a Dockerfile for building XRT on Windows inside a Docker container using **cl.exe** (MSVC) and **vcpkg** for dependencies. + +## Prerequisites + +- Windows host with Docker configured for Windows containers +- Sufficient memory and disk (see [Microsoft's guide](https://learn.microsoft.com/en-us/visualstudio/install/build-tools-container)) + +## Building the image + +From this directory (or repo root): + +```powershell +docker build -t xrt-build:windows -m 2GB .github/containers/windows +``` + +Use `-m 2GB` or more; the default 1 GB is often insufficient for the Build Tools install. + +## Running a build inside the container + +1. Clone XRT and submodules on the host. +2. Run the container with the repo mounted and use the vcpkg workflow (same as the GitHub Action): + +```powershell +docker run -it -v C:\path\to\XRT:C:\XRT xrt-build:windows +``` + +Inside the container, the environment has `cl.exe` in PATH. Install or bring Git, CMake, and vcpkg (e.g. clone vcpkg and bootstrap it), then run the same configure/build steps as in `.github/workflows/build-windows.yml`: use the repo’s `src/vcpkg.json`, pass the vcpkg toolchain file to CMake, and set `KHRONOS` to the vcpkg installed directory (e.g. `vcpkg\installed\x64-windows`). + +## Using with GitHub Actions + +GitHub-hosted Windows runners do **not** support running the job inside a container. To run the Windows build in this container in CI: + +- Use a **self-hosted** Windows runner that has Docker (Windows containers) installed. +- Build this image on that runner (or pull it from your registry). +- In your workflow, run the build by executing the same CMake/vcpkg steps inside this container (e.g. with `docker run` and the appropriate volume and command). + +The main Windows workflow (`.github/workflows/build-windows.yml`) runs on `windows-latest` without a container so it works on GitHub-hosted runners. diff --git a/.github/workflows/build-windows.yml b/.github/workflows/build-windows.yml new file mode 100644 index 00000000000..4236649c5ac --- /dev/null +++ b/.github/workflows/build-windows.yml @@ -0,0 +1,95 @@ +# Build XRT on Windows using cl.exe (MSVC) with vcpkg for 3rd party dependencies. +# Note: GitHub-hosted Windows runners do not support running jobs inside a container. +# For containerized builds, use a self-hosted runner with the Dockerfile in .github/containers/windows. +name: Build XRT (Windows) + +on: + push: + branches: [master, main] + pull_request: + branches: [master, main] + workflow_dispatch: + +env: + VCPKG_BINARY_SOURCES: 'clear;nuget,https://pkgs.dev.azure.com/vcpkg/public/_packaging/public/nuget/v3/index.json,readwrite' + +jobs: + build-windows: + runs-on: windows-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Export GitHub Actions cache environment variables + uses: actions/github-script@v7 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); + + - name: Set up vcpkg + uses: actions/checkout@v4 + with: + repository: microsoft/vcpkg + path: vcpkg + ref: master + + - name: Bootstrap vcpkg + run: .\vcpkg\bootstrap-vcpkg.bat -disableMetrics + working-directory: ${{ github.workspace }} + + - name: Cache vcpkg packages + uses: actions/cache@v4 + with: + path: | + ${{ github.workspace }}/vcpkg/installed + ${{ github.workspace }}/vcpkg/buildtrees + ${{ github.workspace }}/vcpkg/downloads + key: vcpkg-win-${{ runner.os }}-${{ hashFiles('src/vcpkg.json') }} + restore-keys: | + vcpkg-win-${{ runner.os }}- + + - name: Install vcpkg dependencies (manifest) + run: | + .\vcpkg\vcpkg.exe install --x-manifest-root="${{ github.workspace }}\src" --triplet=x64-windows + working-directory: ${{ github.workspace }} + + - name: Configure CMake (Release) + run: | + $vcpkgRoot = "${{ github.workspace }}\vcpkg" + $triplet = "x64-windows" + $kronos = "$vcpkgRoot\installed\$triplet" + $src = "${{ github.workspace }}\src" + $build = "${{ github.workspace }}\build\WRelease" + New-Item -ItemType Directory -Force -Path $build + cmake -B $build -S $src ` + -G "Visual Studio 17 2022" -A x64 ` + -DCMAKE_TOOLCHAIN_FILE="$vcpkgRoot\scripts\buildsystems\vcpkg.cmake" ` + -DVCPKG_HOST_TRIPLET=$triplet ` + -DKHRONOS="$kronos" ` + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ` + -DMSVC_PARALLEL_JOBS=4 + shell: pwsh + + - name: Build (Release) + run: | + $build = "${{ github.workspace }}\build\WRelease" + cmake --build $build --config Release --verbose + shell: pwsh + + - name: Install (staging) + run: | + $build = "${{ github.workspace }}\build\WRelease" + $prefix = "$build\xilinx\xrt" + cmake --install $build --config Release --prefix $prefix --verbose + shell: pwsh + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: xrt-windows-Release + path: ${{ github.workspace }}/build/WRelease/xilinx/xrt + retention-days: 7 diff --git a/src/vcpkg.json b/src/vcpkg.json new file mode 100644 index 00000000000..1b1f2333533 --- /dev/null +++ b/src/vcpkg.json @@ -0,0 +1,11 @@ +{ + "name": "xrt", + "version": "0.1.0", + "description": "XRT Windows build dependencies (vcpkg manifest)", + "dependencies": [ + "boost-filesystem", + "boost-program-options", + "gtest", + "opencl" + ] +}