From 792de93a95a5312581703cb195d5f611950cb25e Mon Sep 17 00:00:00 2001 From: zach Date: Tue, 12 Mar 2024 10:43:30 -0700 Subject: [PATCH] chore: add var max to memory (#20) * chore: add var max to memory * fix: missing comma --- Cargo.toml | 2 +- manifest/Extism/Manifest.hs | 42 ++++++++++++++++++++++-------------- scripts/download-or-build.sh | 3 ++- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ca13ae6..d1971eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" crate-type = ["staticlib"] [dependencies] -extism = "1.1" +extism = "1.2" diff --git a/manifest/Extism/Manifest.hs b/manifest/Extism/Manifest.hs index d3a5cb3..c7bbb25 100644 --- a/manifest/Extism/Manifest.hs +++ b/manifest/Extism/Manifest.hs @@ -9,21 +9,23 @@ import Text.JSON.Generic -- | Memory options data Memory = Memory { memoryMaxPages :: Nullable Int, - memoryMaxHttpResponseBytes :: Nullable Int + memoryMaxHttpResponseBytes :: Nullable Int, + memoryMaxVarBytes :: Nullable Int } deriving (Eq, Show) instance JSON Memory where - showJSON (Memory max maxHttp) = + showJSON (Memory max maxHttp maxVar) = object [ "max_pages" .= max, - "max_http_response_bytes" .= maxHttp + "max_http_response_bytes" .= maxHttp, + "max_var_bytes" .= maxVar ] readJSON obj = - let - max = obj .? "max_pages" - httpMax = obj .? "max_http_response_bytes" - in Ok (Memory max httpMax) + let max = obj .? "max_pages" + httpMax = obj .? "max_http_response_bytes" + maxVar = obj .? "max_var_bytes" + in Ok (Memory max httpMax maxVar) -- | HTTP request data HTTPRequest = HTTPRequest @@ -240,20 +242,28 @@ withTimeout m t = withMaxPages :: Manifest -> Int -> Manifest withMaxPages m pages = case memory m of - Null -> - m {memory = NotNull $ Memory (NotNull pages) Null} - NotNull (Memory _ x) -> - m {memory = NotNull $ Memory (NotNull pages) x} + Null -> + m {memory = NotNull $ Memory (NotNull pages) Null Null} + NotNull (Memory _ x y) -> + m {memory = NotNull $ Memory (NotNull pages) x y} - -- | Set memory.max_http_response_bytes withMaxHttpResponseBytes :: Manifest -> Int -> Manifest withMaxHttpResponseBytes m max = case memory m of - Null -> - m {memory = NotNull $ Memory Null (NotNull max)} - NotNull (Memory x _) -> - m {memory = NotNull $ Memory x (NotNull max)} + Null -> + m {memory = NotNull $ Memory Null (NotNull max) Null} + NotNull (Memory x _ y) -> + m {memory = NotNull $ Memory x (NotNull max) y} + +-- | Set memory.max_var_bytes +withMaxVarBytes :: Manifest -> Int -> Manifest +withMaxVarBytes m max = + case memory m of + Null -> + m {memory = NotNull $ Memory Null Null (NotNull max)} + NotNull (Memory x y _) -> + m {memory = NotNull $ Memory x y (NotNull max)} fromString :: String -> Either String Manifest fromString s = do diff --git a/scripts/download-or-build.sh b/scripts/download-or-build.sh index 85fc054..6421ea3 100644 --- a/scripts/download-or-build.sh +++ b/scripts/download-or-build.sh @@ -11,7 +11,8 @@ if ! [ -x "$(command -v extism)" ]; then echo 'Extism CLI is not installed. Building Extism using cargo' >&2 cargo build --release else - extism lib install --prefix ./target/extism --version v1.1 + VERSION=$(grep 'extism = ".*"' Cargo.toml | awk '{ print $3 }' | sed 's/"//g') + extism lib install --prefix ./target/extism --version v$VERSION mkdir -p ./target/release cp ./target/extism/lib/libextism.a ./target/release/libextism_hs.a fi