|
| 1 | +## Build XGBoost on Windows (CPU or GPU) |
| 2 | +## |
| 3 | +## Usage: |
| 4 | +## build-win64.ps1 -variant <cpu|gpu> |
| 5 | +## |
| 6 | +## Parameters: |
| 7 | +## -variant cpu - Build CPU-only version (creates xgboost-cpu wheel) |
| 8 | +## -variant gpu - Build with CUDA support (creates default xgboost wheel, includes gtest) |
| 9 | +## |
| 10 | +## Examples: |
| 11 | +## # Build CPU wheel (xgboost-cpu) |
| 12 | +## ops/pipeline/build-win64.ps1 -variant cpu |
| 13 | +## |
| 14 | +## # Build GPU wheel with CUDA |
| 15 | +## ops/pipeline/build-win64.ps1 -variant gpu |
| 16 | + |
| 17 | +param( |
| 18 | + [Parameter(Mandatory=$true)] |
| 19 | + [ValidateSet("cpu", "gpu")] |
| 20 | + [string]$variant |
| 21 | +) |
| 22 | + |
| 23 | +$ErrorActionPreference = "Stop" |
| 24 | + |
| 25 | +. ops/pipeline/enforce-ci.ps1 |
| 26 | + |
| 27 | +# Build common CMake arguments |
| 28 | +$cmake_args = @( |
| 29 | + "-G", "Ninja", |
| 30 | + "-DCMAKE_BUILD_TYPE=Release", |
| 31 | + "-DCMAKE_C_COMPILER_LAUNCHER=sccache", |
| 32 | + "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache" |
| 33 | +) |
| 34 | + |
| 35 | +if ($variant -eq "gpu") { |
| 36 | + Write-Host "--- Build libxgboost on Windows with CUDA" |
| 37 | + nvcc --version |
| 38 | + if ($LASTEXITCODE -ne 0) { throw "Last command failed" } |
| 39 | + |
| 40 | + # Add CUDA-specific flags |
| 41 | + $cmake_args += @( |
| 42 | + "-DUSE_CUDA=ON", |
| 43 | + "-DGOOGLE_TEST=ON", |
| 44 | + "-DUSE_DMLC_GTEST=ON" |
| 45 | + ) |
| 46 | + |
| 47 | + # Only build SM75 for non-release branches (faster CI) |
| 48 | + if ($is_release_branch -eq 0) { |
| 49 | + $cmake_args += "-DGPU_COMPUTE_VER=75" |
| 50 | + } |
| 51 | +} else { |
| 52 | + Write-Host "--- Build libxgboost on Windows (CPU, minimal)" |
| 53 | +} |
| 54 | + |
| 55 | +# Run CMake configure |
| 56 | +mkdir build |
| 57 | +cd build |
| 58 | +& cmake .. @cmake_args |
| 59 | +if ($LASTEXITCODE -ne 0) { throw "Last command failed" } |
| 60 | + |
| 61 | +# Build |
| 62 | +cmake --build . -v |
| 63 | +if ($LASTEXITCODE -ne 0) { throw "Last command failed" } |
| 64 | + |
| 65 | +Write-Host "--- Build binary wheel" |
| 66 | +cd .. |
| 67 | + |
| 68 | +# For CPU variant, rename package to xgboost-cpu |
| 69 | +if ($variant -eq "cpu") { |
| 70 | + conda activate |
| 71 | + python ops/script/pypi_variants.py --use-suffix=cpu --require-nccl-dep=na |
| 72 | + if ($LASTEXITCODE -ne 0) { throw "Last command failed" } |
| 73 | +} |
| 74 | + |
| 75 | +cd python-package |
| 76 | +conda activate |
| 77 | +& pip wheel --no-deps -v . --wheel-dir dist/ |
| 78 | +if ($LASTEXITCODE -ne 0) { throw "Last command failed" } |
| 79 | + |
| 80 | +python -m wheel tags --python-tag py3 --abi-tag none ` |
| 81 | + --platform win_amd64 --remove ` |
| 82 | + (Get-ChildItem dist/*.whl | Select-Object -Expand FullName) |
| 83 | +if ($LASTEXITCODE -ne 0) { throw "Last command failed" } |
| 84 | + |
| 85 | +Write-Host "--- Upload Python wheel" |
| 86 | +cd .. |
| 87 | +if ($is_release_branch -eq 1) { |
| 88 | + python ops/pipeline/manage-artifacts.py upload ` |
| 89 | + --s3-bucket 'xgboost-nightly-builds' ` |
| 90 | + --prefix "$Env:BRANCH_NAME/$Env:GITHUB_SHA" --make-public ` |
| 91 | + (Get-ChildItem python-package/dist/*.whl | Select-Object -Expand FullName) |
| 92 | + if ($LASTEXITCODE -ne 0) { throw "Last command failed" } |
| 93 | +} |
0 commit comments