diff --git a/cstruct-async.opam b/cstruct-async.opam index 340b953..3fc684f 100644 --- a/cstruct-async.opam +++ b/cstruct-async.opam @@ -15,7 +15,7 @@ build: [ ] depends: [ "ocaml" {>= "4.08.0"} - "dune" {>= "2.0.0"} + "dune" {>= "3.17"} "async" {>= "v0.9.0" & < "v0.17.0"} "async_unix" {>= "v0.9.0" & < "v0.17.0"} "core" {>= "v0.9.0" & < "v0.17.0"} diff --git a/cstruct-lwt.opam b/cstruct-lwt.opam index 4f702c7..dc5a955 100644 --- a/cstruct-lwt.opam +++ b/cstruct-lwt.opam @@ -16,7 +16,7 @@ build: [ depends: [ "ocaml" {>= "4.08.0"} "base-unix" - "dune" {>= "2.0.0"} + "dune" {>= "3.17"} "lwt" "cstruct" {=version} ] diff --git a/cstruct-sexp.opam b/cstruct-sexp.opam index 6181a9c..c9f6d85 100644 --- a/cstruct-sexp.opam +++ b/cstruct-sexp.opam @@ -17,7 +17,7 @@ build: [ ] depends: [ "ocaml" {>= "4.08.0"} - "dune" {>= "2.0.0"} + "dune" {>= "3.17"} "sexplib" "cstruct" {=version} "alcotest" {with-test} diff --git a/cstruct-unix.opam b/cstruct-unix.opam index 0cda0a0..f6e099f 100644 --- a/cstruct-unix.opam +++ b/cstruct-unix.opam @@ -16,7 +16,7 @@ build: [ ] depends: [ "ocaml" {>= "4.06.0"} - "dune" {>= "2.0.0"} + "dune" {>= "3.17"} "base-unix" "cstruct" {=version} ] diff --git a/cstruct.opam b/cstruct.opam index 6830762..faa7d6d 100644 --- a/cstruct.opam +++ b/cstruct.opam @@ -17,7 +17,7 @@ build: [ ] depends: [ "ocaml" {>= "4.08.0"} - "dune" {>= "2.0.0"} + "dune" {>= "3.17"} "alcotest" {with-test} "fmt" {>= "0.8.9"} "crowbar" {with-test & >= "0.2"} diff --git a/dune-project b/dune-project index 9517716..5c627f8 100644 --- a/dune-project +++ b/dune-project @@ -1,5 +1,3 @@ -(lang dune 2.0) - -(allow_approximate_merlin) +(lang dune 3.17) (name cstruct) diff --git a/fuzz/fuzz.ml b/fuzz/fuzz.ml index 75d2cfd..f50a5bd 100644 --- a/fuzz/fuzz.ml +++ b/fuzz/fuzz.ml @@ -25,8 +25,6 @@ let bytes = map [bytes] Bytes.unsafe_of_string let buffer = map [uint8] Bigarray.(Array1.create Char c_layout) -let pp_cstruct f c = Format.pp_print_string f (Cstruct.debug c) - let check_within ~base x = check Cstruct.(base.off <= x.off); check Cstruct.(base.off + base.len >= x.off + x.len); diff --git a/lib/cstruct.wat b/lib/cstruct.wat new file mode 100644 index 0000000..2b30872 --- /dev/null +++ b/lib/cstruct.wat @@ -0,0 +1,39 @@ +;; The Wasm runtime for cstruct's bigstring primitives -- the analog of +;; cstruct.js for wasm_of_ocaml. wasm_of_ocaml's runtime already provides these +;; operations under its own bigarray names, so each cstruct primitive simply +;; re-exports the matching runtime function; only caml_check_alignment_bigstring +;; is cstruct-specific. +(module + (import "env" "caml_bigstring_blit_ba_to_ba" + (func $caml_blit_bigstring_to_bigstring + (param (ref eq)) (param (ref eq)) (param (ref eq)) (param (ref eq)) + (param (ref eq)) (result (ref eq)))) + (import "env" "caml_bigstring_blit_ba_to_bytes" + (func $caml_blit_bigstring_to_string + (param (ref eq)) (param (ref eq)) (param (ref eq)) (param (ref eq)) + (param (ref eq)) (result (ref eq)))) + (import "env" "caml_bigstring_blit_string_to_ba" + (func $caml_blit_string_to_bigstring + (param (ref eq)) (param (ref eq)) (param (ref eq)) (param (ref eq)) + (param (ref eq)) (result (ref eq)))) + (import "env" "caml_bigstring_memset" + (func $caml_fill_bigstring + (param (ref eq)) (param (ref eq)) (param (ref eq)) (param (ref eq)) + (result (ref eq)))) + (import "env" "caml_bigstring_memcmp" + (func $caml_compare_bigstring + (param (ref eq)) (param (ref eq)) (param (ref eq)) (param (ref eq)) + (param (ref eq)) (result (ref eq)))) + + (export "caml_blit_bigstring_to_bigstring" + (func $caml_blit_bigstring_to_bigstring)) + (export "caml_blit_bigstring_to_string" (func $caml_blit_bigstring_to_string)) + (export "caml_blit_string_to_bigstring" (func $caml_blit_string_to_bigstring)) + (export "caml_fill_bigstring" (func $caml_fill_bigstring)) + (export "caml_compare_bigstring" (func $caml_compare_bigstring)) + + ;; No fixed buffer address on Wasm, as in cstruct.js: always aligned. + (func (export "caml_check_alignment_bigstring") + (param (ref eq)) (param (ref eq)) (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 1))) +) diff --git a/lib/dune b/lib/dune index c1fa1de..4afea93 100644 --- a/lib/dune +++ b/lib/dune @@ -7,6 +7,8 @@ (wrapped false) (js_of_ocaml (javascript_files cstruct.js)) + (wasm_of_ocaml + (wasm_files cstruct.wat)) (modules cstruct cstruct_cap)) (library diff --git a/ppx_cstruct.opam b/ppx_cstruct.opam index 0c647ff..3a2289a 100644 --- a/ppx_cstruct.opam +++ b/ppx_cstruct.opam @@ -17,7 +17,7 @@ build: [ ] depends: [ "ocaml" {>= "4.08.0"} - "dune" {>= "2.0.0"} + "dune" {>= "3.17"} "cstruct" {=version} "ounit" {with-test} "ppxlib" {>= "0.16.0"} diff --git a/ppx_test/with-lwt/ppx_cstruct_and_lwt.ml b/ppx_test/with-lwt/ppx_cstruct_and_lwt.ml index 8fbd3b8..1a6455e 100644 --- a/ppx_test/with-lwt/ppx_cstruct_and_lwt.ml +++ b/ppx_test/with-lwt/ppx_cstruct_and_lwt.ml @@ -13,3 +13,5 @@ type foo64 = let foo = let%lwt foo = Lwt.return () in Lwt.return foo + +let () = ignore foo