Skip to content

Commit

Permalink
Support wasmtime-21.0.0 (#47)
Browse files Browse the repository at this point in the history
This ensures wasmtime-hs builds against the latest wasmtime (v21). It
doesn't ensure all new features in wasmtime have a binding in
wasmtime-hs. That's saved for another set of PRs.
  • Loading branch information
basvandijk authored May 29, 2024
1 parent b86a359 commit c25aa44
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 241 deletions.
22 changes: 11 additions & 11 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
description = "wasmtime-hs";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
wasmtime = {
url = "github:bytecodealliance/wasmtime/v10.0.1";
url = "github:bytecodealliance/wasmtime/v21.0.0";
flake = false;
};
};
Expand Down Expand Up @@ -54,6 +54,7 @@
packages.hello-c = check_c_example "hello";
packages.gcd-c = check_c_example "gcd";
packages.memory-c = check_c_example "memory";
packages.fuel-c = check_c_example "fuel";

# The default development shell brings in all dependencies of
# wasmtime-hs (like all Haskell dependencies, libwasmtime, GHC).
Expand Down
16 changes: 8 additions & 8 deletions lib/Bindings/Wasmtime/Extern.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ import Bindings.Wasmtime.Store
import Data.Word (Word64)

#starttype struct wasmtime_func
#field store_id , Word64
#field index , CSize
#field store_id , Word64
#field __private , CSize
#stoptype

#synonym_t wasmtime_func_t , <wasmtime_func>

#starttype struct wasmtime_table
#field store_id , Word64
#field index , CSize
#field store_id , Word64
#field __private , CSize
#stoptype

#synonym_t wasmtime_table_t , <wasmtime_table>

#starttype struct wasmtime_memory
#field store_id , Word64
#field index , CSize
#field store_id , Word64
#field __private , CSize
#stoptype

#synonym_t wasmtime_memory_t , <wasmtime_memory>

#starttype struct wasmtime_global
#field store_id , Word64
#field index , CSize
#field store_id , Word64
#field __private , CSize
#stoptype

#synonym_t wasmtime_global_t , <wasmtime_global>
Expand Down
12 changes: 3 additions & 9 deletions lib/Bindings/Wasmtime/Store.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,11 @@ import Data.Word (Word64)
#ccall_unsafe wasmtime_context_gc , \
Ptr <wasmtime_context_t> -> IO ()

#ccall_unsafe wasmtime_context_add_fuel , \
#ccall_unsafe wasmtime_context_set_fuel , \
Ptr <wasmtime_context_t> -> Word64 -> IO (Ptr <wasmtime_error_t>)

#ccall_unsafe wasmtime_context_fuel_consumed ,\
Ptr <wasmtime_context_t> -> Ptr Word64 -> IO Bool

#ccall_unsafe wasmtime_context_fuel_remaining , \
Ptr <wasmtime_context_t> -> Ptr Word64 -> IO Bool

#ccall_unsafe wasmtime_context_consume_fuel , \
Ptr <wasmtime_context_t> -> Word64 -> Ptr Word64 -> IO (Ptr <wasmtime_error_t>)
#ccall_unsafe wasmtime_context_get_fuel , \
Ptr <wasmtime_context_t> -> Ptr Word64 -> IO (Ptr <wasmtime_error_t>)

#ccall_unsafe wasmtime_context_set_wasi, \
Ptr <wasmtime_context_t> -> Ptr <wasi_config_t> -> IO (Ptr <wasmtime_error_t>)
Expand Down
49 changes: 18 additions & 31 deletions lib/Bindings/Wasmtime/Val.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,21 @@ import Bindings.Wasmtime.Store
import Data.Int
import Data.WideWord.Word128 (Word128)

#opaque_t wasmtime_externref

#synonym_t wasmtime_externref_t , <wasmtime_externref>

#ccall_unsafe wasmtime_externref_new , \
Ptr () -> \
FunPtr (Ptr () -> IO ()) -> \
IO (Ptr <wasmtime_externref_t>)

#ccall_unsafe wasmtime_externref_data , \
Ptr <wasmtime_externref_t> -> IO (Ptr ())

#ccall_unsafe wasmtime_externref_clone , \
Ptr <wasmtime_externref_t> -> IO (Ptr <wasmtime_externref_t>)
#starttype struct wasmtime_anyref
#field store_id , Word64
#field __private1 , Word32
#field __private2 , Word32
#stoptype

#ccall_unsafe wasmtime_externref_delete , \
Ptr <wasmtime_externref_t> -> IO ()
#synonym_t wasmtime_anyref_t , <wasmtime_anyref>

#ccall_unsafe wasmtime_externref_from_raw , \
Ptr <wasmtime_context_t> -> Ptr () -> IO (Ptr <wasmtime_externref_t>)
#starttype struct wasmtime_externref
#field store_id , Word64
#field __private1 , Word32
#field __private2 , Word32
#stoptype

#ccall_unsafe wasmtime_externref_to_raw , \
Ptr <wasmtime_context_t> -> \
Ptr <wasmtime_externref_t> -> \
IO (Ptr ())
#synonym_t wasmtime_externref_t , <wasmtime_externref>

#synonym_t wasmtime_valkind_t , Word8

Expand All @@ -50,14 +40,16 @@ import Data.WideWord.Word128 (Word128)
#num WASMTIME_V128
#num WASMTIME_FUNCREF
#num WASMTIME_EXTERNREF
#num WASMTIME_ANYREF

#starttype union wasmtime_valunion
#field i32 , Int32
#field i64 , Int64
#field f32 , Float
#field f64 , Double
#field funcref , <wasmtime_func>
#field externref , Ptr <wasmtime_externref_t>
#field anyref , <wasmtime_anyref_t>
#field externref , <wasmtime_externref_t>
#field funcref , <wasmtime_func_t>
#field v128 , <wasmtime_v128>
#stoptype

Expand All @@ -69,8 +61,9 @@ import Data.WideWord.Word128 (Word128)
#field f32 , Float
#field f64 , Double
#field v128 , <wasmtime_v128>
#field anyref , Word32
#field externref , Word32
#field funcref , Ptr ()
#field externref , Ptr ()
#stoptype

#synonym_t wasmtime_val_raw_t , <wasmtime_val_raw>
Expand All @@ -81,9 +74,3 @@ import Data.WideWord.Word128 (Word128)
#stoptype

#synonym_t wasmtime_val_t , <wasmtime_val>

#ccall_unsafe wasmtime_val_delete , \
Ptr <wasmtime_val_t> -> IO ()

#ccall_unsafe wasmtime_val_copy , \
Ptr <wasmtime_val_t> -> Ptr <wasmtime_val_t> -> IO ()
Loading

0 comments on commit c25aa44

Please sign in to comment.