Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get constant strings through stubs. #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
(library
(name lilv)
(public_name lilv)
(libraries ctypes ctypes.foreign)
(libraries lilv.stubs ctypes ctypes.foreign)
(c_names lilv_generated_stubs)
(c_library_flags "-llilv-0")
)

(rule
(targets lilv_generated_stubs.ml)
(deps (:gen ./generator/gen_stubs.exe))
(action (run %{gen} ml %{targets})))

(rule
(targets lilv_generated_stubs.c)
(deps (:gen ./generator/gen_stubs.exe))
(action (run %{gen} c %{targets})))
4 changes: 4 additions & 0 deletions src/generator/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(name gen_stubs)
(modules gen_stubs)
(libraries lilv.stubs ctypes.stubs))
26 changes: 26 additions & 0 deletions src/generator/gen_stubs.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let c_headers = "
#include <lv2.h>

static char *ocaml_lv2_core_uri() {
return LV2_CORE_URI;
}
"

let () =
let mode = Sys.argv.(1) in
let fname = Sys.argv.(2) in
let oc = open_out_bin fname in
let format =
Format.formatter_of_out_channel oc
in
let fn =
match mode with
| "ml" -> Cstubs.write_ml
| "c" ->
Format.fprintf format "%s@\n" c_headers;
Cstubs.write_c
| _ -> assert false
in
fn format ~prefix:"ocaml_lilv" (module Lilv_stubs.Def);
Format.pp_print_flush format ();
close_out oc
4 changes: 3 additions & 1 deletion src/lilv.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
open Ctypes
open Foreign

module Stubs = Lilv_stubs.Def(Lilv_generated_stubs)

module LV2 = struct
type handle = unit ptr
let handle : handle typ = ptr void
Expand All @@ -23,7 +25,7 @@ module LV2 = struct
seal descriptor

module Core = struct
let uri = "http://lv2plug.in/ns/lv2core"
let uri = Stubs.core_uri ()

let prefix s = uri ^ "#" ^ s

Expand Down
8 changes: 8 additions & 0 deletions src/stubs/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(env
(dev
(flags (:standard -warn-error -A))))

(library
(name lilv_stubs)
(public_name lilv.stubs)
(libraries ctypes.stubs))
7 changes: 7 additions & 0 deletions src/stubs/lilv_stubs.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
open Ctypes

module Def (F : Cstubs.FOREIGN) = struct
open F

let core_uri = foreign "ocaml_lv2_core_uri" (void @-> returning string)
end