From 1e34e499d079d7edb003ff593d1337bb034b7ab8 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 2 Dec 2021 13:06:16 +0100 Subject: [PATCH 1/4] Hidapi: vendor ocaml-hidapi.1.1.1 --- vendors/ocaml-hidapi/.gitignore | 8 + vendors/ocaml-hidapi/CHANGES | 15 ++ vendors/ocaml-hidapi/LICENSE.md | 13 ++ vendors/ocaml-hidapi/Makefile | 5 + vendors/ocaml-hidapi/dune-project | 2 + vendors/ocaml-hidapi/hidapi.opam | 21 ++ vendors/ocaml-hidapi/src/config/discover.ml | 23 ++ vendors/ocaml-hidapi/src/config/dune | 3 + vendors/ocaml-hidapi/src/dune | 16 ++ vendors/ocaml-hidapi/src/hidapi.ml | 113 ++++++++++ vendors/ocaml-hidapi/src/hidapi.mli | 83 +++++++ vendors/ocaml-hidapi/src/hidapi_stubs.c | 230 ++++++++++++++++++++ vendors/ocaml-hidapi/test/dune | 11 + vendors/ocaml-hidapi/test/enumerate.ml | 24 ++ 14 files changed, 567 insertions(+) create mode 100644 vendors/ocaml-hidapi/.gitignore create mode 100644 vendors/ocaml-hidapi/CHANGES create mode 100644 vendors/ocaml-hidapi/LICENSE.md create mode 100644 vendors/ocaml-hidapi/Makefile create mode 100644 vendors/ocaml-hidapi/dune-project create mode 100644 vendors/ocaml-hidapi/hidapi.opam create mode 100644 vendors/ocaml-hidapi/src/config/discover.ml create mode 100644 vendors/ocaml-hidapi/src/config/dune create mode 100644 vendors/ocaml-hidapi/src/dune create mode 100644 vendors/ocaml-hidapi/src/hidapi.ml create mode 100644 vendors/ocaml-hidapi/src/hidapi.mli create mode 100644 vendors/ocaml-hidapi/src/hidapi_stubs.c create mode 100644 vendors/ocaml-hidapi/test/dune create mode 100644 vendors/ocaml-hidapi/test/enumerate.ml diff --git a/vendors/ocaml-hidapi/.gitignore b/vendors/ocaml-hidapi/.gitignore new file mode 100644 index 000000000000..d63db7487ddd --- /dev/null +++ b/vendors/ocaml-hidapi/.gitignore @@ -0,0 +1,8 @@ +_build +**/*.merlin +*.install +/ocaml-usb-*.tar.gz + + + + diff --git a/vendors/ocaml-hidapi/CHANGES b/vendors/ocaml-hidapi/CHANGES new file mode 100644 index 000000000000..ca5bec29e359 --- /dev/null +++ b/vendors/ocaml-hidapi/CHANGES @@ -0,0 +1,15 @@ +v1.1.1 2019-04-09 Paris +--------------------- + +- Fix bug in discover which causes build failure on some platforms. + +v1.1 2019-04-06 Paris +--------------------- + +- Switch to dune. +- Fix build on some platforms (@dakk). + +1.0 2018-05-30 Paris +-------------------- + +- Initial release. \ No newline at end of file diff --git a/vendors/ocaml-hidapi/LICENSE.md b/vendors/ocaml-hidapi/LICENSE.md new file mode 100644 index 000000000000..52b5f8cd7437 --- /dev/null +++ b/vendors/ocaml-hidapi/LICENSE.md @@ -0,0 +1,13 @@ +Copyright (c) 2017 Vincent Bernardoff + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/vendors/ocaml-hidapi/Makefile b/vendors/ocaml-hidapi/Makefile new file mode 100644 index 000000000000..8557f2abf36a --- /dev/null +++ b/vendors/ocaml-hidapi/Makefile @@ -0,0 +1,5 @@ +all: + dune build @install @runtest + +clean: + dune clean diff --git a/vendors/ocaml-hidapi/dune-project b/vendors/ocaml-hidapi/dune-project new file mode 100644 index 000000000000..1540e385fd17 --- /dev/null +++ b/vendors/ocaml-hidapi/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.0) +(name hidapi) diff --git a/vendors/ocaml-hidapi/hidapi.opam b/vendors/ocaml-hidapi/hidapi.opam new file mode 100644 index 000000000000..5f8e72ea01dc --- /dev/null +++ b/vendors/ocaml-hidapi/hidapi.opam @@ -0,0 +1,21 @@ +opam-version: "2.0" +name: "hidapi" +version: "1.1.1" +authors: "Vincent Bernardoff " +maintainer: "Vincent Bernardoff " +homepage: "https://github.com/vbmithr/ocaml-hidapi" +bug-reports: "https://github.com/vbmithr/ocaml-hidapi/issues" +dev-repo: "git+https://github.com/vbmithr/ocaml-hidapi" +doc: "https://vbmithr.github.io/ocaml-hidapi/doc" + +build: [ "dune" "build" "-p" name "-j" jobs ] +depends: [ + "ocaml" {>= "4.02.0"} + "dune" {build & >= "1.8.2"} + "conf-hidapi" {build} + "bigstring" {>= "0.2"} +] +synopsis: "Bindings to Signal11's hidapi library" +description: """ +A Simple library for communicating with USB and Bluetooth HID devices +on Linux, Mac, and Windows.""" diff --git a/vendors/ocaml-hidapi/src/config/discover.ml b/vendors/ocaml-hidapi/src/config/discover.ml new file mode 100644 index 000000000000..60ff2e3da2d4 --- /dev/null +++ b/vendors/ocaml-hidapi/src/config/discover.ml @@ -0,0 +1,23 @@ +module C = Configurator.V1 + +let () = + C.main ~name:"hidapi" begin fun c -> + let default : C.Pkg_config.package_conf = + { libs = ["-lhidapi"] + ; cflags = ["-I/usr/include/hidapi"] + } + in + let conf = + match C.Pkg_config.get c with + | None -> default + | Some pc -> + match + C.Pkg_config.query pc ~package:"hidapi-libusb", + C.Pkg_config.query pc ~package:"hidapi" with + | None, None -> default + | Some a, _ + | None, Some a -> a + in + C.Flags.write_sexp "c_flags.sexp" conf.cflags ; + C.Flags.write_sexp "c_library_flags.sexp" conf.libs + end diff --git a/vendors/ocaml-hidapi/src/config/dune b/vendors/ocaml-hidapi/src/config/dune new file mode 100644 index 000000000000..21a5f9a549b0 --- /dev/null +++ b/vendors/ocaml-hidapi/src/config/dune @@ -0,0 +1,3 @@ +(executable + (name discover) + (libraries dune.configurator)) diff --git a/vendors/ocaml-hidapi/src/dune b/vendors/ocaml-hidapi/src/dune new file mode 100644 index 000000000000..4b7f588a50dd --- /dev/null +++ b/vendors/ocaml-hidapi/src/dune @@ -0,0 +1,16 @@ +(library + (name hidapi) + (public_name hidapi) + (libraries bigstring) + (c_names hidapi_stubs) + (c_flags + (:include c_flags.sexp)) + (c_library_flags + (:include c_library_flags.sexp))) + +(rule + (targets c_flags.sexp c_library_flags.sexp) + (deps + (:< config/discover.exe)) + (action + (run %{<}))) diff --git a/vendors/ocaml-hidapi/src/hidapi.ml b/vendors/ocaml-hidapi/src/hidapi.ml new file mode 100644 index 000000000000..5552a03c3538 --- /dev/null +++ b/vendors/ocaml-hidapi/src/hidapi.ml @@ -0,0 +1,113 @@ +(*--------------------------------------------------------------------------- + Copyright (c) 2017 Vincent Bernardoff. All rights reserved. + Distributed under the ISC license, see terms at the end of the file. + ---------------------------------------------------------------------------*) + +type device_info = { + path : string ; + vendor_id : int ; + product_id : int ; + serial_number : string option ; + release_number : int ; + manufacturer_string : string option ; + product_string : string option ; + usage_page : int ; + usage : int ; + interface_number : int ; +} + +type t +type info + +external hid_error : t -> string option = "stub_hid_error" + +external init : unit -> unit = "stub_hid_init" [@@noalloc] +external deinit : unit -> unit = "stub_hid_exit" [@@noalloc] + +external hid_enumerate : int -> int -> info option = "stub_hid_enumerate" +external hid_enumerate_next : info -> device_info * info option = "stub_hid_enumerate_next" +external hid_free_enumeration : info -> unit = "stub_hid_free_enumeration" [@@noalloc] + +let enumerate ?(vendor_id=0) ?(product_id=0) () = + match hid_enumerate vendor_id product_id with + | None -> [] + | Some info -> + let rec inner acc i = + match hid_enumerate_next i with + | di, None -> di :: acc + | di, Some next -> inner (di :: acc) next + in + let res = inner [] info in + hid_free_enumeration info ; + res + +external hid_open : int -> int -> t option = "stub_hid_open" + +let open_id ~vendor_id ~product_id = + hid_open vendor_id product_id + +external open_path : string -> t option = "stub_hid_open_path" + +let open_id_exn ~vendor_id ~product_id = + match open_id ~vendor_id ~product_id with + | None -> failwith "open_id_exn" + | Some t -> t + +let open_path_exn path = + match open_path path with + | None -> failwith "open_path_exn" + | Some t -> t + +external hid_write : + t -> Bigstring.t -> int -> int = "stub_hid_write" [@@noalloc] +external hid_read_timeout : + t -> Bigstring.t -> int -> int -> int = "stub_hid_read_timeout" [@@noalloc] +external hid_set_nonblocking : + t -> bool -> int = "stub_hid_set_nonblocking" [@@noalloc] +external close : + t -> unit = "stub_hid_close" [@@noalloc] + +let set_nonblocking t v = + match hid_set_nonblocking t v with + | -1 -> Error (match hid_error t with None -> "" | Some msg -> msg) + | _ -> Ok () + +let set_nonblocking_exn t v = + match set_nonblocking t v with + | Error err -> failwith err + | Ok () -> () + +let write t ?len buf = + let buflen = Bigstring.length buf in + let len = + match len with + | None -> buflen + | Some l when l < 0 -> + invalid_arg (Printf.sprintf "write: len = %d must be positive" l) + | Some l when l > buflen -> + invalid_arg (Printf.sprintf "write: len is too big (%d > %d)" l buflen) + | Some l -> l in + match hid_write t buf len with + | -1 -> Error (match hid_error t with None -> "" | Some msg -> msg) + | nb_written -> Ok nb_written + +let read ?(timeout=(-1)) t buf len = + match hid_read_timeout t buf len timeout with + | -1 -> Error (match hid_error t with None -> "" | Some msg -> msg) + | nb_read -> Ok nb_read + +(*--------------------------------------------------------------------------- + Copyright (c) 2017 Vincent Bernardoff + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + ---------------------------------------------------------------------------*) diff --git a/vendors/ocaml-hidapi/src/hidapi.mli b/vendors/ocaml-hidapi/src/hidapi.mli new file mode 100644 index 000000000000..a681d58f4eb9 --- /dev/null +++ b/vendors/ocaml-hidapi/src/hidapi.mli @@ -0,0 +1,83 @@ +(*--------------------------------------------------------------------------- + Copyright (c) 2017 Vincent Bernardoff. All rights reserved. + Distributed under the ISC license, see terms at the end of the file. + ---------------------------------------------------------------------------*) + +type device_info = { + path : string ; + vendor_id : int ; + product_id : int ; + serial_number : string option ; + release_number : int ; + manufacturer_string : string option ; + product_string : string option ; + usage_page : int ; + usage : int ; + interface_number : int ; +} + +type t + +val init : unit -> unit +(** [init ()] initializes the HIDAPI library. Calling it is not + strictly necessary, however this function should be called at the + beginning of execution however, if there is a chance of HIDAPI + handles being opened by different threads simultaneously. *) + +val deinit : unit -> unit +(** [deinit ()] frees all of the static data associated with + HIDAPI. It should be called at the end of execution to avoid memory + leaks. *) + +val enumerate : + ?vendor_id:int -> ?product_id:int -> unit -> device_info list +(** [enumerate ?vendor_id ?product_id ()] is the list of HID devices + attached to the system. The optional arguments are a way to filter + the results returned. *) + +val open_id : vendor_id:int -> product_id:int -> t option +(** [open_id ~vendor_id ~product_id] is the device handle of HID + device (vendor_id, product_id), or None if no such device exist or + in case of error. *) + +val open_path : string -> t option +(** [open_path path] is the device handle of HID device of path + [path], or None if no such device exist or in case of error. [path] + can be discovered with [enumerate] or a platform-specific path name + can be used (eg: /dev/hidraw0 on Linux). *) + +val open_id_exn : vendor_id:int -> product_id:int -> t +val open_path_exn : string -> t + +val write : t -> ?len:int -> Bigstring.t -> (int, string) result +(** [write t buf] is [Ok nb_bytes_written] on success, or + [Error description] in case of error. *) + +val read : ?timeout:int -> t -> Bigstring.t -> int -> (int, string) result +(** [read ?timeout t buf len] is [Ok nb_bytes_read] on success, or + [Error description] in case of error. *) + +val set_nonblocking : t -> bool -> (unit, string) result +(** [set_nonblocking t v] sets nonblocking mode if [v] is [true], or + sets blocking mode otherwise. *) + +val set_nonblocking_exn : t -> bool -> unit + +val close : t -> unit +(** [close t] closes the HID device [t]. *) + +(*--------------------------------------------------------------------------- + Copyright (c) 2017 Vincent Bernardoff + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + ---------------------------------------------------------------------------*) diff --git a/vendors/ocaml-hidapi/src/hidapi_stubs.c b/vendors/ocaml-hidapi/src/hidapi_stubs.c new file mode 100644 index 000000000000..d9ee3d62790f --- /dev/null +++ b/vendors/ocaml-hidapi/src/hidapi_stubs.c @@ -0,0 +1,230 @@ +/* -------------------------------------------------------------------------- + Copyright (c) 2017 Vincent Bernardoff. All rights reserved. + Distributed under the ISC license, see terms at the end of the file. + --------------------------------------------------------------------------- */ + +#include +#include + +#include +#include +#include +#include +#include + +typedef struct hid_device_info hid_device_info_t; + +#define Hid_val(v) (*((hid_device **) Data_custom_val(v))) +#define Hidinfo_val(v) (*((hid_device_info_t **) Data_custom_val(v))) + +#define Gen_custom_block(SNAME, CNAME, MNAME) \ + static int compare_##SNAME(value a, value b) { \ + CNAME *aa = MNAME(a), *bb = MNAME(b); \ + return (aa == bb ? 0 : (aa < bb ? -1 : 1)); \ + } \ + \ + static struct custom_operations hidapi_##SNAME##_ops = { \ + .identifier = "hidapi_" #SNAME, \ + .finalize = custom_finalize_default, \ + .compare = compare_##SNAME, \ + .compare_ext = custom_compare_ext_default, \ + .hash = custom_hash_default, \ + .serialize = custom_serialize_default, \ + .deserialize = custom_deserialize_default \ + }; \ + \ + static value alloc_##SNAME (CNAME *a) { \ + value custom = alloc_custom(&hidapi_##SNAME##_ops, sizeof(CNAME *), 0, 1); \ + MNAME(custom) = a; \ + return custom; \ + } + +Gen_custom_block(hid, hid_device, Hid_val) +Gen_custom_block(hidinfo, hid_device_info_t, Hidinfo_val) + +CAMLprim value stub_hid_error(value dev) { + CAMLparam1(dev); + CAMLlocal2(ret, msg); + + const wchar_t *err_string = hid_error(Hid_val(dev)); + + if (err_string == NULL) ret = Val_unit; + + else { + char buf[1024] = {0}; + snprintf(buf, sizeof(buf), "%ls", err_string); + ret = caml_alloc(1, 0); + msg = caml_copy_string(buf); + Store_field(ret, 0, msg); + } + + CAMLreturn(ret); +} + +static value copy_device_info (hid_device_info_t *di) { + CAMLparam0(); + CAMLlocal5(result, path, sn, ms, ps); + CAMLlocal3(ret1, ret2, ret3); + + result = caml_alloc_tuple(10); + char buf[1024] = {0}; + + path = caml_copy_string(di->path); + Store_field(result, 0, path); + + Store_field(result, 1, Val_int(di->vendor_id)); + Store_field(result, 2, Val_int(di->product_id)); + + if (di->serial_number == NULL) + Store_field(result, 3, Val_unit); + else { + snprintf(buf, sizeof(buf), "%ls", di->serial_number); + ret1 = caml_alloc(1, 0); + sn = caml_copy_string(buf); + Store_field(ret1, 0, sn); + Store_field(result, 3, ret1); + } + + Store_field(result, 4, Val_int(di->release_number)); + + if (di->manufacturer_string == NULL) + Store_field(result, 5, Val_unit); + else { + snprintf(buf, sizeof(buf), "%ls", di->manufacturer_string); + ret2 = caml_alloc(1, 0); + ms = caml_copy_string(buf); + Store_field(ret2, 0, ms); + Store_field(result, 5, ret2); + } + + if (di->product_string == NULL) + Store_field(result, 6, Val_unit); + else { + snprintf(buf, sizeof(buf), "%ls", di->product_string); + ret3 = caml_alloc(1, 0); + ps = caml_copy_string(buf); + Store_field(ret3, 0, ps); + Store_field(result, 6, ret3); + } + + Store_field(result, 7, Val_int(di->usage_page)); + Store_field(result, 8, Val_int(di->usage)); + Store_field(result, 9, Val_int(di->interface_number)); + + CAMLreturn(result); +} + +CAMLprim value stub_hid_init(value unit) { + return Val_int(hid_init()); +} + +CAMLprim value stub_hid_exit(value unit) { + return Val_int(hid_exit()); +} + +CAMLprim value stub_hid_enumerate(value vendor_id, value product_id) { + CAMLparam2(vendor_id, product_id); + CAMLlocal2(ret, hidinfo); + + struct hid_device_info *di = hid_enumerate(Int_val(vendor_id), Int_val(product_id)); + + if (di == NULL) ret = Val_unit; + + else { + ret = caml_alloc(1, 0); + hidinfo = alloc_hidinfo(di); + Store_field(ret, 0, hidinfo); + } + + CAMLreturn(ret); +} + +CAMLprim value stub_hid_free_enumeration(value hid_info) { + hid_free_enumeration(Hidinfo_val(hid_info)); + return Val_unit; +} + +CAMLprim value stub_hid_enumerate_next(value hid_info) { + CAMLparam1(hid_info); + CAMLlocal4(ret, info, nextopt, next); + + hid_device_info_t *di = Hidinfo_val(hid_info); + + info = copy_device_info(di); + ret = caml_alloc_tuple(2); + + if (!di->next) nextopt = Val_unit; + else { + nextopt = caml_alloc(1, 0); + next = alloc_hidinfo(di->next); + Store_field(nextopt, 0, next); + } + + Store_field(ret, 0, info); + Store_field(ret, 1, nextopt); + + CAMLreturn(ret); +} + +CAMLprim value stub_hid_open(value vendor_id, value product_id) { + CAMLparam2(vendor_id, product_id); + CAMLlocal2(ret, hid); + + hid_device* h = hid_open(Int_val(vendor_id), Int_val(product_id), NULL); + if (h == NULL) ret = Val_unit; + else { + ret = caml_alloc(1, 0); + hid = alloc_hid(h); + Store_field(ret, 0, hid); + } + + CAMLreturn(ret); +} + +CAMLprim value stub_hid_open_path(value path) { + CAMLparam1(path); + CAMLlocal2(ret, hid); + + hid_device* h = hid_open_path(String_val(path)); + if (h == NULL) ret = Val_unit; + else { + ret = caml_alloc(1, 0); + hid = alloc_hid(h); + Store_field(ret, 0, hid); + } + + CAMLreturn(ret); +} + +CAMLprim value stub_hid_write(value dev, value data, value len) { + return Val_int(hid_write(Hid_val(dev), Caml_ba_data_val(data), Int_val(len))); +} + +CAMLprim value stub_hid_read_timeout(value dev, value data, value len, value ms) { + return Val_int(hid_read_timeout(Hid_val(dev), Caml_ba_data_val(data), Int_val(len), Int_val(ms))); +} + +CAMLprim value stub_hid_set_nonblocking(value dev, value nonblock) { + return Val_int(hid_set_nonblocking(Hid_val(dev), Bool_val(nonblock))); +} + +CAMLprim value stub_hid_close(value dev) { + hid_close(Hid_val(dev)); + return Val_unit; +} + +/* -------------------------------------------------------------------------- + Copyright (c) 2017 Vincent Bernardoff + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + --------------------------------------------------------------------------- */ diff --git a/vendors/ocaml-hidapi/test/dune b/vendors/ocaml-hidapi/test/dune new file mode 100644 index 000000000000..8a7924089a6d --- /dev/null +++ b/vendors/ocaml-hidapi/test/dune @@ -0,0 +1,11 @@ +(executable + (name enumerate) + (public_name ocaml-hid-enumerate) + (libraries hidapi)) + +(alias + (name runtest-hidapi) + (deps + (:< enumerate.exe)) + (action + (run %{<}))) diff --git a/vendors/ocaml-hidapi/test/enumerate.ml b/vendors/ocaml-hidapi/test/enumerate.ml new file mode 100644 index 000000000000..dc62c22f1f56 --- /dev/null +++ b/vendors/ocaml-hidapi/test/enumerate.ml @@ -0,0 +1,24 @@ +open Hidapi + +let () = + init () ; + let devs = Hidapi.enumerate () in + ListLabels.iter devs ~f:begin fun { path; vendor_id; product_id; + serial_number; release_number; + manufacturer_string; product_string; + interface_number ; _ } -> + let s = match serial_number with None -> "" | Some s -> s in + let m = match manufacturer_string with None -> "" | Some s -> s in + let p = match product_string with None -> "" | Some s -> s in + Printf.printf "%s 0x%04x 0x%04x %s %d %s %s %d\n" + path vendor_id product_id + s release_number m p + interface_number ; + match open_id ~vendor_id ~product_id with + | None -> + Printf.printf "Impossible to open %d:%d\n" vendor_id product_id + | Some d -> + close d ; + Printf.printf "Ok, opened/closed %d:%d\n" vendor_id product_id ; + end ; + deinit () -- GitLab From 968a4601d7555aebdf5b0304ac88d1a39a251e52 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 2 Dec 2021 13:24:52 +0100 Subject: [PATCH 2/4] Hidapi: patch hidapi for static profile --- vendors/ocaml-hidapi/hidapi.opam | 1 + vendors/ocaml-hidapi/src/dune | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/vendors/ocaml-hidapi/hidapi.opam b/vendors/ocaml-hidapi/hidapi.opam index 5f8e72ea01dc..6b671e14f8f2 100644 --- a/vendors/ocaml-hidapi/hidapi.opam +++ b/vendors/ocaml-hidapi/hidapi.opam @@ -12,6 +12,7 @@ build: [ "dune" "build" "-p" name "-j" jobs ] depends: [ "ocaml" {>= "4.02.0"} "dune" {build & >= "1.8.2"} + "dune-configurator" "conf-hidapi" {build} "bigstring" {>= "0.2"} ] diff --git a/vendors/ocaml-hidapi/src/dune b/vendors/ocaml-hidapi/src/dune index 4b7f588a50dd..2de261f79832 100644 --- a/vendors/ocaml-hidapi/src/dune +++ b/vendors/ocaml-hidapi/src/dune @@ -1,3 +1,7 @@ +(rule + (targets static_library_flags.sexp) + (action (with-stdout-to static_library_flags.sexp (system "[ 'static' = '%{profile}' ] && echo '(-lusb-1.0 -ludev)' || echo '()'")))) + (library (name hidapi) (public_name hidapi) @@ -6,7 +10,8 @@ (c_flags (:include c_flags.sexp)) (c_library_flags - (:include c_library_flags.sexp))) + (:include c_library_flags.sexp) + (:include static_library_flags.sexp))) (rule (targets c_flags.sexp c_library_flags.sexp) -- GitLab From 23407468dfae43b1144b613fd49278973459261f Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Thu, 2 Dec 2021 13:30:32 +0100 Subject: [PATCH 3/4] Build: simplify static build --- src/bin_client/dune | 2 +- src/bin_codec/dune | 2 +- src/bin_signer/dune | 2 +- src/proto_010_PtGRANAD/bin_accuser/dune | 3 +-- src/proto_010_PtGRANAD/bin_baker/dune | 3 +-- src/proto_010_PtGRANAD/bin_endorser/dune | 3 +-- src/proto_011_PtHangz2/bin_accuser/dune | 3 +-- src/proto_011_PtHangz2/bin_baker/dune | 3 +-- src/proto_011_PtHangz2/bin_endorser/dune | 3 +-- src/proto_alpha/bin_accuser/dune | 3 +-- src/proto_alpha/bin_baker/dune | 3 +-- 11 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/bin_client/dune b/src/bin_client/dune index 9ab1908d3f0c..d7541c171d4b 100644 --- a/src/bin_client/dune +++ b/src/bin_client/dune @@ -4,7 +4,7 @@ (env (static - (flags (:standard -ccopt -static -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + (flags (:standard -ccopt -static)))) (executables (names main_client main_admin) diff --git a/src/bin_codec/dune b/src/bin_codec/dune index 421a68bb9d60..aee18a1a369a 100644 --- a/src/bin_codec/dune +++ b/src/bin_codec/dune @@ -1,6 +1,6 @@ (env (static - (flags (:standard -ccopt -static -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + (flags (:standard -ccopt -static)))) (executable (name codec) diff --git a/src/bin_signer/dune b/src/bin_signer/dune index 8528f6c04312..a0a483a00d23 100644 --- a/src/bin_signer/dune +++ b/src/bin_signer/dune @@ -1,6 +1,6 @@ (env (static - (flags (:standard -ccopt -static -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + (flags (:standard -ccopt -static)))) (executable (name main_signer) diff --git a/src/proto_010_PtGRANAD/bin_accuser/dune b/src/proto_010_PtGRANAD/bin_accuser/dune index b744597f77ea..ef860e26da49 100644 --- a/src/proto_010_PtGRANAD/bin_accuser/dune +++ b/src/proto_010_PtGRANAD/bin_accuser/dune @@ -2,8 +2,7 @@ (env (static (flags (:standard - -ccopt -static - -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + -ccopt -static)))) (executable (name main_accuser_010_PtGRANAD) diff --git a/src/proto_010_PtGRANAD/bin_baker/dune b/src/proto_010_PtGRANAD/bin_baker/dune index c4a977650edb..89be23390eb5 100644 --- a/src/proto_010_PtGRANAD/bin_baker/dune +++ b/src/proto_010_PtGRANAD/bin_baker/dune @@ -2,8 +2,7 @@ (env (static (flags (:standard - -ccopt -static - -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + -ccopt -static)))) (executable (name main_baker_010_PtGRANAD) diff --git a/src/proto_010_PtGRANAD/bin_endorser/dune b/src/proto_010_PtGRANAD/bin_endorser/dune index 8201ba78b384..83b67b999e8e 100644 --- a/src/proto_010_PtGRANAD/bin_endorser/dune +++ b/src/proto_010_PtGRANAD/bin_endorser/dune @@ -2,8 +2,7 @@ (env (static (flags (:standard - -ccopt -static - -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + -ccopt -static)))) (executable (name main_endorser_010_PtGRANAD) diff --git a/src/proto_011_PtHangz2/bin_accuser/dune b/src/proto_011_PtHangz2/bin_accuser/dune index 50f1caf8ef4e..f4f72161b26f 100644 --- a/src/proto_011_PtHangz2/bin_accuser/dune +++ b/src/proto_011_PtHangz2/bin_accuser/dune @@ -2,8 +2,7 @@ (env (static (flags (:standard - -ccopt -static - -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + -ccopt -static)))) (executable (name main_accuser_011_PtHangz2) diff --git a/src/proto_011_PtHangz2/bin_baker/dune b/src/proto_011_PtHangz2/bin_baker/dune index d578ca5283f9..cad6ae39df90 100644 --- a/src/proto_011_PtHangz2/bin_baker/dune +++ b/src/proto_011_PtHangz2/bin_baker/dune @@ -2,8 +2,7 @@ (env (static (flags (:standard - -ccopt -static - -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + -ccopt -static)))) (executable (name main_baker_011_PtHangz2) diff --git a/src/proto_011_PtHangz2/bin_endorser/dune b/src/proto_011_PtHangz2/bin_endorser/dune index f271804315c1..d4b3e36c3136 100644 --- a/src/proto_011_PtHangz2/bin_endorser/dune +++ b/src/proto_011_PtHangz2/bin_endorser/dune @@ -2,8 +2,7 @@ (env (static (flags (:standard - -ccopt -static - -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + -ccopt -static)))) (executable (name main_endorser_011_PtHangz2) diff --git a/src/proto_alpha/bin_accuser/dune b/src/proto_alpha/bin_accuser/dune index 520b4384a4ac..fdccc1691e5e 100644 --- a/src/proto_alpha/bin_accuser/dune +++ b/src/proto_alpha/bin_accuser/dune @@ -2,8 +2,7 @@ (env (static (flags (:standard - -ccopt -static - -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + -ccopt -static)))) (executable (name main_accuser_alpha) diff --git a/src/proto_alpha/bin_baker/dune b/src/proto_alpha/bin_baker/dune index 7db4bf1b9480..51b3365bf832 100644 --- a/src/proto_alpha/bin_baker/dune +++ b/src/proto_alpha/bin_baker/dune @@ -2,8 +2,7 @@ (env (static (flags (:standard - -ccopt -static - -cclib "-lusb-1.0 -lhidapi-libusb -ludev")))) + -ccopt -static)))) (executable (name main_baker_alpha) -- GitLab From 2a9e1e8fc7a423384cd08e9604e946c0cf9612a4 Mon Sep 17 00:00:00 2001 From: Hugo Heuzard Date: Mon, 6 Dec 2021 12:06:38 +0100 Subject: [PATCH 4/4] Opam: bump opam-repository --- .gitlab/ci/templates.yml | 2 +- scripts/version.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab/ci/templates.yml b/.gitlab/ci/templates.yml index d4f6542b4f14..db26ddcee493 100644 --- a/.gitlab/ci/templates.yml +++ b/.gitlab/ci/templates.yml @@ -1,6 +1,6 @@ variables: ## This value MUST be the same as `opam_repository_tag` in `scripts/version.sh` - build_deps_image_version: 8c079ce574eb9097edf48c39fecff2aefb960229 + build_deps_image_version: 9202c9e950c4eef8fc971f878a255a97880ffb7b build_deps_image_name: registry.gitlab.com/tezos/opam-repository GIT_STRATEGY: fetch GIT_DEPTH: "1" diff --git a/scripts/version.sh b/scripts/version.sh index b3cf10a601c2..81956a028b1e 100755 --- a/scripts/version.sh +++ b/scripts/version.sh @@ -25,7 +25,7 @@ export full_opam_repository_tag=28242c987fe0ddfe6d17bf4c8a9d4c450b8978a8 ## opam_repository is an additional, tezos-specific opam repository. ## This value MUST be the same as `build_deps_image_version` in `.gitlab/ci/templates.yml export opam_repository_url=https://gitlab.com/tezos/opam-repository -export opam_repository_tag=8c079ce574eb9097edf48c39fecff2aefb960229 +export opam_repository_tag=9202c9e950c4eef8fc971f878a255a97880ffb7b export opam_repository_git=$opam_repository_url.git export opam_repository=$opam_repository_git\#$opam_repository_tag -- GitLab