-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall-wasi-sdk.sh
executable file
·32 lines (28 loc) · 1.12 KB
/
install-wasi-sdk.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
UPDATE_RC="${UPDATE_RC:=true}"
WASI_SDK_VERSION="${WASI_SDK_VERSION:=16}"
WASI_SDK_URL="${WASI_SDK_URL:=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-${WASI_SDK_VERSION}/wasi-sdk-${WASI_SDK_VERSION}.0-linux.tar.gz}"
WASI_SDK_HOME="${WASI_SDK_HOME:=/opt/wasi-sdk/}"
mkdir -p ${WASI_SDK_HOME}
curl -L ${WASI_SDK_URL} | tar -xz -C ${WASI_SDK_HOME} --strip-components 1
if [ $? -ne 0 ] ; then
echo "ERROR: Failed to install WASI SDK"
exit 1
fi
updaterc() {
if [ "${UPDATE_RC}" = "true" ]; then
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then
echo -e "$1" >> /etc/bash.bashrc
fi
if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then
echo -e "$1" >> /etc/zsh/zshrc
fi
fi
}
# Add WASI-SDK bin to beginning of PATH in bashrc/zshrc files (unless disabled)
# so that WASI clang and clang++ take precedence over the system ones.
updaterc "$(cat << EOF
if [[ "\${PATH}" != *"${WASI_SDK_HOME}bin"* ]]; then export PATH="${WASI_SDK_HOME}bin:\${PATH}"; fi
EOF
)"