Skip to content

Commit

Permalink
h2-lwt-unix: replace dune file written in OCaml with select form (#68)
Browse files Browse the repository at this point in the history
Also remove `{build}` constraint from the dune dependency in opam files
  • Loading branch information
anmonteiro authored Sep 3, 2019
1 parent 65402ae commit e1ea33a
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Unreleased
--------------

- h2-lwt-unix: replace the `dune` file (previously written in OCaml) with a
`(select)` form to avoid depending on `ocamlfind`
([#68](https://github.com/anmonteiro/ocaml-h2/pull/68))
- h2-lwt, h2-lwt-unix, h2-mirage: Refactor interface code through common
`H2_lwt_intf` and expose less (internal) types
([#65](https://github.com/anmonteiro/ocaml-h2/pull/65))
Expand Down
3 changes: 1 addition & 2 deletions h2-lwt-unix.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ depends: [
"ocaml" {>= "4.04"}
"faraday-lwt-unix"
"h2-lwt" {>= "0.2.0"}
"dune" {build}
"ocamlfind" {build}
"dune"
"lwt"
]
depopts: ["tls" "lwt_ssl"]
Expand Down
2 changes: 1 addition & 1 deletion h2-lwt.opam
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ build: [
depends: [
"ocaml" {>= "4.04"}
"h2" {>= "0.2.0"}
"dune" {build}
"dune"
"lwt"
]
synopsis: "Lwt support for h2"
Expand Down
2 changes: 1 addition & 1 deletion h2-mirage.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ depends: [
"ocaml" {>= "4.04"}
"faraday-lwt"
"h2-lwt" {>= "0.2.0"}
"dune" {build}
"dune"
"lwt"
"mirage-conduit"
"cstruct"
Expand Down
2 changes: 1 addition & 1 deletion h2.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ build: [
]
depends: [
"ocaml" {>= "4.04"}
"dune" {build}
"dune"
"alcotest" {with-test}
"yojson" {with-test}
"hex" {with-test}
Expand Down
2 changes: 1 addition & 1 deletion hpack.opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dev-repo: "git+https://github.com/anmonteiro/ocaml-h2.git"
doc: "https://anmonteiro.github.io/ocaml-h2/"
depends: [
"ocaml" {>= "4.04"}
"dune" {build}
"dune"
"yojson" {with-test}
"hex" {with-test}
"angstrom"
Expand Down
12 changes: 12 additions & 0 deletions lib/parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -573,13 +573,25 @@ module Reader = struct

let client_frames preface_handler frame_handler =
connection_preface_and_frames
(* From RFC7540§3.5:
* The server connection preface consists of a potentially empty
* SETTINGS frame (Section 6.5) that MUST be the first frame the server
* sends in the HTTP/2 connection. *)
settings_preface
preface_handler
frame_handler

let server_frames preface_handler frame_handler =
connection_preface_and_frames
(fun parse_context ->
(* From RFC7540§3.5:
* The client connection preface starts with a sequence of 24 octets,
* which in hex notation is:
*
* 0x505249202a20485454502f322e300d0a0d0a534d0d0a0d0a
* That is, the connection preface starts with the string
* PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n). This sequence MUST be followed
* by a SETTINGS frame (Section 6.5), which MAY be empty. *)
connection_preface *> settings_preface parse_context)
preface_handler
frame_handler
Expand Down
49 changes: 17 additions & 32 deletions lwt-unix/dune
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
(* -*- tuareg -*- *)
(* This was inspired by `conduit-lwt-unix`'s dune file *)

let v ~ssl ~tls () =
let ssl, ssl_d =
if ssl then "ssl_io_real", "lwt_ssl "
else "ssl_io_dummy", ""
in
let tls, tls_d =
if tls then "tls_io_real", "tls.lwt "
else "tls_io_dummy", ""
in
Printf.sprintf {|
(rule (copy %s.ml ssl_io.ml))
(rule (copy %s.ml tls_io.ml))

(library
(name h2_lwt_unix)
(public_name h2-lwt-unix)
(libraries faraday-lwt-unix h2 h2-lwt lwt.unix %s%s)
(libraries
faraday-lwt-unix
h2
h2-lwt
lwt.unix
(select
ssl_io.ml
from
(lwt_ssl -> ssl_io_real.ml)
(-> ssl_io_dummy.ml))
(select
tls_io.ml
from
(tls.lwt -> tls_io_real.ml)
(-> tls_io_dummy.ml)))
(modules h2_lwt_unix tls_io ssl_io)
(flags (:standard -safe-string)))
|} ssl tls ssl_d tls_d

let main () =
let is_installed s = Printf.kprintf Sys.command "ocamlfind query %s" s = 0 in
let ssl = is_installed "lwt_ssl" in
let tls = is_installed "tls.lwt" in
Printf.printf
"Configuration\n\
\ ssl : %b\n\
\ tls : %b\n%!"
ssl tls;
v ~ssl ~tls ()

let () = Jbuild_plugin.V1.send @@ main ()
(flags
(:standard -safe-string)))

0 comments on commit e1ea33a

Please sign in to comment.