Skip to content
Open
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
108 changes: 108 additions & 0 deletions .github/scripts/shorten-conda-env-windows.sh
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file trying to do?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That script shortens a long Conda env path by mapping its parent directory to a temporary Windows drive letter
Example:
C:...\very\very\long\conda\envs\path
becomes something like:
T:
That helps avoid Windows path length failures during builds.
The Windows drive requirement is:
single ASCII letter A-Z, case-insensitive, followed by :

Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env bash

set -euo pipefail

if [[ -z "${CONDA_ENV:-}" ]]; then
echo "::error::CONDA_ENV is not set"
exit 1
fi

if [[ -z "${GITHUB_ENV:-}" ]]; then
echo "::error::GITHUB_ENV is not set"
exit 1
fi

if ! command -v cygpath >/dev/null 2>&1; then
echo "::error::cygpath is required to shorten Windows paths"
exit 1
fi

to_windows_path() {
local path="${1//\\//}"

if [[ "${path}" =~ ^[A-Za-z]:/ ]]; then
printf "%s\n" "${path//\//\\}"
else
cygpath -w "${path}"
fi
}

to_bash_path() {
local path="${1//\\//}"

if [[ "${path}" =~ ^([A-Za-z]):(/.*)?$ ]]; then
printf "/%s%s\n" "${BASH_REMATCH[1],,}" "${BASH_REMATCH[2]}"
else
printf "%s\n" "${path}"
fi
}

find_unused_drive() {
local drive

for drive in T S R Q P O N M L K J I H G F E D; do
if [[ ! -e "/${drive,,}" ]]; then
printf "%s:\n" "${drive}"
return 0
fi
done

return 1
}

conda_env="${CONDA_ENV%/}"
conda_env_bash="$(to_bash_path "${conda_env}")"
conda_env_name="$(basename "${conda_env_bash}")"
conda_env_parent="$(dirname "${conda_env_bash}")"
conda_env_parent_win="$(to_windows_path "${conda_env_parent}")"

if [[ -n "${SHORT_CONDA_DRIVE:-}" ]]; then
short_drive="${SHORT_CONDA_DRIVE%:}:"
elif ! short_drive="$(find_unused_drive)"; then
echo "::error::Could not find an unused drive letter for the Conda env path"
exit 1
fi

if [[ ! "${short_drive}" =~ ^[A-Za-z]:$ ]]; then
echo "::error::SHORT_CONDA_DRIVE must be a Windows drive letter like T:"
exit 1
fi

MSYS2_ARG_CONV_EXCL="*" MSYS2_ENV_CONV_EXCL="CONDA_ENV_PARENT_WIN" SHORT_CONDA_DRIVE="${short_drive}" CONDA_ENV_PARENT_WIN="${conda_env_parent_win}" powershell.exe -NoProfile -ExecutionPolicy Bypass -Command '
$ErrorActionPreference = "Stop"
$drive = $env:SHORT_CONDA_DRIVE
$target = $env:CONDA_ENV_PARENT_WIN
$target = $target -replace "^[\\/]+(?=[A-Za-z]:[\\/])", ""
Write-Host "Mapping Conda env parent path: $target"
if (-not (Test-Path -LiteralPath $target -PathType Container)) {
throw "Conda env parent path not found: $target"
}
& subst.exe $drive /D 2>$null
& subst.exe $drive $target
if ($LASTEXITCODE -ne 0) {
throw "subst failed to map $drive to $target"
}
'

short_conda_env="${short_drive}/${conda_env_name}"
short_conda_run="conda run --no-capture-output -p ${short_conda_env}"

{
echo "CONDA_ENV=${short_conda_env}"
echo "CONDA_RUN=${short_conda_run}"
} >> "${GITHUB_ENV}"

build_env_file="${BUILD_ENV_FILE:-}"
if [[ -n "${build_env_file}" ]]; then
build_env_file="$(to_bash_path "${build_env_file}")"
fi

if [[ -n "${build_env_file}" && -f "${build_env_file}" ]]; then
{
printf "export CONDA_ENV=%q\n" "${short_conda_env}"
printf "export CONDA_RUN=%q\n" "${short_conda_run}"
} >> "${build_env_file}"
fi

echo "Mapped ${conda_env_parent_win} to ${short_drive}"
echo "Using ${short_conda_env} as the Conda environment prefix"
3 changes: 3 additions & 0 deletions .github/workflows/build-tensorrt-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
cuda-version: ${{ env.CU_VERSION }}
arch: ${{ env.ARCH }}
- name: Shorten Conda environment path
run: |
bash "${REPOSITORY}/.github/scripts/shorten-conda-env-windows.sh"
- name: Install XPU support package
if: ${{ matrix.gpu_arch_type == 'xpu' }}
run: |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
cuda-version: ${{ env.CU_VERSION }}
arch: ${{ inputs.architecture }}
- name: Shorten Conda environment path
if: inputs.architecture == 'x64'
run: |
bash "${REPOSITORY}/.github/scripts/shorten-conda-env-windows.sh"
- name: Install XPU support package
if: ${{ matrix.gpu_arch_type == 'xpu' }}
env:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/windows-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ jobs:
python-version: ${{ env.PYTHON_VERSION }}
cuda-version: ${{ env.CU_VERSION }}
arch: ${{ env.ARCH }}
- name: Shorten Conda environment path
if: inputs.architecture == 'x64'
run: |
bash "${REPOSITORY}/.github/scripts/shorten-conda-env-windows.sh"
- name: Run Pre-Script with Caching
if: ${{ inputs.pre-script != '' }}
uses: ./test-infra/.github/actions/run-script-with-cache
Expand Down
11 changes: 6 additions & 5 deletions packaging/pre_build_script_windows.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set -x

pip install -U numpy packaging pyyaml setuptools wheel fmt
python -m pip install -U numpy packaging pyyaml setuptools wheel fmt

choco install bazelisk -y

Expand All @@ -20,12 +20,13 @@ fi
TORCH=$(grep "^torch>" py/requirements.txt)
INDEX_URL=https://download.pytorch.org/whl/${CHANNEL}/${CU_VERSION}

# Install all the dependencies required for Torch-TensorRT
pip uninstall -y torch torchvision
pip install --force-reinstall --pre ${TORCH} --index-url ${INDEX_URL}
# The workflow installs torch before this script runs. Avoid uninstalling and
# force-reinstalling it here: with the shortened Windows conda prefix, pip can
# rediscover a half-removed torch dist-info through the original C:\ path.
python -m pip install --pre "${TORCH}" --index-url "${INDEX_URL}" || exit 1

export CUDA_HOME="$(echo ${CUDA_PATH} | sed -e 's#\\#\/#g')"
export TORCH_INSTALL_PATH="$(python -c "import torch, os; print(os.path.dirname(torch.__file__))" | sed -e 's#\\#\/#g')"
export TORCH_INSTALL_PATH="$(python -c "import torch, os; print(os.path.dirname(torch.__file__).replace('\\\\', '/'))")" || exit 1

# tried with conda install -c conda-forge fmt -y, but build still failed in windows with the following error:
# C:\actions-runner\_work\_temp\conda_environment_18042354682\lib\site-packages\torch\include\torch/csrc/utils/python_arg_parser.h(42): fatal error C1083: Cannot open include file: 'fmt/format.h': No such file or directory
Expand Down
Loading