Skip to content

Commit

Permalink
chore: add var max to memory (#20)
Browse files Browse the repository at this point in the history
* chore: add var max to memory

* fix: missing comma
  • Loading branch information
zshipko authored Mar 12, 2024
1 parent 1fc2e1b commit 792de93
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ edition = "2021"
crate-type = ["staticlib"]

[dependencies]
extism = "1.1"
extism = "1.2"
42 changes: 26 additions & 16 deletions manifest/Extism/Manifest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion scripts/download-or-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 792de93

Please sign in to comment.