forked from api7/wasm-nginx-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-wasmtime.sh
executable file
·50 lines (49 loc) · 1.94 KB
/
install-wasmtime.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
# Copyright 2022 Shenzhen ZhiLiu Technology Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
set -euo pipefail -x
arch=$(uname -m | tr '[:upper:]' '[:lower:]')
os=$(uname -s | tr '[:upper:]' '[:lower:]')
if [ "$os" = "darwin" ]; then
os="macos"
if [ "$arch" = "arm64" ]; then
arch="aarch64"
fi
else
os="linux"
fi
ARCH=$arch
VER=v0.38.1
wget https://github.com/bytecodealliance/wasmtime/releases/download/${VER}/wasmtime-${VER}-${ARCH}-${os}-c-api.tar.xz
tar -xvf ./wasmtime-${VER}-${ARCH}-${os}-c-api.tar.xz > /dev/null
if [ -d wasmtime-c-api ]; then
rm -rf wasmtime-c-api
fi
mv wasmtime-${VER}-${ARCH}-${os}-c-api wasmtime-c-api
if { echo "int main(void) {}" | gcc -o /dev/null -v -x c - &> /dev/stdout| grep collect | tr -s " " "\012" | grep musl; } \
|| ( [[ -f /etc/redhat-release ]] && [[ "$arch" = "aarch64" ]] ); then
# build from source code if the libc is musl or under centos aarch64
if ! command -v cargo > /dev/null; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
fi
git clone https://github.com/bytecodealliance/wasmtime -b ${VER} --depth 1 \
&& cd wasmtime \
&& git submodule update --init \
&& RUSTFLAGS="-C target-feature=-crt-static" \
cargo build --release --manifest-path crates/c-api/Cargo.toml \
&& mv target/release/libwasmtime.* ../wasmtime-c-api/lib \
&& cd ..
fi