Skip to content

Instantly share code, notes, and snippets.

@toots
Last active November 24, 2021 21:25
Show Gist options
  • Save toots/1260687647c139f7a1e862bea924e9b1 to your computer and use it in GitHub Desktop.
Save toots/1260687647c139f7a1e862bea924e9b1 to your computer and use it in GitHub Desktop.
Test dune configurator with cross-compilers.
module C = Configurator.V1
let () =
C.main ~name:"test-dune-configurator" (fun c ->
let has_alsa =
C.c_test c
{|
#include <alsa/asoundlib.h>
int main() {
snd_pcm_t *pcm_handle;
return 0;
}
|}
in
C.C_define.gen_header_file c ~fname:"config.h"
[
("HAS_ALSA", Switch has_alsa);
])
(library
(name test_dune_configurator)
(modules test_dune_configurator)
(foreign_stubs
(extra_deps config.h)
(language c)
(names test_dune_configurator)))
(executable
(name print_conf)
(modules print_conf)
(libraries test_dune_configurator))
(executable
(name discover)
(modules discover)
(libraries dune.configurator))
(rule
(targets config.h)
(action
(run ./discover.exe)))
(lang dune 2.8)
(name test-dune-configurator)
let () =
Printf.printf "System has alsa: %d\n%!" (Test_dune_configurator.has_alsa ())
#include <caml/misc.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include "config.h"
CAMLprim value ocaml_test_dune_configurator_has_alsa(value unit) {
CAMLparam0();
#ifdef HAS_ALSA
CAMLreturn(Val_int(1));
#else
CAMLreturn(Val_int(0));
#endif
}
external has_alsa : unit -> int = "ocaml_test_dune_configurator_has_alsa"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment