Repository: shader-slang/slang
File: extras/check-spirv-generated.sh (Shell)

Code before:
  SPIRV_CHANGED=true
else
  SPIRV_CHANGED=false
  if echo "$CHANGED_FILES" | grep -q "^external/spirv-tools"; then
    echo_info "Detected changes in external/spirv-tools"
    SPIRV_CHANGED=true
  fi
  if echo "$CHANGED_FILES" | grep -q "^external/spirv-headers"; then
    echo_info "Detected changes in external/spirv-headers"
    SPIRV_CHANGED=true
  fi
fi

if [ "$SPIRV_CHANGED" = false ]; then
  echo_success "No changes to external/spirv-tools or external/spirv-headers - skipping check"
  exit 0
fi

echo ""
echo_info "Changes detected in SPIRV directories - verifying generated files are up-to-date..."
echo ""

# 2. Initialize submodules
echo_info "Initializing SPIRV submodules..."
git submodule update --init --recursive external/spirv-tools
git submodule update --init --recursive external/spirv-headers

# 3. Sync spirv-tools dependencies
echo_info "Syncing spirv-tools dependencies..."
cd external/spirv-tools

if [ ! -f "utils/git-sync-deps" ]; then
  echo_error "utils/git-sync-deps not found in external/spirv-tools"
  exit 1
fi

# git-sync-deps needs to be run to get additional dependencies
python3 utils/git-sync-deps

cd ../..

# 4. Build spirv-tools to generate files
BUILD_DIR="external/spirv-tools/build-ci-check"
echo_info "Building spirv-tools generation targets in $BUILD_DIR..."

mkdir -p "$BUILD_DIR"

# Configure CMake (suppress warnings from external project)
cmake -Wno-dev -B "$BUILD_DIR" external/spirv-tools

# Build only the generation targets (faster than full build)

Review comment (suggestion):
I don't think we need spirv-headers.
We only need to know the commit hash value, which can be retrieved without cloning the repo.
```
git submodule state external/spirv-headers
```


Code after:
  echo "  git -C external/spirv-headers fetch"
  echo "  git -C external/spirv-headers checkout $EXPECTED_COMMIT"
  echo "  git add external/spirv-headers"
  exit 1
fi

echo_success "spirv-headers commit matches spirv-tools DEPS"

# 3. Sync spirv-tools dependencies
echo_info "Syncing spirv-tools dependencies..."
cd external/spirv-tools

if [ ! -f "utils/git-sync-deps" ]; then
  echo_error "utils/git-sync-deps not found in external/spirv-tools"
  exit 1
fi

# git-sync-deps needs to be run to get additional dependencies
echo_info "Running git-sync-deps (this may take a moment)..."
if ! python3 utils/git-sync-deps; then
  echo_error "Failed to sync spirv-tools dependencies"
  echo_error "This may be due to network issues or missing git credentials"
  cd ../..
  exit 1
fi
echo_success "Dependencies synced successfully"

cd ../..

# 4. Build spirv-tools to generate files
BUILD_DIR="external/spirv-tools/build-ci-check"
echo_info "Building spirv-tools generation targets in $BUILD_DIR..."

mkdir -p "$BUILD_DIR"

# Configure CMake (suppress warnings from external project)
cmake -Wno-dev -B "$BUILD_DIR" external/spirv-tools

# Build only the generation targets (faster than full build)
echo_info "Building generation targets (this may take a few minutes)..."
if ! cmake --build "$BUILD_DIR" \
  --target spirv-tools-build-version \
  --target core_tables \
  --target extinst_tables; then
  echo_error "Failed to build spirv-tools generation targets"
  echo_error "Check the build output above for details"
  rm -rf "$BUILD_DIR"
  exit 1
fi
echo_success "Build completed successfully"