|
| 1 | +#!/bin/bash |
| 2 | +# setup_windows_dev.sh — add Visual Studio dev tools (msbuild, fxc, cl, etc.) |
| 3 | +# to the current bash session's PATH. Equivalent of setup_windows_dev.ps1 but |
| 4 | +# callable from Git Bash / MSYS2 without a PowerShell detour. |
| 5 | +# |
| 6 | +# Usage: source setup_windows_dev.sh |
| 7 | + |
| 8 | +if [[ "$(uname -s)" != MINGW* && "$(uname -s)" != MSYS* ]]; then |
| 9 | + return 0 2>/dev/null || exit 0 |
| 10 | +fi |
| 11 | + |
| 12 | +# Already set up? |
| 13 | +if command -v msbuild.exe &>/dev/null; then |
| 14 | + return 0 2>/dev/null || exit 0 |
| 15 | +fi |
| 16 | + |
| 17 | +# Locate Visual Studio via vswhere (works for any version/edition/location). |
| 18 | +VSWHERE="/c/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" |
| 19 | +if [ ! -f "$VSWHERE" ]; then |
| 20 | + echo "setup_windows_dev.sh: vswhere.exe not found — is Visual Studio installed?" >&2 |
| 21 | + return 1 2>/dev/null || exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +VS_INSTALL_PATH=$("$VSWHERE" -latest -property installationPath 2>/dev/null | tr -d '\r') |
| 25 | +if [ -z "$VS_INSTALL_PATH" ]; then |
| 26 | + echo "setup_windows_dev.sh: no Visual Studio installation found" >&2 |
| 27 | + return 1 2>/dev/null || exit 1 |
| 28 | +fi |
| 29 | + |
| 30 | +VS_DEVSHELL="${VS_INSTALL_PATH}\\Common7\\Tools\\Launch-VsDevShell.ps1" |
| 31 | +VS_DEVSHELL_UNIX=$(cygpath -u "$VS_DEVSHELL" 2>/dev/null) |
| 32 | +if [ ! -f "$VS_DEVSHELL_UNIX" ]; then |
| 33 | + echo "setup_windows_dev.sh: Launch-VsDevShell.ps1 not found at $VS_DEVSHELL" >&2 |
| 34 | + return 1 2>/dev/null || exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +# Run Launch-VsDevShell in PowerShell and capture the resulting PATH. |
| 38 | +NEW_PATH=$(powershell -NoProfile -ExecutionPolicy Bypass -Command " |
| 39 | + & '${VS_DEVSHELL}' -SkipAutomaticLocation *>\$null |
| 40 | + \$env:Path |
| 41 | +" 2>/dev/null | tr -d '\r') |
| 42 | + |
| 43 | +if [ -z "$NEW_PATH" ]; then |
| 44 | + echo "setup_windows_dev.sh: failed to extract VS dev PATH" >&2 |
| 45 | + return 1 2>/dev/null || exit 1 |
| 46 | +fi |
| 47 | + |
| 48 | +# Convert Windows PATH (;-separated) to bash PATH (:-separated, unix paths). |
| 49 | +UNIX_PATH="" |
| 50 | +IFS=';' read -ra ENTRIES <<< "$NEW_PATH" |
| 51 | +for entry in "${ENTRIES[@]}"; do |
| 52 | + unix_entry=$(cygpath -u "$entry" 2>/dev/null || echo "$entry") |
| 53 | + if [ -n "$UNIX_PATH" ]; then |
| 54 | + UNIX_PATH="$UNIX_PATH:$unix_entry" |
| 55 | + else |
| 56 | + UNIX_PATH="$unix_entry" |
| 57 | + fi |
| 58 | +done |
| 59 | + |
| 60 | +export PATH="$UNIX_PATH" |
| 61 | + |
| 62 | +# Also set RIVE_ROOT if not already set. |
| 63 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" |
| 64 | +export RIVE_ROOT="${RIVE_ROOT:-$(cd "$SCRIPT_DIR/../../.." && pwd)}" |
| 65 | +export PATH="$SCRIPT_DIR:$PATH" |
0 commit comments