diff --git a/Makefile b/Makefile index 7bc661e64..72890b6b1 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ PCRE ?= 8.45 ZLIB ?= 1.2.13 LUAROCKS ?= 3.9.2 PROXY_WASM_GO_SDK ?= v0.21.0 +PROXY_WASM_ASSEMBLYSCRIPT_SDK ?= v0.0.5 # util/runtime.sh - no makefile target NGX_BUILD_WASMER_RUSTFLAGS ?= -g -C opt-level=0 -C debuginfo=1 diff --git a/util/_lib.sh b/util/_lib.sh index aea179948..51a0a5a7e 100644 --- a/util/_lib.sh +++ b/util/_lib.sh @@ -7,6 +7,7 @@ DIR_NOPOOL=$DIR_DOWNLOAD/no-pool-nginx DIR_NGX_ECHO_MODULE=$DIR_DOWNLOAD/echo-nginx-module DIR_NGX_HEADERS_MORE_MODULE=$DIR_DOWNLOAD/headers-more-nginx-module DIR_MOCKEAGAIN=$DIR_DOWNLOAD/mockeagain +DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK=$DIR_DOWNLOAD/proxy-wasm-assemblyscript-sdk DIR_PROXY_WASM_GO_SDK=$DIR_DOWNLOAD/proxy-wasm-go-sdk DIR_PATCHED_PROXY_WASM_GO_SDK=$DIR_DOWNLOAD/proxy-wasm-go-sdk-patched DIR_BUILDROOT=$DIR_WORK/buildroot diff --git a/util/sdks/as.sh b/util/sdks/as.sh deleted file mode 100644 index e69de29bb..000000000 diff --git a/util/sdks/assemblyscript.sh b/util/sdks/assemblyscript.sh new file mode 100755 index 000000000..2375a8b3b --- /dev/null +++ b/util/sdks/assemblyscript.sh @@ -0,0 +1,91 @@ +#!/usr/bin/env bash +set -e + +SCRIPT_NAME=$(basename $0) +NGX_WASM_DIR=${NGX_WASM_DIR:-"$( + cd $(dirname $(dirname $(dirname ${0}))) + pwd -P +)"} +if [[ ! -f "${NGX_WASM_DIR}/util/_lib.sh" ]]; then + echo "Unable to source util/_lib.sh" >&2 + exit 1 +fi + +source $NGX_WASM_DIR/util/_lib.sh + +############################################################################### + +download_assemblyscript_sdk() { + local version="$1" + local clean="$2" + + if [[ "$clean" = "clean" ]]; then + rm -rfv "$DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK" + fi + + if [[ -d "$DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK" ]]; then + notice "updating the proxy-wasm-assemblyscript-sdk repository..." + pushd $DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK + git fetch + git reset --hard $version + popd + else + notice "cloning proxy-wasm-assemblyscript-sdk repository, version ${version}..." + git clone \ + -c advice.detachedHead=false --depth 1 \ + --branch $version \ + https://github.com/Kong/proxy-wasm-assemblyscript-sdk.git \ + $DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK + fi +} + +build_assemblyscript_sdk() { + local version="$1" + local clean="$2" + + if [[ ! -x "$(command -v npm)" ]]; then + fatal "missing 'npm', is Node.js installed?" + exit 1 + fi + + local hasher=sha1sum + if [[ ! -x "$(command -v $hasher)" ]]; then + hasher=shasum + fi + + local hash_src=$(find $DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK -type f \( -name '*.ts' -or -name 'package*.json' \) -exec $hasher {} \; \ + | $hasher | awk '{ print $1 }') + + if [[ -f "$DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK/.hash" \ + && $(cat "$DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK/.hash") == $(echo $hash_src) ]]; + then + exit + fi + + echo $hash_src > "$DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK/.hash" + + notice "compiling AssemblyScript examples..." + + for example in $DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK/examples/*; do + name=$(basename $example) + name=$(echo $name | sed 's/-/_/g') + + pushd $example + npm install + npm run asbuild + cp build/debug.wasm $DIR_TESTS_LIB_WASM/assemblyscript_$name.wasm + popd + done +} + +############################################################################### + +mode="$1" +version="$2" +clean="$3" + +if [ "$mode" = "download" ]; then + download_assemblyscript_sdk "$version" "$clean" +else + build_assemblyscript_sdk "$version" "$clean" +fi diff --git a/util/setup_dev.sh b/util/setup_dev.sh index 57c6adbf1..e26edac27 100755 --- a/util/setup_dev.sh +++ b/util/setup_dev.sh @@ -184,6 +184,11 @@ if [[ ! -d "$DIR_PROXY_WASM_GO_SDK" ]]; then $NGX_WASM_DIR/util/sdk.sh -S go --clean fi +if [[ ! -d "$DIR_PROXY_WASM_ASSEMBLYSCRIPT_SDK" ]]; then + notice "downloading proxy-wasm AssemblyScript SDK..." + $NGX_WASM_DIR/util/sdk.sh -S assemblyscript --clean +fi + notice "done" # vim: ft=sh ts=4 sts=4 sw=4: