Files

40 lines
962 B
Haskell

import Development.Shake
import Development.Shake.Command
import Development.Shake.FilePath
import Development.Shake.Util
import Data.Char (toUpper)
capitalise (x:xs) = toUpper x : xs
ghcflags =
[ "-no-hs-main"
, "-optl-mexec-model=reactor"
, "-optl-Wl,--export=hello,--export=hs_init"
]
main = shakeArgs shakeOptions $ do
want ["call-hello.wasm","hello.wasm"]
"call-hello.wasm" %> \out -> do
need ["call-hello.wat"]
cmd_ "wasm-tools parse call-hello.wat" "-o" [out]
"hello.wasm" %> \out -> do
need ["Hello.hs"]
cmd_
"wasm32-wasi-ghc"
"Hello.hs" ghcflags
"-o" [out]
phony "run" $ do
need ["call-hello.wasm","hello.wasm"]
cmd_ "wasmtime run"
"--preload" "env=hello.wasm"
"--invoke" "call-hello"
"call-hello.wasm"
phony "clean" $ do
removeFilesAfter ".shake" ["//*"]
liftIO $ removeFiles "."
[ "*.wasm"
, "*.o"
, "*_stub.h"
, "*.hi"
]