-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e199b6e
Showing
9 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
_* | ||
result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
opam-version: "2.0" | ||
depends: [ | ||
"ocaml" {>= "4.08.0"} | ||
"eio_main" | ||
"capnp-rpc-lwt" | ||
"logs" | ||
] | ||
build: [ | ||
["dune" "build" "-p" name "-j" jobs] | ||
["dune" "runtest" "-p" name "-j" jobs] {with-test} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(executable | ||
(name main) | ||
(libraries eio_main capnp-rpc-lwt logs.fmt) | ||
(flags (:standard -w -53-55))) | ||
|
||
(rule | ||
(targets echo_api.ml echo_api.mli) | ||
(deps echo_api.capnp) | ||
(action (run capnp compile -o %{bin:capnpc-ocaml} %{deps}))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(lang dune 2.9) | ||
(name capnp-rpc-demo) | ||
(formatting disabled) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
(* $MDX part-begin=server *) | ||
module Api = Echo_api.MakeRPC(Capnp_rpc_lwt) | ||
|
||
open Capnp_rpc_lwt | ||
|
||
let local = | ||
let module Echo = Api.Service.Echo in | ||
Echo.local @@ object | ||
inherit Echo.service | ||
|
||
method ping_impl params release_param_caps = | ||
let open Echo.Ping in | ||
let msg = Params.msg_get params in | ||
release_param_caps (); | ||
let response, results = Service.Response.create Results.init_pointer in | ||
Results.reply_set results ("echo:" ^ msg); | ||
Service.return response | ||
end | ||
(* $MDX part-end *) | ||
|
||
(* $MDX part-begin=client *) | ||
module Echo = Api.Client.Echo | ||
|
||
let ping t msg = | ||
let open Echo.Ping in | ||
let request, params = Capability.Request.create Params.init_pointer in | ||
Params.msg_set params msg; | ||
Capability.call_for_value_exn t method_id request |> Results.reply_get | ||
(* $MDX part-end *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@0xb287252b6cbed46e; | ||
|
||
interface Echo { | ||
ping @0 (msg :Text) -> (reply :Text); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
inputs = { | ||
opam-nix.url = "github:tweag/opam-nix"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
opam-nix.inputs.nixpkgs.follows = "nixpkgs"; | ||
}; | ||
outputs = { self, nixpkgs, flake-utils, opam-nix, ... }@inputs: | ||
let package = "capnp-rpc-demo"; | ||
in flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
pkgs = nixpkgs.legacyPackages.${system}; | ||
opam-nix-lib = opam-nix.lib.${system}; | ||
devPackagesQuery = { | ||
ocaml-lsp-server = "*"; | ||
ocamlformat = "*"; | ||
}; | ||
query = { | ||
ocaml-base-compiler = "*"; | ||
}; | ||
overlay = final: prev: { | ||
"${package}" = prev.${package}.overrideAttrs (_: { | ||
# Prevent the ocaml dependencies from leaking into dependent environments | ||
doNixSupport = false; | ||
nativeBuildInputs = [ pkgs.dune_3 ]; | ||
}); | ||
}; | ||
resolved-scope = | ||
let scope = opam-nix-lib.buildOpamProject' { } ./. (query // devPackagesQuery); in | ||
scope.overrideScope' overlay; | ||
materialized-scope = | ||
# to generate: | ||
# nix shell github:tweag/opam-nix#opam-nix-gen -c opam-nix-gen -p ocaml-lsp-server -p ocamlformat -p ocaml-base-compiler aeon . package-defs.json | ||
let scope = opam-nix-lib.materializedDefsToScope { sourceMap.${package} = ./.; } ./package-defs.json; in | ||
scope.overrideScope' overlay; | ||
in rec { | ||
packages = { | ||
resolved = resolved-scope; | ||
materialized = materialized-scope; | ||
default = resolved-scope.${package}; | ||
}; | ||
defaultPackage = packages.default; | ||
|
||
devShells = | ||
let | ||
mkDevShell = scope: | ||
let | ||
devPackages = builtins.attrValues | ||
(pkgs.lib.getAttrs (builtins.attrNames devPackagesQuery) scope); | ||
in pkgs.mkShell { | ||
inputsFrom = [ scope.${package} ]; | ||
buildInputs = devPackages; | ||
}; | ||
in rec { | ||
resolved = mkDevShell resolved-scope; | ||
materialized = mkDevShell materialized-scope; | ||
default = resolved; | ||
}; | ||
}) // { | ||
nixosModules.default = { | ||
imports = [ ./module.nix ]; | ||
}; | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open Eio.Std | ||
|
||
let () = | ||
Logs.set_level (Some Logs.Warning); | ||
Logs.set_reporter (Logs_fmt.reporter ()) | ||
|
||
let () = | ||
Eio_main.run @@ fun _ -> | ||
let service = Echo.local in | ||
let reply = Echo.ping service "foo" in | ||
traceln "Got reply %S" reply |