Permalink
Browse files

Integrate cstubs.

  • Loading branch information...
whitequark committed May 17, 2014
1 parent 857c7f0 commit acc257ea18a5f5b99f5a4e23eb505f80f8f8e42c
Showing with 56 additions and 14 deletions.
  1. +11 −1 _oasis
  2. +1 −13 lib/LZ4.ml
  3. +11 −0 lib_gen/LZ4_bindgen.ml
  4. +13 −0 lib_gen/LZ4_bindings.ml
  5. +20 −0 myocamlbuild.ml
View
12 _oasis
@@ -12,8 +12,18 @@ Homepage : https://github.com/whitequark/ocaml-lz4
Library "lz4"
Path: lib
Modules: LZ4
- BuildDepends: bytes, ctypes.foreign
+ InternalModules: LZ4_bindings, LZ4_generated
+ CSources: LZ4_stubs.c
CCLib: -llz4
+ CCOpt: -I $pkg_ctypes_stubs/..
+ BuildDepends: bytes, ctypes.stubs
+ BuildTools: lz4_bindgen
+
+Executable "lz4_bindgen"
+ Install: false
+ Path: lib_gen
+ MainIs: LZ4_bindgen.ml
+ BuildDepends: ctypes.stubs
Executable "test_lz4"
Build$: flag(tests)
View
@@ -1,18 +1,6 @@
open Ctypes
-module C = struct
- open Foreign
-
- let compressBound = foreign "LZ4_compressBound" (int @-> returning int)
- let b_compress = foreign "LZ4_compress"
- (ocaml_bytes @-> ocaml_bytes @-> int @-> returning int)
- let ba_compress = foreign "LZ4_compress"
- (ptr char @-> ptr char @-> int @-> returning int)
- let b_decompress = foreign "LZ4_decompress_safe"
- (ocaml_bytes @-> ocaml_bytes @-> int @-> int @-> returning int)
- let ba_decompress = foreign "LZ4_decompress_safe"
- (ptr char @-> ptr char @-> int @-> int @-> returning int)
-end
+module C = LZ4_bindings.C(LZ4_generated)
exception Input_too_large
exception Corrupted
View
@@ -0,0 +1,11 @@
+open Ctypes
+
+let _ =
+ let fmt = Format.formatter_of_out_channel (open_out "lib/LZ4_stubs.c") in
+ Format.fprintf fmt "#include <caml/mlvalues.h>@.";
+ Format.fprintf fmt "#include <ctypes/cstubs_internals.h>@.";
+ Format.fprintf fmt "#include <lz4.h>@.";
+ Cstubs.write_c fmt ~prefix:"caml_" (module LZ4_bindings.C);
+
+ let fmt = Format.formatter_of_out_channel (open_out "lib/LZ4_generated.ml") in
+ Cstubs.write_ml fmt ~prefix:"caml_" (module LZ4_bindings.C)
View
@@ -0,0 +1,13 @@
+open Ctypes
+
+module C(F: Cstubs.FOREIGN) = struct
+ let compressBound = F.foreign "LZ4_compressBound" (int @-> returning int)
+ let b_compress = F.foreign "LZ4_compress"
+ (ocaml_bytes @-> ocaml_bytes @-> int @-> returning int)
+ let ba_compress = F.foreign "LZ4_compress"
+ (ptr char @-> ptr char @-> int @-> returning int)
+ let b_decompress = F.foreign "LZ4_decompress_safe"
+ (ocaml_bytes @-> ocaml_bytes @-> int @-> int @-> returning int)
+ let ba_decompress = F.foreign "LZ4_decompress_safe"
+ (ptr char @-> ptr char @-> int @-> int @-> returning int)
+end
View
@@ -0,0 +1,20 @@
+(* OASIS_START *)
+(* OASIS_STOP *)
+
+open Ocamlbuild_plugin;;
+
+dispatch
+ (MyOCamlbuildBase.dispatch_combine [
+ begin function
+ | After_rules ->
+ rule "cstubs: lib/x_bindings.ml -> x_stubs.c, x_stubs.ml"
+ ~prods:["lib/%_stubs.c"; "lib/%_generated.ml"]
+ ~deps: ["lib_gen/%_bindgen.byte"]
+ (fun env build ->
+ Cmd (A(env "lib_gen/%_bindgen.byte")));
+ copy_rule "cstubs: lib_gen/x_bindings.ml -> lib/x_bindings.ml"
+ "lib_gen/%_bindings.ml" "lib/%_bindings.ml"
+ | _ -> ()
+ end;
+ dispatch_default
+ ])

0 comments on commit acc257e

Please sign in to comment.