Skip to content

Commit

Permalink
chore(util) add sdks/assemblyscript.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
casimiro committed Nov 16, 2023
1 parent 8ec3e83 commit 4e24257
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions util/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Empty file removed util/sdks/as.sh
Empty file.
91 changes: 91 additions & 0 deletions util/sdks/assemblyscript.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4e24257

Please sign in to comment.