From 51e54b8475e429e899326ada5d5a41701c16b2f4 Mon Sep 17 00:00:00 2001 From: BananaLF <864685021@qq.com> Date: Tue, 30 May 2023 16:53:56 +0800 Subject: [PATCH 1/3] add wasm static install scripts --- Makefile | 12 +++++- libs/scripts/system.sh | 58 +++++++++++++++++++++++++++++ libs/scripts/wasm_static_install.sh | 18 +++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100755 libs/scripts/system.sh create mode 100755 libs/scripts/wasm_static_install.sh diff --git a/Makefile b/Makefile index 572a69212..c1b208a8f 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,15 @@ endif build_tags = netgo +system=$(shell $(shell pwd)/libs/scripts/system.sh) +ifeq ($(system),alpine) + LINK_STATICALLY=true +else + ifeq ($(LINK_STATICALLY),true) + $(error your system is $(system) which can not be complied statically. please set LINK_STATICALLY=false) + endif +endif + ifeq ($(WITH_ROCKSDB),true) CGO_ENABLED=1 build_tags += rocksdb @@ -53,7 +62,8 @@ else endif ifeq ($(LINK_STATICALLY),true) - build_tags += muslc + build_tags += muslc + dummy := $(shell $(shell pwd)/libs/scripts/wasm_static_install.sh) endif build_tags += $(BUILD_TAGS) diff --git a/libs/scripts/system.sh b/libs/scripts/system.sh new file mode 100755 index 000000000..b24d953c9 --- /dev/null +++ b/libs/scripts/system.sh @@ -0,0 +1,58 @@ +#!/bin/sh +#set -e +GO_VERSION=$1 +ROCKSDB_VERSION=$2 + +get_distribution() { + lsb_dist="" + # Every system that we officially support has /etc/os-release + if [ -r /etc/os-release ]; then + lsb_dist="$(. /etc/os-release && echo "$ID")" + fi + # Returning an empty string here should be alright since the + # case statements don't act unless you provide an actual value + echo "$lsb_dist" +} + +is_darwin() { + case "$(uname -s)" in + *darwin*) true ;; + *Darwin*) true ;; + *) false ;; + esac +} + +get_system_version() { + lsb_dist=$(get_distribution) + lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')" + system_version= + case "$lsb_dist" in + ubuntu) + system_version="ubuntu" + ;; + centos) + system_version="centos" + ;; + alpine) + system_version="alpine" + ;; + *) + if [ -z "$lsb_dist" ]; then + if is_darwin; then + system_version="macos" + fi + else + echo + echo "ERROR: Unsupported system '$lsb_dist', only support centos,ubuntu,alpine,macos" + echo + exit 1 + fi + ;; + esac + + # checkout go version + + echo "$system_version" +} + +echo $(get_system_version) diff --git a/libs/scripts/wasm_static_install.sh b/libs/scripts/wasm_static_install.sh new file mode 100755 index 000000000..abd8a528d --- /dev/null +++ b/libs/scripts/wasm_static_install.sh @@ -0,0 +1,18 @@ +#!/bin/sh +#set -e + +echo "install wasm static lib with sudo" +installWasmLib() { + if [ -r /usr/local/lib/libwasmvm_muslc.a ]; then + exit 0 + elif [ -r /lib/libwasmvm_muslc.a ]; then + exit 0 + fi + wget --no-check-certificate "https://github.com/CosmWasm/wasmvm/releases/download/v1.0.0/libwasmvm_muslc.x86_64.a" -O /usr/local/lib/libwasmvm_muslc.x86_64.a + cp /usr/local/lib/libwasmvm_muslc.x86_64.a /usr/local/lib/libwasmvm_muslc.a + echo "install wasm static lib success" +} + +installWasmLib + + From 8b099fb48116fa5ab3ede663d0152355b91860b3 Mon Sep 17 00:00:00 2001 From: BananaLF <864685021@qq.com> Date: Wed, 31 May 2023 10:16:14 +0800 Subject: [PATCH 2/3] remove useless code --- libs/scripts/system.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/libs/scripts/system.sh b/libs/scripts/system.sh index b24d953c9..a4846face 100755 --- a/libs/scripts/system.sh +++ b/libs/scripts/system.sh @@ -1,7 +1,5 @@ #!/bin/sh #set -e -GO_VERSION=$1 -ROCKSDB_VERSION=$2 get_distribution() { lsb_dist="" From 421318e13624cbe5eecc7f2765841f21fb45f930 Mon Sep 17 00:00:00 2001 From: BananaLF <864685021@qq.com> Date: Wed, 31 May 2023 10:32:40 +0800 Subject: [PATCH 3/3] add warning tips --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index c1b208a8f..5a67abed4 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,9 @@ build_tags = netgo system=$(shell $(shell pwd)/libs/scripts/system.sh) ifeq ($(system),alpine) + ifeq ($(LINK_STATICALLY),false) + $(warning Your system is alpine. It must be compiled statically. Now we start compile statically.) + endif LINK_STATICALLY=true else ifeq ($(LINK_STATICALLY),true)