Skip to content

Commit eed3f69

Browse files
committed
fix: add missing CI script
1 parent 2373e6f commit eed3f69

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
id: setup
5454
run: |
5555
echo "version=$SLANG_TAG" >> $GITHUB_OUTPUT # Output for cache key
56-
SLANG_DIR=$(./download_slang.sh --version $SLANG_TAG | grep '^SLANG_DIR=' | cut -d'=' -f2-)
56+
SLANG_DIR=$(./.github/workflows/download_slang.sh --version $SLANG_TAG | grep '^SLANG_DIR=' | cut -d'=' -f2-)
5757
echo "slang-dir=$SLANG_DIR" >> $GITHUB_OUTPUT # Output for dependents
5858
echo "slang-cache-key=slang-v$SLANG_TAG-${{ runner.os }}-${{ runner.arch }}" >> $GITHUB_OUTPUT
5959
echo "SLANG_DIR=$SLANG_DIR" >> $GITHUB_ENV # For this job if needed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/bash
2+
3+
# Default values
4+
OS=""
5+
OUTPUT_DIR="$HOME/.cache/slang"
6+
SLANG_VERSION=""
7+
SLANG_TAG=""
8+
ASSET_SUFFIX=""
9+
SLANG_URL_BASE="https://github.com/shader-slang/slang/releases/download"
10+
11+
# Help message
12+
usage() {
13+
echo "Usage: $0 [--os <linux|macos|macos-arm64|windows>] [--output-dir <path>] [--version <version>]"
14+
echo " --os: Target OS (default: auto-detect from current platform)"
15+
echo " --output-dir: Directory to extract Slang (default: ~/.cache/slang)"
16+
echo " --version: Slang version (e.g., 2025.18.2, default: latest)"
17+
echo "Example: $0 --os linux --output-dir /tmp/slang"
18+
}
19+
20+
# Parse arguments
21+
while [[ "$#" -gt 0 ]]; do
22+
case $1 in
23+
--os) OS="$2"; shift ;;
24+
--output-dir) export OUTPUT_DIR="$2"; shift ;;
25+
--version) export SLANG_VERSION="$2"; shift ;;
26+
*) usage ; exit 1 ;;
27+
esac
28+
shift
29+
done
30+
31+
# Detect OS if not specified
32+
if [[ -z "$OS" ]]; then
33+
case "$(uname -s)" in
34+
Linux*) OS="linux" ;;
35+
Darwin*)
36+
if [[ "$(uname -m)" == "arm64" ]]; then
37+
OS="macos-aarch64"
38+
else
39+
OS="macos"
40+
fi
41+
;;
42+
CYGWIN*|MINGW*|MSYS*) OS="windows" ;;
43+
*) echo "Error: Unable to detect OS. Specify --os (linux, macos, macos-arm64, windows)"; exit 1 ;;
44+
esac
45+
fi
46+
47+
# Determine asset suffix based on OS
48+
case "$OS" in
49+
linux) ASSET_SUFFIX="linux-x86_64.zip" ;;
50+
macos) ASSET_SUFFIX="macos-x86_64.zip" ;;
51+
macos-aarch64) ASSET_SUFFIX="macos-aarch64.zip" ;;
52+
windows) ASSET_SUFFIX="windows-x86_64.zip" ;;
53+
*) echo "Error: Unsupported OS: $OS"; exit 1 ;;
54+
esac
55+
56+
# Get Slang version if not specified
57+
if [[ -z "$SLANG_VERSION" ]]; then
58+
export SLANG_TAG=$(curl -s https://api.github.com/repos/shader-slang/slang/releases/latest | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/')
59+
export SLANG_VERSION=$(echo "$SLANG_TAG" | sed 's/v//') # e.g., v2025.18.2 -> 2025.18.2
60+
else
61+
export SLANG_TAG="v$SLANG_VERSION"
62+
fi
63+
64+
if [[ -z "$SLANG_VERSION" ]]; then
65+
echo "Error: Could not determine Slang version"
66+
exit 1
67+
fi
68+
69+
# Set up paths
70+
SLANG_DIR="$OUTPUT_DIR/slang-v$SLANG_VERSION-$OS"
71+
ZIP_URL="$SLANG_URL_BASE/$SLANG_TAG/slang-$SLANG_VERSION-$ASSET_SUFFIX"
72+
TEMP_ZIP="/tmp/slang-$SLANG_VERSION.zip"
73+
74+
# Check if Slang is already extracted
75+
if [[ -d "$SLANG_DIR" ]] && [[ -f "$SLANG_DIR/bin/slangc" || -f "$SLANG_DIR/bin/slangc.exe" ]]; then
76+
echo "Using existing Slang at $SLANG_DIR"
77+
echo "SLANG_DIR=$SLANG_DIR"
78+
exit 0
79+
fi
80+
81+
# Download Slang release
82+
echo "Downloading Slang v$SLANG_VERSION for $OS from $ZIP_URL..."
83+
mkdir -p "$OUTPUT_DIR"
84+
curl -L -o "$TEMP_ZIP" "$ZIP_URL" || { echo "Error: Download failed for $ZIP_URL"; exit 1; }
85+
86+
# Extract based on OS
87+
echo "Extracting to $SLANG_DIR..."
88+
if [[ "$OS" == "windows" ]]; then
89+
# Windows: Assume 7z is available (or adjust for PowerShell/Expand-Archive)
90+
7z x "$TEMP_ZIP" -o"$SLANG_DIR" -y > /dev/null || { echo "Error: Extraction failed"; rm -f "$TEMP_ZIP"; exit 1; }
91+
else
92+
# Linux/macOS: Use unzip
93+
unzip -q "$TEMP_ZIP" -d "$SLANG_DIR" || { echo "Error: Extraction failed"; rm -f "$TEMP_ZIP"; exit 1; }
94+
fi
95+
96+
# Clean up
97+
rm -f "$TEMP_ZIP"
98+
99+
# Verify extraction
100+
if [[ ! -f "$SLANG_DIR/bin/slangc" && ! -f "$SLANG_DIR/bin/slangc.exe" ]]; then
101+
echo "Error: Extraction incomplete, slangc not found in $SLANG_DIR/bin"
102+
exit 1
103+
fi
104+
105+
echo "Slang v$SLANG_VERSION extracted to $SLANG_DIR"
106+
echo "SLANG_DIR=$SLANG_DIR"
107+
108+
# For use in calling script
109+
export SLANG_DIR

0 commit comments

Comments
 (0)