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