1#!/bin/bash
2set -euo pipefail
3
4# Check if ./target/wasi-sdk exists
5if [ ! -d "./target/wasi-sdk" ]; then
6 echo "WASI SDK not found, downloading v25..."
7
8 # Determine OS and architecture
9 OS=$(uname -s | tr '[:upper:]' '[:lower:]')
10 ARCH=$(uname -m)
11
12 # Map architecture names to WASI SDK format
13 case $ARCH in
14 x86_64)
15 ARCH="x86_64"
16 ;;
17 arm64|aarch64)
18 ARCH="arm64"
19 ;;
20 *)
21 echo "Unsupported architecture: $ARCH"
22 exit 1
23 ;;
24 esac
25
26 # Map OS names to WASI SDK format
27 case $OS in
28 darwin)
29 OS="macos"
30 ;;
31 linux)
32 OS="linux"
33 ;;
34 mingw*|msys*|cygwin*)
35 OS="mingw"
36 ;;
37 *)
38 echo "Unsupported OS: $OS"
39 exit 1
40 ;;
41 esac
42
43 # Construct download URL
44 WASI_SDK_VERSION="25"
45 WASI_SDK_URL="https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-${ARCH}-${OS}.tar.gz"
46
47 echo "Downloading from: $WASI_SDK_URL"
48
49 # Create target directory if it doesn't exist
50 mkdir -p ./target
51
52 # Download and extract
53 curl -fL "$WASI_SDK_URL" | tar -xz -C ./target
54
55 # Rename the extracted directory to wasi-sdk
56 mv "./target/wasi-sdk-${WASI_SDK_VERSION}.0-${ARCH}-${OS}" "./target/wasi-sdk"
57
58 echo "WASI SDK v25 installed successfully"
59else
60 echo "WASI SDK already exists at ./target/wasi-sdk"
61fi